dummy variable for calculating

2 views (last 30 days)
King To Leung
King To Leung on 5 Aug 2022
Answered: Walter Roberson on 5 Aug 2022
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 Comments
King To Leung
King To Leung on 5 Aug 2022
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 on 5 Aug 2022
@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.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 5 Aug 2022
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()

Community Treasure Hunt

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

Start Hunting!