Tips - Stata: How to generate composite categorical variables and indicate/dummy variables, convert a continuous variable into a categorical variable
1. to generate composite categorical variables:
.egen compvar=group(var1 var2 var3), label
Now, the dataset has a categorical variable with the different combinations of three variables: var1, var2, and var3.
2. to generate indicate variables:
.tabulate compvar, generate(compvar)
Now, the dataset has multiple indicate variables with a prefix of ‘compvar’
3. to convert a continuous variable into a categorical variable
.gen agecat = recode(age, 24,29,34,39,44,49,54,59,64, ///
69, 74, 79, 90) if !missing(age)
or
.gen age13grp = 1+irecode(age,24,29,34,39,44,49,54,59,64, ///
69, 74, 79, 90) if !missing(age)
3. to convert a continuous variable into a categorical variable
.gen agecat = recode(age, 24,29,34,39,44,49,54,59,64, ///
69, 74, 79, 90) if !missing(age)
or
.gen age13grp = 1+irecode(age,24,29,34,39,44,49,54,59,64, ///
69, 74, 79, 90) if !missing(age)
No comments:
Post a Comment