I'm working with my data file but find difficulty on labelling derived categorical variables.
In my data set, there are more than 100 crude variables and they range from 1 to 28.
And crudecat variables are derived from crude variables.
Then, according to crude variables, I want to label my variables as following rules:
crude variables | crudecat variables | |
if crude variables=1 | → | 1 |
if crude variables=2 | → | 2 |
if crude variables=3 | → | 3 |
if crude variables>3 | → | 4+ |
gen crudecat=.
replace crudecat=1 if crude==1
replace crudecat=2 if crude==2
……
But when I entered "replace crrudecat=4+ if crude>3 & crude<3", it didn't work. And I also noticed that "gen" command only create numerical variables rather than categorical variables that I want.
So I tried to use "label" command, I typed:
label define crudecat 1 "1" 2 "2" 3 "3" >3 "4+"
or
label define crudecat 1 "1" 2 "2" 3 "3" 3/99 "4+" (Because the range from crude variables are 1 to 28 and I guessed "/" can use to denote "range to" , but it failed. After that command, my crude variables which equal to 4 change to "/" and others stay same. I don't know why.)
or
label define crudecat 1 "1" 2 "2" 3 "3" 3/max "4+"
All methods show errors and don't work. Most of time we only label variables with fixed number like:
label define crudecat 1 "1" 2 "2 "
It tortures me for days.
Thanks for your time and help
0 Response to Help on labeling categorical variables
Post a Comment