I'm need help in recoding numeric variables to characters.
-
Login or Register
- Log in with
clear input mos freq 5 1 6 22 7 101 8 88 9 8 end expand freq * Your original form tab mos * String format (Bad idea) generate mos_string = "May" if mos == 5 replace mos_string = "June" if mos == 6 replace mos_string = "July" if mos == 7 replace mos_string = "August" if mos == 8 replace mos_string = "September" if mos == 9 * Tabulate: notice that months are now alphabetically ordered tab mos_string
mos_string | Freq. Percent Cum. ------------+----------------------------------- August | 88 40.00 40.00 July | 101 45.91 85.91 June | 22 10.00 95.91 May | 1 0.45 96.36 September | 8 3.64 100.00 ------------+----------------------------------- Total | 220 100.00
* Instead, try labeling: label define month_name 5 "May" 6 "June" 7 "July" 8 "August" 9 "September" label values mos month_name * Now the order makes sense tab mos
mos | Freq. Percent Cum. ------------+----------------------------------- May | 1 0.45 0.45 June | 22 10.00 10.45 July | 101 45.91 56.36 August | 88 40.00 96.36 September | 8 3.64 100.00 ------------+----------------------------------- Total | 220 100.00
levelsof mos, local(months) foreach m of local months { label define month_name `m' "`:word `m' of `c(Months)''", add } label values mos month_name
creturn list
Comment