I have a panel data set from survey data in long format that has to be kept confidential, that's why I can't show it here.
Nevertheless, I have the variable called "net yearly household income" which is numeric (float).
I would like to generate percentiles (p5, p10, p25 and so forth) and then create string variables for those percentiles "p5", "p10","p25"... in order to generate the categories labelled as "categories of income percentiles" and run regressions out of that.
The variable thinc_m = the net yearly household income
The variable ccthinc_m is the name of new variable
The code I have been using to create centiles is this one:
Code:
xtile ccthinc_m = thinc_m, nq (10) tab ccthinc_m tabstat thinc_m, stat (n mean min max sd p50) by (ccthinc_m)
Code:
centile thinc_m , c(5 10 25 50 75 90 95) local nc : word count `r(centiles)' qui forval i = 1/`nc' { local list "`list'`r(c_`i')'," } summarize thinc_m, meanonly gen cthinc_m= recode(thinc_m,`list'`r(max)')
In summary, the first question: 1) How can I turn the centiles into string categories (I tried using recode/replace commands, but it seems that I need more difficult codes) and the second: 2) Which of the two codes that I used for centiles is considered better?
If you have better ideas, I am all ears. And if you can help me on this I thank you in advance.
Regards
0 Response to Creating categories of string variables from a continuous variable
Post a Comment