Stata 15 help for rolling

[TS] rolling -- Rolling-window and recursive estimation

Syntax

rolling [exp_list] [if] [in] , window(#) [options] : command

options Description ------------------------------------------------------------------------- Main * window(#) number of consecutive data points in each sample recursive use recursive samples rrecursive use reverse recursive samples

Options clear replace data in memory with results saving(filename, ...) save results to filename; save statistics in double precision; save results to filename every # replications stepsize(#) number of periods to advance window start(time_constant) period at which rolling is to start end(time_constant) period at which rolling is to end keep(varname[, start]) save varname with results; optionally, use value at left edge of window

Reporting nodots suppress replication dots dots(#) display dots every # replications noisily display any output from command trace trace command's execution

Advanced reject(exp) identify invalid results ------------------------------------------------------------------------- * window(#) is required. You must tsset your data before using rolling; see [TS] tsset. command is any command that follows standard Stata syntax and allows the if qualifier. The by prefix cannot be part of command. aweights are allowed in command if command accepts aweights; see weight.

Menu

Statistics > Time series > Rolling-window and recursive estimation

Description

rolling executes a command on each of a series of windows of observations and stores the results. rolling can perform what are commonly called rolling regressions, recursive regressions, and reverse recursive regressions. However, rolling is not limited to just linear regression analysis: any command that stores results in e() or r() can be used with rolling.

Options

+------+ ----+ Main +-------------------------------------------------------------

window(#) defines the window size used each time command is executed. The window size refers to calendar periods, not the number of observations. If there are missing data (for example, because of weekends), the actual number of observations used by command may be less than window(#). window(#) is required.

recursive specifies that a recursive analysis be done. The starting period is held fixed, the ending period advances, and the window size grows.

rrecursive specifies that a reverse recursive analysis be done. Here the ending period is held fixed, the starting period advances, and the window size shrinks.

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

clear specifies that Stata replace the data in memory with the collected statistics even though the current data in memory have not been saved to disk.

saving(filename [, suboptions]) creates a Stata data file (.dta file) consisting of (for each statistic in exp_list) a variable containing the replicates.

double specifies that the results for each replication be saved as doubles, meaning 8-byte reals. By default, they are saved as floats, meaning 4-byte reals.

every(#) specifies that results be written to disk every #th replication. every() should be specified in conjunction with saving() only when command takes a long time for each replication. This will allow recovery of partial results should your computer crash. See [P] postfile.

stepsize(#) specifies the number of periods the window is to be advanced each time command is executed.

start(time_constant) specifies the date on which rolling is to start. start() may be specified as an integer or as a date literal.

end(time_constant) specifies the date on which rolling is to end. end() may be specified as an integer or as a date literal.

keep(varname[, start]) specifies a variable to be posted along with the results. The value posted is the value that corresponds to the right edge of the window. Specifying the start() option requests that the value corresponding to the left edge of the window be posted instead. This option is often used to record calendar dates.

+-----------+ ----+ Reporting +--------------------------------------------------------

nodots suppresses the display of the replication dot for each window on which command is executed. By default, one dot character is printed for each window. A red `x' is printed if command returns with an error or if any value in exp_list is missing.

dots(#) displays dots every # replications. dots(0) is a synonym for nodots.

noisily causes the output of command to be displayed for each window on which command is executed. This option implies the nodots option.

trace causes a trace of the execution of command to be displayed. This option implies the noisily and nodots options.

+----------+ ----+ Advanced +---------------------------------------------------------

reject(exp) identifies an expression that indicates when results should be rejected. When exp is true, the saved statistics are set to missing values.

Example: Collecting coefficients

. webuse lutkepohl2 . tsset qtr . rolling _b, window(30): regress dln_inv dln_inc dln_consump

Same as above, _b is default for e-class commands . webuse lutkepohl2, clear . tsset qtr . rolling, window(30): regress dln_inv dln_inc dln_consump . list in 1/10, abbrev(14)

Example: Collecting standard errors

. webuse lutkepohl2, clear . tsset qtr . rolling _se, window(10): regress dln_inv dln_inc dln_consump . list in 1/10, abbrev(14)

Example: Collecting stored results

. webuse lutkepohl2, clear . tsset qtr . rolling mean=r(mean) median=r(p50), window(10): summarize inc, detail . list in 1/10

. webuse lutkepohl2, clear . tsset qtr . rolling ratio=(r(mean)/r(p50)), window(10): summarize inc, detail . list in 1/10

Stored results

rolling sets no r- or e-class macros. The results from the command used with rolling, depending on the last window of data used, are available after rolling has finished.


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