help rollstat-------------------------------------------------------------------------------

Title

rollstat-- Rolling-window statistics fortime seriesorpanel data

Syntax

rollstat[varlist] [if] [in],statistic(statname)[options]

optionsDescription ------------------------------------------------------------------------- Mainstatistic(statname)report specified statistic (required option).Options

w(#)number of consecutive data points in each sample (it should be an integer grater than one), defaultw(3).forceforces results to be computed when some of a particular window's values are missing. ------------------------------------------------------------------------- User musttssetfor time series or panel databeforeusingrollstat; see[TS] tsset.

statnamedefinition ---------------------------------------------------------------------meanmeansumsumsdstandard deviationVarvarianceminminimummaxmaximumNcount of nonmissing observations ---------------------------------------------------------------------

Description

rollstatgenerates a new variable named_`statistic´`w´_varname(i.e._sd3_gdp for the 3 period standard deviation of GDP) containing the rolling calculation of the specified statistic (under the aegis oftsset) with window size defined in option w. Results are placed at the end of the window. Althoughrollstatworks with unbalanced panels (where the start and/or end points differ across units),rollstatdoes not allow gaps within the observations of a time series; that is, the value of an observation for a given period may be missing, but the observation itself must be defined. Gaps in time series may be dealt with viatsfill; see[TS] tsfill.

+---------+ ----+ Options +----------------------------------------------------------

w(#)defines the window size. If there are missing data, the actual number of observations used byrollstatmay be less thanw(#).

forceforces results to be computed when some of a particular window's values are missing (and data has at least two observations). whenforceis set,rollstatstarts accumulating from the first two observations of the sample until it reaches the desired window size. Then it continues with the defined window size to the end of sample.

Examples

. tsset year, y

. rollstat gdp cpi, s(sd). rollstat gdp, s(mean) w(5). rollstat gdp, s(sd) force

AcknowledgementsWe acknowledge useful advice of Christopher F. Baum on previous version of this > routine.

AuthorsMaximo Sangiacomo & Demian Panigo

Email:msangia@hotmail.comEmail:panigo@gmail.com