dummy variable for calculating
2 次查看(过去 30 天)
显示 更早的评论
Hi all,
I have a bunch of sector code in c.sic column (column19). However, there are too many sub sectors and I need to group them to a larger industry. For example, both internet sector (code 123) and microchip sector(code 124) belongs to technology sector. I wanna assign a dummy variable according to the sector code. Like 123 and 124 is A, 234, 255 and 235 is B etc. I wanna have a colum for this. After that I wanna calculate the total return (column 8) for each sector.
Thanks in advance!
3 个评论
Jan
2022-8-5
@King To Leung: It is not clear what your data types are. I do not have any idea about what "code like 123 refers to a sub industry/sector" means. It is not possibloe to suggest some code, as long as you do not clarify with which kind of data you are working.
回答(1 个)
Walter Roberson
2022-8-5
Create a list of valid subsector codes, and a corresponding list the same size of the sector each should belong to.
Use the two-output form of ismember() to look up the subsector code to get the index into the table. Use the index to pull out the sector code.
This does not require that the codes are numeric.
If the codes are numeric but include fractional values you should probably use ismembertol()
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!