Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: how to cut at percentiles


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: how to cut at percentiles
Date   Mon, 12 Aug 2002 13:04:15 +0100

Radu Ban
> 
> Thanks for the previous help.
> I have an income variable and I would like to create a set 
> of dummies for
> whether the income is between certain percentiles (i.e 
> inc10 for income b/w
> the 10th and 15th percentile and so on). I know that 
> -centile- generates
> requested centiles, but I'm not sure how to put the results 
> of this command
> into a list that can be used with the -egen cut- command.
 
I'm assuming there is some reason why -_pctile- 
is irrelevant. 

As reported previously, -egen, cut()-, as updated 
on 9 August 2002, ignores values beyond the first 
and penultimate arguments of -at()-. Thus if 
you used it, you would need to apply corrective surgery 
anyway. 

Of various alternatives, writing your own code 
is one possibility. Illustration: -mpg- in auto 
data. 

1. Calculate your percentiles 

centile mpg , c(5 10 25 50 75 90 95) 

2. Pick them up and put them in a comma-separated 
list

local nc : word count `r(centiles)' 
qui forval i = 1/`nc' { 
	local list "`list'`r(c_`i')'," 
} 

3. That list will end with a comma. We need 
to add the maximum to the list: 

su mpg, meanonly 

4. Generate your classified variable

gen cmpg = recode(mpg,`list'`r(max)') 

5. and thus the dummies: 

tab cmpg, gen(cmpg) 


Nick 
n.j.cox@durham.ac.uk 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index