**[TS] tssmooth ma** -- Moving-average filter

__Syntax__

Moving average with uniform weights

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

Moving average with specified weights

**tssmooth** **ma** [*type*] *newvar* **=** *exp* [*if*] [*in*]**,** __we__**ights(**[*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**