hfilter
Syntax
Description
The hfilter function applies the Hamilton filter  to separate
      one or more time series into additive trend and cyclical components.
        hfilter optionally plots the series and trend component, with
      cycles removed.
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 and cyclical components from applying the Hamilton filter
          [2] to each variable (column) of an input matrix of
          time series data.Trend,Cyclical] = hfilter(Y)
[
          returns tables or timetables containing variables for the trend and cyclical components
          from applying the Hamilton filter to each variable in an input table or timetable. To
          select different variables to filter, use the TTbl,CTbl] = hfilter(Tbl)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
Name-Value Arguments
Output Arguments
More About
Tips
- Regarding a setting for the - LeadLengthname-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 the- LagLengthname-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





