Hi,
As part of my master's progam in Accountancy, I am doing a replication study. I was wondering if anyone would be able to give me some advice on the following topic.
One of the variables that I have to create from the data is an industry dummy. This dummy should have the value "1" if the firm-year has a industry code (sic2) which is among the 6 most frequent industry codes in the dataset, and "0" otherwise.
My data:
Currently, I am using the following commands to create the industry dummy:
However, ideally, I would like to use the output from "groups" automatically in my loop. So, I don't have to type the relevant sic2 codes in the loop myself (as this seems inefficient and has to been changed manually if my data changes).
Is there a way to do this?
For your information, I am using Stata 16.1.
I hope this gives you enough information about my question. Please let me know if you can help me out!
Kind regards,
Lianne
As part of my master's progam in Accountancy, I am doing a replication study. I was wondering if anyone would be able to give me some advice on the following topic.
One of the variables that I have to create from the data is an industry dummy. This dummy should have the value "1" if the firm-year has a industry code (sic2) which is among the 6 most frequent industry codes in the dataset, and "0" otherwise.
My data:
Code:
* Example generated by -dataex-. clear input str10 tic long gvkey2 double fyear float sic2 "PNW" 1075 2013 49 "PNW" 1075 2014 49 "PNW" 1075 2015 49 "ABT" 1078 2013 38 "ABT" 1078 2014 38 "ABT" 1078 2015 38 "AET" 1177 2013 63 "HON" 1300 2013 99 "HON" 1300 2014 99 "HON" 1300 2015 99 "AEP" 1440 2013 49 "AEP" 1440 2014 49 "AEP" 1440 2015 49 end
Code:
groups sic2, order(h) select(6) /// From the table can be obtained that the six most frequent sic codes are 49, 28, 73, 60, 38 and 63. gen D_IND = 0 foreach i in 28 38 49 60 63 73 { replace D_IND = 1 if sic2 == `i' }
Is there a way to do this?
For your information, I am using Stata 16.1.
I hope this gives you enough information about my question. Please let me know if you can help me out!
Kind regards,
Lianne
Comment