Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Re: How to generate quantile categories by group/varlist?
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Re: How to generate quantile categories by group/varlist?
Date
Thu, 25 Oct 2012 09:33:45 +0100
Sounds like Indonesia!
UIi Kohler has written an -xtile()- function for -egen- that does
this; see the -egenmore- package (SSC).
Suppose that didn't exist. Some technique is shown by
egen group = group(province)
su group, meanonly
gen q_epc = .
quietly forval i = 1/`r(max)' {
xtile work = epc if group == `i' [fweight = weind],
nquantiles(5)
replace q_epc = work if group == `i'
drop work
}
drop group
See also
FAQ . . . . . . . . . . Making foreach go through all values of a variable
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
8/05 Is there a way to tell Stata to try all values of a
particular variable in a foreach statement without
specifying them?
http://www.stata.com/support/faqs/data/foreach.html
Nick
On Thu, Oct 25, 2012 at 6:13 AM, Alika Tuwo <[email protected]> wrote:
> I'm working on a national survey data and I'm trying to group
> expenditure per capita according to provincial (NOT national)
> quantiles.
>
> prov - code for province (33 unique values)
> ecp - expenditure per capita
> weind - individual weight
>
>
> If I were to group 'epc' by national quintiles I would use the command:
>
> xtile q_epc = epc [fweight = weind], nquantiles(5)
>
> But what if I would like to generate quantile groups for each
> province? Is there any quick way to do this? The 'by' option wouldn't
> work with 'xtile'. So far I've had to work on each province
> separately.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/