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

From |
"Fabian Brenner" <Fabian.Brenner@gmx.de> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Fri, 03 Oct 2008 15:04:30 +0200 |

Dear Martin: your proposal will result in the 3-year-mean of means; but I want to get the 3-year-mean of (yearly) medians (across observations). This is why I cannot use meanonly; I would need "medianonly" for your solution, which unfortunately doesn't exist. Please correct me if I'm wrong. This is why I want to do it like this, but I don't kow what is wrong (Stata says: if not allowed r(101)) 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' } } Hope someone could tell me..Thanks. -------- Original-Nachricht -------- > Datum: Fri, 3 Oct 2008 14:52:12 +0200 > Von: "Martin Weiss" <martin.weiss1@gmx.de> > An: statalist@hsphsun2.harvard.edu > Betreff: Re: st: Re: creating average over past three years within groups > 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" <Fabian.Brenner@gmx.de> > To: <statalist@hsphsun2.harvard.edu> > 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" <martin.weiss1@gmx.de> > >> An: statalist@hsphsun2.harvard.edu > >> 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" <Fabian.Brenner@gmx.de> > >> To: <statalist@hsphsun2.harvard.edu> > >> 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/ -- GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion! http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196 * * 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/

**Follow-Ups**:**Re: st: Re: creating average over past three years within groups***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**Re: st: Re: creating average over past three years within groups***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**References**:**st: creating average over past three years within groups***From:*"Fabian Brenner" <Fabian.Brenner@gmx.de>

**st: Re: creating average over past three years within groups***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**Re: st: Re: creating average over past three years within groups***From:*"Fabian Brenner" <Fabian.Brenner@gmx.de>

**Re: st: Re: creating average over past three years within groups***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**Re: st: Re: creating average over past three years within groups** - Next by Date:
**Re: st: Re: creating average over past three years within groups** - Previous by thread:
**Re: st: Re: creating average over past three years within groups** - Next by thread:
**Re: st: Re: creating average over past three years within groups** - Index(es):

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