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

st: RE: median for last 3 years within groups

From   "Martin Weiss" <>
To   <>
Subject   st: RE: median for last 3 years within groups
Date   Mon, 29 Sep 2008 18:06:34 +0200

sysuse auto, clear
_pctile mpg, p(50)
ret li
di in red r(r1)

to get the median elegantly into r(r1). I hope you know how to take it from
there... BTW, -if- and -in- are allowed with -_pctile-...


-----Original Message-----
[] On Behalf Of Fabian Brenner
Sent: Monday, September 29, 2008 6:03 PM
Subject: st: median for last 3 years within groups

Dear all:

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') &
	replace threeyearmedian median if year == `y' & group ==`k' 

Hope someone can help me.

Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen:
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index