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" <[email protected]>
To   <[email protected]>
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 

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

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 

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) 

[email protected] 

*   For searches and help try:

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