Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: mean and sd of lagged variables

From   "Ben Hoen" <>
To   <>
Subject   Re: st: RE: mean and sd of lagged variables
Date   Fri, 29 Jul 2011 09:08:12 -0400

Well Nick, you have blown right past my level of competency.  I could not
figure out how to execute a rolling command correctly.

I did get a manual mean and sd to work, but now I am curious about how to
use rolling, assuming that if I learn to use it for this purpose it will
have many other uses.

Here is the ado file that is producing what I want, manually

keep if company==1
tsset year
g ml3i=(L3.invest + L2.invest + l1.invest)/3
g sdl3i= (((L3.invest-ml3i)^2 + (L2.invest-ml3i)^2 + ///
label var ml3i "ma lag3 of invest"
label var sdl3i "sd lag3 of invest"
list year invest ml3i sdl3i, sep(20)

And this was what I was working on with .rolling until I gave up:

rolling ml3ri=r(mean) sdl3ri=r(sd), window(3):summarize invest, detail
list year invest ml3ri sdl3ri, sep(20)

Can you see where my error(s) was(were)? Will the rolling command allow me
to add variables like .generate or .egen (the sample ado seemed to discard
the working data for new data - but again, maybe I was not getting it)?

I don't know what I would do without this list,


st: RE: mean and sd of lagged variables

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index