Stata 15 help for tssmooth ma

[TS] tssmooth ma -- Moving-average filter

Syntax

Moving average with uniform weights

tssmooth ma [type] newvar = exp [if] [in], window(#l[#c[#f]]) [replace]

Moving average with specified weights

tssmooth ma [type] newvar = exp [if] [in], weights([numlist_l] <#c> [numlist_f]) [replace]

You must tsset your data before using tssmooth ma; [TS] tsset. exp may contain time-series operators; see tsvarlist.

Menu

Statistics > Time series > Smoothers/univariate forecasters > Moving-average filter

Description

tssmooth ma creates a new series in which each observation is an average of nearby observations in the original series. The moving average may be calculated with uniform or user-specified weights. Missing periods are excluded from calculations.

Options

window(#l[#c[#f]]) describes the span of the uniformly weighted moving average.

#l specifies the number of lagged terms to be included, 0 < #l < one-half the number of observations in the sample.

#c is optional and specifies whether to include the current observation in the filter. A 0 indicates exclusion and 1, inclusion. The current observation is excluded by default.

#f is optional and specifies the number of forward terms to be included, 0 < #f < one-half the number of observations in the sample.

weights([numlist_l] <#_c> [numlist_f]) is required for the weighted moving average and describes the span of the moving average, as well as the weights to be applied to each term in the average. The middle term literally is surrounded by < and >, so you might type weights(1/2 <3> 2/1).

numlist_l is optional and specifies the weights to be applied to the lagged terms when computing the moving average.

#_c is required and specifies the weight to be applied to the current term.

numlist_f is optional and specifies the weights to be applied to the forward terms when computing the moving average.

The number of elements in each numlist is limited to one-half the number of observations in the sample.

replace replaces newvar if it already exists.

Examples

Setup . webuse sales1 . tsset

Create uniformly weighted moving average of sales using 2 lagged terms, 3 forward terms, and the current observation in the filter . tssmooth ma sm1=sales, window(2 1 3)

Create weighted moving average of sales using 1 and 2 as the weights for the lagged terms, 3 as the weight for the current term, and 2 and 1 as the weights for the forward terms . tssmooth ma sm2=sales, weights(1/2 <3> 2/1)

Video example

Moving-average smoothers

Stored results

tssmooth ma stores the following in r():

Scalars r(N) number of observations r(w0) weight on the current observation r(wlead#) weight on lead #, if leads are specified r(wlag#) weight on lag #, if lags are specified

Macros r(method) smoothing method r(exp) expression specified r(timevar) time variable specified in tsset r(panelvar) panel variable specified in tsset


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