Hi, following is an example chunk of my data set.
What I want to do is compute totals in the following fashion:
I want to add the numbers in the estab column for naics codes that are 3 digit but within broader groups. In this example, the broader groups start from naics codes 11 and 23.
For 11, I want to add estab numbers for naics codes 113, 114 and 115.
For 23, I want to add estab numbers for naics codes 233, 234 and 235.
Then I want to do the same for naics codes that are 4 digit. For example: 233 is the broader group and I want to add the numbers in estab column for naics 2331, 2332 and 2333.
Any help would be greatly appreciated, thank you!
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float countyid str6 naics long estab long total 1001 "11" 23 0 1001 "113" 0 1001 "114" 0 1001 "1141" 0 1001 "1142" 0 1001 "115" 0 1001 "1151" 0 1001 "1152" 0 1001 "1153" 0 1001 "23" 344 98 1001 "233" 98 1001 "2331" 13 1001 "2332" 73 1001 "2333" 12 1001 "234" 0 1001 "2341" 0 1001 "2349" 0 1001 "235" 0 1001 "2351" 16 1001 "2352" 35 1001 "2353" 22 1001 "2354" 31 1001 "2355" 43 1001 "2356" 22 1001 "2357" 0 1001 "2359" 67 end
I want to add the numbers in the estab column for naics codes that are 3 digit but within broader groups. In this example, the broader groups start from naics codes 11 and 23.
For 11, I want to add estab numbers for naics codes 113, 114 and 115.
For 23, I want to add estab numbers for naics codes 233, 234 and 235.
Then I want to do the same for naics codes that are 4 digit. For example: 233 is the broader group and I want to add the numbers in estab column for naics 2331, 2332 and 2333.
Any help would be greatly appreciated, thank you!
Comment