Statalist


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

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


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

True, consecutive -summarize-s will overwrite the rclass results so you have to store the r(mean) them in -local-s. Apart from that, I do not know what is wrong with my proposal...

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



Dear Martin,

I don't know if I got what you mean, but as far as I know your proposal using -summarize, meanonly- would lead to the average (across the most recent three years) of the mean (across observations within each year).

But I want to get the average (across the most recent three years) of the median (across observations within each year), i.e. average1997=(median1997+median1996+median1995)/3

Hope someone could help me.
Fabian


[I guess your proposal would look like the following:
quietly forvalues k = 1/10 {
quietly forvalues y = 1974/2000 {
summarize age if year == `= `y' - 3' & group == `k', meanonly
local median3 = r(mean)
summarize roe if year == `= `y' - 2' & group == `k', meanonly
local median2 = r(mean)
summarize roe if year == `= `y' - 1' & industry == `k', meanonly
replace fiveyearmedian = (`median3' + `median2' + r(mean1 ) / 3 if year == `y' & group == `k'
}
}



-------- Original-Nachricht --------

Datum: Fri, 3 Oct 2008 14:22:16 +0200
Von: "Martin Weiss" <[email protected]>
An: [email protected]
Betreff: st: Re: creating average over past three years within groups

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