Trends and cycles in unemployment¶
Here we consider three methods for separating a trend and cycle in economic data. Supposing we have a time series \(y_t\), the basic idea is to decompose it into these two components:
where \(\mu_t\) represents the trend or level and \(\eta_t\) represents the cyclical component. In this case, we consider a stochastic trend, so that \(\mu_t\) is a random variable and not a deterministic function of time. Two of methods fall under the heading of “unobserved components” models, and the third is the popular Hodrick-Prescott (HP) filter. Consistent with e.g. Harvey and Jaeger (1993), we find that these models all produce similar decompositions.
This notebook demonstrates applying these models to separate trend from cycle in the U.S. unemployment rate.
[1]:
%matplotlib inline
[2]:
import numpy as np
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt
[3]:
from pandas_datareader.data import DataReader
endog = DataReader('UNRATE', 'fred', start='1954-01-01')
/home/travis/miniconda/envs/statsmodels-test/lib/python3.7/site-packages/pandas_datareader/compat/__init__.py:7: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
from pandas.util.testing import assert_frame_equal
Hodrick-Prescott (HP) filter¶
The first method is the Hodrick-Prescott filter, which can be applied to a data series in a very straightforward method. Here we specify the parameter \(\lambda=129600\) because the unemployment rate is observed monthly.
[4]:
hp_cycle, hp_trend = sm.tsa.filters.hpfilter(endog, lamb=129600)
Unobserved components and ARIMA model (UC-ARIMA)¶
The next method is an unobserved components model, where the trend is modeled as a random walk and the cycle is modeled with an ARIMA model - in particular, here we use an AR(4) model. The process for the time series can be written as:
where \(\phi(L)\) is the AR(4) lag polynomial and \(\epsilon_t\) and \(\nu_t\) are white noise.
[5]:
mod_ucarima = sm.tsa.UnobservedComponents(endog, 'rwalk', autoregressive=4)
# Here the powell method is used, since it achieves a
# higher loglikelihood than the default L-BFGS method
res_ucarima = mod_ucarima.fit(method='powell', disp=False)
print(res_ucarima.summary())
/home/travis/build/statsmodels/statsmodels/statsmodels/tsa/base/tsa_model.py:162: ValueWarning: No frequency information was provided, so inferred frequency MS will be used.
% freq, ValueWarning)
Unobserved Components Results
==============================================================================
Dep. Variable: UNRATE No. Observations: 793
Model: random walk Log Likelihood 257.082
+ AR(4) AIC -502.164
Date: Fri, 21 Feb 2020 BIC -474.117
Time: 13:54:37 HQIC -491.384
Sample: 01-01-1954
- 01-01-2020
Covariance Type: opg
================================================================================
coef std err z P>|z| [0.025 0.975]
--------------------------------------------------------------------------------
sigma2.level 0.0172 0.003 6.291 0.000 0.012 0.023
sigma2.ar 0.0108 0.003 3.565 0.000 0.005 0.017
ar.L1 1.0380 0.065 16.069 0.000 0.911 1.165
ar.L2 0.4736 0.103 4.580 0.000 0.271 0.676
ar.L3 -0.3377 0.123 -2.737 0.006 -0.580 -0.096
ar.L4 -0.1845 0.075 -2.446 0.014 -0.332 -0.037
===================================================================================
Ljung-Box (Q): 75.64 Jarque-Bera (JB): 44.56
Prob(Q): 0.00 Prob(JB): 0.00
Heteroskedasticity (H): 0.49 Skew: 0.25
Prob(H) (two-sided): 0.00 Kurtosis: 4.05
===================================================================================
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).
Unobserved components with stochastic cycle (UC)¶
The final method is also an unobserved components model, but where the cycle is modeled explicitly.
[6]:
mod_uc = sm.tsa.UnobservedComponents(
endog, 'rwalk',
cycle=True, stochastic_cycle=True, damped_cycle=True,
)
# Here the powell method gets close to the optimum
res_uc = mod_uc.fit(method='powell', disp=False)
# but to get to the highest loglikelihood we do a
# second round using the L-BFGS method.
res_uc = mod_uc.fit(res_uc.params, disp=False)
print(res_uc.summary())
/home/travis/build/statsmodels/statsmodels/statsmodels/tsa/base/tsa_model.py:162: ValueWarning: No frequency information was provided, so inferred frequency MS will be used.
% freq, ValueWarning)
Unobserved Components Results
=====================================================================================
Dep. Variable: UNRATE No. Observations: 793
Model: random walk Log Likelihood 220.614
+ damped stochastic cycle AIC -433.229
Date: Fri, 21 Feb 2020 BIC -414.541
Time: 13:54:39 HQIC -426.045
Sample: 01-01-1954
- 01-01-2020
Covariance Type: opg
===================================================================================
coef std err z P>|z| [0.025 0.975]
-----------------------------------------------------------------------------------
sigma2.level 0.0140 0.005 2.793 0.005 0.004 0.024
sigma2.cycle 0.0173 0.005 3.569 0.000 0.008 0.027
frequency.cycle 0.0691 0.005 13.501 0.000 0.059 0.079
damping.cycle 0.9897 0.004 243.366 0.000 0.982 0.998
===================================================================================
Ljung-Box (Q): 170.28 Jarque-Bera (JB): 87.10
Prob(Q): 0.00 Prob(JB): 0.00
Heteroskedasticity (H): 0.48 Skew: 0.48
Prob(H) (two-sided): 0.00 Kurtosis: 4.32
===================================================================================
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).
Graphical comparison¶
The output of each of these models is an estimate of the trend component \(\mu_t\) and an estimate of the cyclical component \(\eta_t\). Qualitatively the estimates of trend and cycle are very similar, although the trend component from the HP filter is somewhat more variable than those from the unobserved components models. This means that relatively mode of the movement in the unemployment rate is attributed to changes in the underlying trend rather than to temporary cyclical movements.
[7]:
fig, axes = plt.subplots(2, figsize=(13,5));
axes[0].set(title='Level/trend component')
axes[0].plot(endog.index, res_uc.level.smoothed, label='UC')
axes[0].plot(endog.index, res_ucarima.level.smoothed, label='UC-ARIMA(2,0)')
axes[0].plot(hp_trend, label='HP Filter')
axes[0].legend(loc='upper left')
axes[0].grid()
axes[1].set(title='Cycle component')
axes[1].plot(endog.index, res_uc.cycle.smoothed, label='UC')
axes[1].plot(endog.index, res_ucarima.autoregressive.smoothed, label='UC-ARIMA(2,0)')
axes[1].plot(hp_cycle, label='HP Filter')
axes[1].legend(loc='upper left')
axes[1].grid()
fig.tight_layout();