dogIn finance/ accounting research, we have to often create industry dummy variables to control for industry effects.

Often, we obtain four digit SIC code but need to use either two digit or three digit SIC codes.

Q: How to create two/three digit code?

***************

*suppose sic4 is the industry variable containing four digit SIC codes.

**If sic4 is numeric, then

gen sic3=int(sic4/10)

gen sic2=int(sic4/100)

**If sic4 is a string then

gen sic3=substr(sic4,1,3)

gen sic2=substr(sic4,1,2)

**To create industries dummies,

tab sic3, gen(sic3_)

tab sic2, gen(sic2_)

***If this code helped, please support this blog by liking the posts and do please ask more questions, so we can all learn together 😀

Advertisement