Obsidian | Level 7

## Creating industry dummies uisng array

Hi,

I tried to create dummy variables for the large sample (over 10,000 firm-year observations). The following code assigns each industry. This is very long. Is there array statement to read all industry (two digit SIC industry)fo the large sample and assign industry dummies using array statement? Thank you for your advice.

if sic2=1 then id1=1; else id1=0;

if sic2=10 then id2=1; else id2=0;

if sic2=12 then id3=1; else id3=0;

if sic2=13 then id4=1; else id4=0;

if sic2=14 then id5=1; else id5=0;

if sic2=16 then id6=1; else id6=0;

if sic2=20 then id7=1; else id7=0;

if sic2=21 then id8=1; else id8=0;

if sic2=23 then id9=1; else id9=0;

if sic2=24 then id10=1; else id10=0;

if sic2=26 then id11=1; else id11=0;

if sic2=27 then id12=1; else id12=0;

if sic2=28 then id13=1; else id13=0;

if sic2=29 then id14=1; else id14=0;

if sic2=30 then id15=1; else id15=0;

if sic2=32 then id16=1; else id16=0;

if sic2=33 then id17=1; else id17=0;

if sic2=34 then id18=1; else id18=0;

if sic2=35 then id19=1; else id19=0;

if sic2=36 then id20=1; else id20=0;

if sic2=37 then id21=1; else id21=0;

if sic2=38 then id22=1; else id22=0;

if sic2=39 then id23=1; else id23=0;

if sic2=40 then id24=1; else id24=0;

if sic2=42 then id25=1; else id25=0;

if sic2=44 then id26=1; else id26=0;

if sic2=45 then id27=1; else id27=0;

if sic2=47 then id28=1; else id28=0;

if sic2=48 then id29=1; else id29=0;

if sic2=49 then id30=1; else id30=0;

if sic2=50 then id31=1; else id31=0;

if sic2=51 then id32=1; else id32=0;

if sic2=53 then id33=1; else id33=0;

if sic2=54 then id34=1; else id34=0;

if sic2=58 then id35=1; else id35=0;

if sic2=59 then id36=1; else id36=0;

if sic2=70 then id37=1; else id37=0;

if sic2=72 then id38=1; else id38=0;

if sic2=73 then id39=1; else id39=0;

if sic2=75 then id40=1; else id40=0;

if sic2=78 then id41=1; else id41=0;

if sic2=79 then id42=1; else id42=0;

if sic2=87 then id43=1; else id43=0;

if sic2=99 then id44=1; else id44=0;

if sic2=15 then id45=1; else id45=0;

if sic2=25 then id46=1; else id46=0;

if sic2=80 then id47=1; else id47=0;

if sic2=82 then id48=1; else id48=0;

if sic2=89 then id49=1; else id49=0;

if sic2=2 then id50=1; else id50=0;

3 REPLIES 3
PROC Star

## Re: Creating industry dummies uisng array

You can do this using arrays, but you can't get around the fact that this is a custom mapping.  You will have to specify the mapping of which sic codes map to which ID variables.  This would be one way:

array siccodes {50} _temporary_ (1 10 12 13 14 16 ... 80 82 89 2);

array id {50};

code = whichn (sic2, of siccodes{*});

do _J_=1 to 50;

id{_J_} = 0;

end;

if (1 <= code <= 50) then id{code}=1;

The order if the elements in the _TEMPORARY_ array specifies the mapping.

Good luck.

Diamond | Level 26

## Re: Creating industry dummies uisng array

Use PROC GLMMOD to create dummy variables. You need a numeric Y variable for this to work, it can be random numbers or other gibberish.

proc glmmod data=yourdata outdesign=design outparms=parms;

class sic;

model y=sic;

run;

--
Paige Miller
Obsidian | Level 7

## Re: Creating industry dummies uisng array

I tried to run your 'glmmod' statement using assign one of existing variales for 'y'. The results look strange.

Do I need to create 'y'  ? Which is the best way (there are a lot of observations) to create 'y'?

What is the final result? Industry dummies?