*! version 1.0.0 27sep2019

[TS] hpfilter -- Hodrick-Prescott time-series filter

Syntax

Filter one variable

hpfilter
varname
[if] [in] [, options]

options

New variables
trend(newvar) save the trend component in new variable

cycle(newvar) save the cyclical component in new variable

Parameters
smooth(#) smoothing parameter for the Hodrick-Prescott filter

optimal use optimal smoothing parameter for the Hodrick-Prescott filter

twosided option for twosided filter (default)

onesided option for onesided filter

forcast(#) number of periods for trend forcast

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

varname may contain time-series operators; see
tsvarlist.

Description

hpfilter uses the Hodrick-Prescott 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.

Options

New variables

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

cycle(newvar) saves the cyclical component in the new variable specified by newvar.

Options

smooth(#) sets the smoothing parameter for the Hodrick-Prescott filter.
By default, if the units of the time variable are set to daily, weekly, monthly,
quarterly, half-yearly, or yearly, then the Ravn-Uhlig rule is used to set the
smoothing parameter; otherwise, the default value is smooth(1600). The
Ravn-Uhlig rule sets # to 1600p^4, where p is the number of periods per
quarter. The smoothing parameter must be greater than 0.

optimal finds the optimal smoothing paramter as the ratio of variances of innovations to the series and innovations to the trend.

twosided uses the full sample to get estimates of the trend. This is the default option if none of twosided and onesided options are specified.

onesided uses the only the current and past values of the series to get estimates of the trend.

forecast(#) number of periods to forcast the trend. The forecast option must be greater than 0.

Example

Setup

. webuse gdp2

Use the Hodrick-Prescott high-pass filter to estimate the trend and cyclical components of the log of quarterly U.S. GDP

. hpfilter gdp_ln, trend(gdp_trend) cycle(gdp_cycle)

Plot the cyclical component

. tsline gdp_hp

Stored results

hpfilter stores the following in r():

Scalars

r(smooth) smoothing parameter lambda

Macros

r(varname) original time-series variables

r(trendname) variables containing estimates of the trend components, if trend() was specified

r(cyclename) variables containing estimates of the cyclical components, if cycle() was specified

r(method) Hodrick-Prescott (onesided or twosided)

r(unit) units of time variable set using tsset or xtset

Author

Narek Ohanyan

Universitat Pompeu Fabra

Email: narek.ohanyan@upf.edu