Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

Re: st: Rolling Means and Standard Deviations

From   Scott Merryman <>
Subject   Re: st: Rolling Means and Standard Deviations
Date   Wed, 30 Nov 2011 07:04:19 -0600

Take a look at the last example in the -rolling- help file - your
syntax does not make any sense.

Perhaps you want something like this:

tsset t
generate ibmadj = ibm - irx
generate spxadj = spx - irx
rolling  mean_ibm=r(mean) sd_ibm=r(sd), window(200) saving(ibm,
replace) keep(date): sum ibmadj
rolling  mean_spx=r(mean) sd_spx=r(sd), window(200) saving(spx,
replace) keep(date): sum spxadj
merge 1:1 date using ibm, nogenerate
merge 1:1 date using spx, nogenerate
l in -20/l


On Wed, Nov 30, 2011 at 6:40 AM, David Ashcraft
<> wrote:
> Hi Statalist:
> I am trying to find the rolling mean and standard deviation. I know that I can use -rolling- command but somehow lost my track. Please see the example below:
> use
> tsset t
> generate ibmadj = ibm - irx
> generate spxadj = spx - irx
> now I want to generate means and standard deviation of both ibmadj and spxadj with window of 200 days. I looked in the Stata manual, it mentioned about the command. I believe, I should do the following:
> rolling  _sd, window(200) saving(means, replace) keep(date): gen sd=r(sd)
> rolling  _mean, window(200) saving(means, append) keep(date): gen mean=r(mean)
> But this is not working. Any help will be greatly appreciated.
> Regards
> David

*   For searches and help try:

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