Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: median for last 3 years within groups


From   Nick Cox <n.j.cox@stata.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: median for last 3 years within groups
Date   Mon, 29 Sep 2008 11:30:03 -0500

Look at -egen, median()-.

Nick
n.j.cox@durham.ac.uk

Fabian Brenner wrote:

I have 10 different "groups" of people and I want to get the median "age" (across observations) for the last 3 years within each group for each year.
I have the following idea but unfortunately I don't have any idea how to get the median.

sort year group
genenerate threeyearmedian=.
generate median=.

quietly forvalues k = 1/10 {
quietly forvalues y = 1982/2006 { local y1 = `y' - 3 local y2 = `y' - 1
generate median = ??? median age ??? if inrange(year, `y1', `y2') & group==`k' replace threeyearmedian median if year == `y' & group ==`k' } }
*
*   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   |   What's new   |   Site index