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: Re: rolling standard deviation [was: ""]

From   Austin Nichols <>
Subject   Re: st: RE: Re: rolling standard deviation [was: ""]
Date   Wed, 29 Jun 2011 13:57:54 -0400

florian et al.
Note that using the business calendar or redefining elapsed days in
another way and then estimating a SD on pooled data requires an
assumption about poolability.  If changes in the data-generating
process accrue daily (not just Mon-Fri) and exhibit positive serial
correlation, then changes over three days could well exhibit a much
higher SD than one-day changes, which might be a difference of
substantial import, depending on what you intend to do with the
estimated SD.  But you could check this in your data like so:

sysuse sp500, clear
g dow=dow(date)
tsset date
g dd=date-date[_n-1]
ta dow dd
levelsof dd, loc(ds)
g d=.
qui foreach d of loc ds {
 g d`d'=ln(close)-ln(L`d'.close)
 replace d=d`d' if dd==`d'
su d1 if dd==1
su d3 if dd==3
g faked=_n
tsset faked
rolling, w(30) keep(date) clear nodots:su d
su sd

Note that the above calculates the SD for each day over the last 30
business days and you might want 126 business days to represent 6
calendar months, or 130 days; if you really wanted the last 6 calendar
months you would need to define more precisely how you want to measure
that (all business days back to the same number day in that past
month? what about Aug 31?).

On Wed, Jun 29, 2011 at 8:25 AM, Nick Cox <> wrote:
> Stata 12 supports business calendars:
> Nick
> Maarten Buis
> On Wed, Jun 29, 2011 at 1:29 PM,  wrote:
>> I'm having a hard time trying to calculate the standard deviation of the first difference of logarithms of daily exchange rates for the past 6 month (or 180 days).
>> As I'm using a huge dataset with daily data, I have gaps (or missings, if I use the fillin command before).
> Such gaps are often the result of the fact that the data is not
> generated by a daily process, e.g. no data for weekends and holidays.
> In that case the calender time is not the appropriate time axis when
> doing your analysis. For solutions see: Christopher F. Baum (2007)
> "Stata tip 40: Taking care of business" The Stata Journal, 7(1):
> 137--139. <>
> For computing the standard deviation of the past six months I would
> use -rolling-, see: -help rolling-.

*   For searches and help try:

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