dummy variable for calculating
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Jan
le 5 Août 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.
Réponses (1)
Walter Roberson
le 5 Août 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()
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!