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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: Rolling Means and Standard Deviations


From   David Ashcraft <ashcraftd@rocketmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Rolling Means and Standard Deviations
Date   Wed, 30 Nov 2011 04:40:37 -0800 (PST)

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 http://www.stata-press.com/data/r11/ibm
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:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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