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 个评论
King To Leung
King To Leung 2022-8-5
I mean like each code like 123 refers to a sub industry/sector. Sub sector is like sub divisions of an industry. Like the sector is manufacturing sector. And there is sub sectors under the industry, like textile, clothing, heavy mental manufacturing etc.
So I wanna group sub sectors together, like sector code 111 123 125 belongs to the same sector and we give it a dummy variable "A".
Jan
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
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()

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by