Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[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 <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
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 <mcdonald.1@nd.edu> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index