Constructing Variables

Hi guys,
I'm new to Stata and am not too familiar with statistical software. I'm trying to construct some different variables. I have OCC, which is a 3-digit Census occupation code. This variables ranges from 3-889. I need to break down the OCC into five different categories. The first category is managerial and professional workers and the OCC code for this is 3-199. Each other category is similar in that they all have a set range of numbers. I'm just not sure what the code is to generate each variable from a range of the OCC.

Thanks for the help


Take a look at the recode command, eg
recode OCC (3/199=1 "Managerial and professional") (etc), gen(occ_cat)
Last edited:


Ninja say what!?!
gen OCC1=0
replace OCC1=1 if (OCC>=3)*(OCC<=199)

gen OCC2=0
replace OCC2=1 if (OCC>=200)*(OCC<= some value)

Hello there,

Not much to add to the answers above but the problem is familiar to me since I work on occupational coding. Personnaly I use the command "inrange", which is very convenient to aggregate categories:

gen occ1d = 1 if inrange(occ, 3, 199)
replace etc.