hfilter
Syntax
Description
Separate one or more time series into trend and cyclical components by applying
the Hamilton filter
[2]. hfilter
optionally plots the series and trend component, with
cycles removed. The plot helps you select a smoothing parameter.
In addition to the Hamilton filter, Econometrics Toolbox™ supports the Baxter-King (bkfilter
),
Christiano-Fitzgerald (cffilter
), and
Hodrick-Prescott (hpfilter
) filters.
[
returns the additive trend Trend
,Cyclical
] = hfilter(Y
)Trend
and cyclical
Cycilcal
components from applying the Hamilton filter to each
variable (column) of the input matrix of time series data Y
.
[
returns the tables or timetables TTbl
,CTbl
] = hfilter(Tbl
)TTbl
and CTbl
containing variables for the trend and cyclical components, respectively, from applying
the Hamilton filter to each variable in the input table or timetable
Tbl
. To select different variables in Tbl
to
filter, use the DataVariables
name-value argument.
[___] = hfilter(___,
specifies options using one or more name-value arguments in
addition to any of the input argument combinations in previous syntaxes.
Name=Value
)hfilter
returns the output argument combination for the
corresponding input arguments. For example, hfilter(Tbl,LeadLength=4,DataVariables=1:5)
applies the Hamilton filter to the first five variables in the input table
Tbl
, and, for each selected variable, specifies the lead
yt + 4 as the response
variable in the filter weight regression.
hfilter(___)
plots time series variables in the input
data and their respective smoothed trend components (cycles removed), computed by the
Hamilton filter, on the same axes.
hfilter(
plots on the axes specified by ax
,___)ax
instead
of the current axes (gca
). ax
can precede any of the input
argument combinations in the previous syntaxes.
Examples
Input Arguments
Output Arguments
More About
Tips
Regarding a setting for the
LeadLength
name-value argument, Hamilton [2] states "If we are interested in business cycles, a 2-year horizon should be the standard benchmark." Regarding a setting for theLagLength
name-value argument, the article states "One might be tempted to use a richer model to forecast yt+h, such as using more than 4 lags, or even a nonlinear relation. However, such refinements are completely unnecessary for the goal of extracting a stationary (cyclical) component, and have the significant drawback that the more parameters we try to estimate by regression, the more the small-sample results are likely to differ from the asymptotic predictions."
References
Version History
Introduced in R2023a