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: Place in quartiles based on prior year - panel data


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Place in quartiles based on prior year - panel data
Date   Wed, 28 Mar 2012 00:12:23 +0100

Sounds like

webuse grunfeld, clear
egen g_t = group(time)
gen tokeep = .
su g_t

forval t = 1/`= r(max) - 1' {
       local T = `t' + 1
       pctile work = invest if g_t == `t', n(4)
       xtile result = invest if g_t == `T', cut(work)
       replace tokeep = result if g_t == `T'
       drop work result
}

Nick

On Tue, Mar 27, 2012 at 9:51 PM, Bill McDonald <[email protected]> wrote:
> I have a variable, lets say mpg in a panel of data.  I would like to put each observation into a quartile based on quartile cutoffs from the prior year.  I know how to brute force a solution by have not been able to figure out some combination of xtile, egenmore or cutoff that will categorize the variable based on the prior year quartile cutoffs.  Any help would be appreciated.
>
>
> Bill
>
> *
> *   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/

*
*   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