*! version 1.1 22feb2024

mvfilter -- Multivariate time-series filter.

Syntax

mvfilter
var
[varlist]
[if] [in] [, options]

options

Main
varlist contains exogenous variable(s) for the observed equation

trend(newvar) save the trend component in new a variable

cycle(newvar) save the cyclical component in a new variable

ar(#) specify the order of the autoregressive process in the cycle

smooth(#) smoothing parameter for the filter

type(string) specify the type of filter used

Other
details display the details of the Kalman filter estimation

optimal let the Kalman filter estimate the smoothing parameter

adjustment adjust the sample variance ratio of the dynamic filter
to match the static Hodrick-Prescott filter

loop display the convergence of the sample variance ratio of the
dynamic filter to the static Hodrick-Prescott filter

betacap constraints the autoregressive parameter to
min(beta,0.85). The default is unconstrained beta.

You must tsset your data before using mvfilter;
see [TS] tsset.

var and varlist may contain time series operators; see
tsvarlist.

Description

mvfilter uses the sspace high-pass filter to separate a
time series into trend and cyclical components. The trend component may
contain a deterministic or a stochastic trend. The smoothing parameter
determines the periods of the stochastic cycles that drive the stationary cyclical
component. It allows for and AR(p) process in the cyclical component and
for exogenous variables in the observed equation of the sspace representation

See [TS] sspace and [TS] tsfilter for an introduction to the methods implemented in
mvfilter.

Options

Main

varlist the exogenous variables will only enter the observed equation.
In this version on mvfilter, expoenous variables in the state equation are
not allowed.

trend(newvar} saves the trend component in the new variable specified
by newvar.

cycle(newvar} saves the trend component in the new variable specified
by newvar.

ar(#) specifies the order 0<=p<=2 of the autoregressive process of the
cycle component. The default is AR(0). In this case, the output matches
the output of tsfilter hp.

smooth(#) sets the smoothing parameter for the filter. Unless specified,
the Ravn-Uhlig (2002) rule is used to set the smoothing parameter. The smoothing
parameter must be greater than 0.

Other

optimal forces the Kalman filter to estimate the smoothing parameter.
This works only for AR(0) (see technical remarks).

details display the oytput of the Kalman filter estimation

adjust With AR(p>=1), a small sample problem is introduced. adjusts
allows you to adjust the ratio of the sample variance of the cycle over the
sample variance of the change in the slope of the trend in the dynamic filter
to match the sample variance ratio in the static HP filter following
Borio et al. (2013 and 2014).

loop returns the adjustment factor, the SS and HP sample variance ratios
for each iteration when the option adjust is specified.

betacap is useful whan the cyclical compnent approaches a random walk and
would converge to its mean only after very olong time.

Tecnical Remarks

optimal works only with AR(0). This is due to the fact that sspace
does not allow for non linear constraints. Indeed, in the case of AR(1) (say),
the joint estimation of lambda and the AR parameter would require a linear
constraint in the observed equation such that the parameter (beta1) in front
of the lagged observed variable is equal to minus the parameter in front of the
lagged state variable and a non-linear constraint on variance ratio such that it is
equal to lambda*(1-beta1^2). Because sspace cannot handle this second
constraint, option is allowed only for the static filter with AR(0).

the autoregressive parameters cannot be estimated by the Kalman filter.
These are estimated before by regressing the cyclycal component of the static
filter with AR(0) on its lag(s) and then imposed as linear restriction(s) in the
sspace representation. This is due again to the fact that sspace does
not allow for non-linear constraints. In order to have the Kalman filter estimate
the autregressive parameters, you need to impose a non liner restriction on the
variance ratio of lambda*(1-beta1^2) in the case of AR(1) and
lambda*(1-beta1^2-beta2^2) in the case of AR(2).

loop adjusts the sample variance ratio of the dynamic filter with p>=1 to
match the sample varance ratio of the static filter with p=0. The code for
the loop implementation comes code accompanying Berger et al. (2015).

smooth(#) Unless specified, the smoothing parameter is set as a function of the
units of the time variable (daily, weekly, monthly, quarterly, half-yearly,
or yearly) following Ravn and Uhlig (2002). The Ravn-Uhlig rule sets # to
1600n^4, where n is the number of periods per quarter.

NB: if mvfilter fails to converge, there is no option to adjust the intial
conditions. This is for future implementation. At present the only suggestion to
help convergence is to change sample.

Example

Setup

. webuse gdp2

Use mvfilter to estimate the cyclical component of the log of
quarterly U.S. GDP

. mvfilter gdp_ln, cycle(cyc_ss)

Use mvfilter to estimate the cyclical component of the log of
quarterly U.S. GDP assuming an AR(1) in the cycle

. mvfilter gdp_ln, cycle(cyc_ss) ar(1)

Use mvfilter to estimate the cyclical component of the log of
quarterly U.S. GDP assuming an AR(1) in the cycle and adjust the sample
variance ratio

. mvfilter gdp_ln, cycle(cyc_ss) ar(1) adj

Stored results

mvfilter stores the following in r():

Scalars

r(ar_p) Order of the autoregressive process in the cyclycal component

r(var_ratio) Value of the variance ratio in the SS model

r(lambda) Value of lambda in the SS model

Macros

r(type) Filter type

r(unit) Time frequency unit

r(obs_var) Observed variable

r(exog_var) Exogenous variable(s)

r(cycle) Estimated cyclical component

r(trend) Estimated trend component

References

Borio, C., P. Disyatat and M. Juselius. 2013. Rethinking potential output: Embedding information about the financial cycle. BIS Working Papers, No 404.

Borio, C., P. Disyatat and M. Juselius. 2014. A parsimonious approach to incorporating economic information in measures of potential output. BIS Working Papers, No 442.

Berger H., T. Dowling, S. Lanau, M. Mrkaic, P. Rabanal and M. Taheri Sanjani. 2015.
Steady as She Goes — Estimating Potential Output During Financial Booms and Busts.
IMF Working Papers, No 2015/233.

Ravn, M.O and H Uhlig. 2002. On Adjusting the Hodrick-Prescott Filter for the Frequency of Observations. The Review of Economics and Statistics, 84(2): 371–376.

Author

Gregorio Impavido

International Monetary Fund

Email: gimpavido@imf.org

SSRN: https://papers.ssrn.com.