Statalist


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

st: Re: creating average over past three years within groups


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: Re: creating average over past three years within groups
Date   Fri, 3 Oct 2008 14:22:16 +0200

Not sure what you are doing with all those -locals-. Just -summarize, meanonly- with your -if- statements and type -ret li- afterwards. There you will find the average as r(mean) to plug into your -replace- operation.

HTH
Martin
_______________________
----- Original Message ----- From: "Fabian Brenner" <[email protected]>
To: <[email protected]>
Sent: Friday, October 03, 2008 2:17 PM
Subject: st: creating average over past three years within groups



Dear all:

I used -bysort year group : egen oneyearmedian = median(age)- to create the median within each group (1-10) for each year (1974-2000).

Now I want to get the three year average of the three median for each group for the most recent three years:

generate threeyearaverage = .
sort year group

quietly forvalues k = 1/10 {
quietly forvalues y = 1974/2000 {
local median3 = oneyearmedian if year == `= `y' - 3' & industry == `k',
local median2 = oneyearmedian if year == `= `y' - 2' & industry == `k',
local median1 = oneyearmedian if year == `= `y' - 1' & industry == `k',
replace fiveyearmedian = (`median3' + `median2' + `median1' ) / 3 if year == `y' & group == `k'
}
}

But stata always says: if not allowed r(101);

What do I wrong? Hope someone can help me.
Fabian Brenner


--
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@gmx
*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index