I am trying to change an income_change categorical variable from 5 groups to 3 groups.
Currently the variable looks:
tab income_change frequency
Decreased by more than 25% | 333
Decreased by 1-25% | 331
Stayed the same | 222
Increased by 1-25% | 23
Increased by more than 25% | 12
And the variable is stored as:
storage display value
variable name type format label variable label
--------------------------------------------------------------------------------------------------------------------------
income_change int %26.0g Lchg
To create three groups based on the five categories above, I ran this, but I get this error message "type mismatch"
gen perc_change = income_change
recode perc_change ="Income Decreased" if perc_change =="1" | if perc_change =="2"
recode perc_change ="Same Income" if perc_change =="3"
recode perc_change ="Income Increased" if perc_change =="4" | if perc_change =="5"
The perc_change variable is stored as follows:
storage display value
variable name type format label
--------------------------------------------------------------------------------------------------------------------------
perc_change float %9.0g
Solved with the proposed solution below:
gen inc_change = income_change
gen inc_perc_change = ""
replace inc_perc_change ="Income Decreased" if inc_change == 1 | inc_change == 2
replace inc_perc_change ="Same Income" if inc_change_perc == 3
replace inc_perc_change ="Income Increased" if inc_change_perc == 4 | inc_change_perc == 5
tab inc_perc_change
Produced the graph I was looking for with this:
catplot tn_cor22_str inc_perc_change, percent(tn_cor22_str)