Bookmark and Share

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: creating deciles by location by year


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: creating deciles by location by year
Date   Wed, 15 Aug 2012 09:04:37 +0100

This isn't really a different problem. It is also an FAQ:

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

gen size_decile = .
egen group = group(location year)
su group, meanonly

forval i = 1/`r(max)' {
          xtile decile_temp=size if group==`i', nq(10)
          replace size_decile = decile_temp if group == `i'
          drop decile_temp
}



On Wed, Aug 15, 2012 at 2:28 AM, Alexey Lyubimov <[email protected]> wrote:

> I am using Stata 11, I have a panel data set that has multiple years, locations, and companies.  I am trying to create deciles by year by location.
> I use the following code to calculate deciles by year, but how can I add one more level and calculate by year by location?
>
> gen size_decile = .
> levelsof year, local(tempyear)
> foreach i in `tempyear' {
> xtile decile_temp=size if year==`i', nq(10)
> replace size_decile = decile_temp if missing(size_decile)
> drop decile_temp
> }
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index