Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Grouping SIC codes

    Hello all,

    I want to generate new variable for Industry dummies (say SIC). I want to further condense the industries based on their two digit SIC codes. For example, codes 23-27, 30-37, 40-49, 51-59, 60-69, 70-80, rest in category for OHTERS, making total of 7 industries for my analysis.

    I would appreciate help in this regard.

    Thanks in advance.






    Code:
           SIC |      Freq.     Percent        Cum.
    ------------+-----------------------------------
             15 |         10        1.46        1.46
             23 |         10        1.46        2.93
             27 |         10        1.46        4.39
             28 |        110       16.11       20.50
             29 |         10        1.46       21.96
             30 |         20        2.93       24.89
             32 |         19        2.78       27.67
             33 |         38        5.56       33.24
             35 |         48        7.03       40.26
             36 |         16        2.34       42.61
             37 |         85       12.45       55.05
             38 |         10        1.46       56.52
             42 |         10        1.46       57.98
             45 |         20        2.93       60.91
             48 |         30        4.39       65.30
             49 |         18        2.64       67.94
             51 |         13        1.90       69.84
             53 |         10        1.46       71.30
             59 |         11        1.61       72.91
             60 |         10        1.46       74.38
             61 |         10        1.46       75.84
             62 |         10        1.46       77.31
             63 |         20        2.93       80.23
             65 |         56        8.20       88.43
             67 |          7        1.02       89.46
             73 |         23        3.37       92.83
             79 |         10        1.46       94.29
             80 |         20        2.93       97.22
             99 |         19        2.78      100.00
    ------------+-----------------------------------
          Total |        683      100.00




  • #2
    You can use -recode-:
    Code:
    recode SIC (23/27=1) (30/37=2) ... , gen(SIC_group)
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Irfan, Carole's code elegantly solves your problem.

      I am posting here just because I find myself frequently trying to create 2- and 3-digit SIC codes from 4-digit SIC codes and thought I would post two different ways to accomplish that in Stata (for those coming along later).

      Code:
      * Creating 2- and 3-digit SIC codes (from 4-digit code)
      * Also, could put in Excel and just use LEFT() function (and then merge in)
      
      gen target_SIC_3digit = substr(string(target_SIC),1,3)  /* converts target_SIC to a string, then takes left 3 numbers */
      gen target_SIC_2digit = substr(string(target_SIC),1,2)
      
      destring target_SIC_3digit, replace
      destring target_SIC_2digit, replace
      order target_SIC_3digit target_SIC_2digit, after(target_SIC)  // just places them after target_SIC so all SIC code variables are together
      
      
      * Creating 2- and 3-digit SIC codes (without converting to string)
      gen target_SIC_3digit = int(target_SIC/10)  // int() or floor() creates integer by rounding down. So int(367 / 10) = 36
      gen target_SIC_2digit = int(target_SIC/100)
      order target_SIC_3digit target_SIC_2digit, after(target_SIC)

      Comment

      Working...
      X