Consider the following autoregressive distributed lag model (ADL): $$ \Delta c_{t}=\alpha+\beta\Delta c_{t-1}+\gamma_{0}y_{t}+\gamma_{1}y_{t-1}+u_{t}, $$ where $c_{t}$
The purpose of this exercise is to test the null hypothesis $H_{0}:\gamma_{0}+\gamma_{1}=0$.
Download US monthly data for Personal Income [http://research.stlouisfed.org/fred2/data/PI.csv] and for Personal Consumption Expenditures [http://research.stlouisfed.org/fred2/data/PCE.csv]. Resample the data into quarterly frequency. Plot the data in levels, in logs, and in differences of logs.
In [1]:
import Quandl
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
import seaborn as sns
import statsmodels.api as sm
%matplotlib inline
In [2]:
token = open('quandl.token').read()
data = Quandl.get(["FRED/PI", "FRED/PCE"], authtoken=token)
cols = {'FRED.PI - VALUE': 'Income', 'FRED.PCE - VALUE': 'Expenditures'}
data.rename(columns=cols, inplace=True)
print(data.tail())
data.plot()
plt.show()
In [3]:
data_logs = data.apply(np.log).rename(columns={'Income': 'log(I)', 'Expenditures': 'log(C)'})
print(data_logs.tail())
data_logs.plot()
plt.show()
In [4]:
data_dlogs = data_logs.diff().dropna().rename(columns={'log(I)': 'Dlog(I)', 'log(C)': 'Dlog(C)'})
print(data_dlogs.tail())
print(data_dlogs.head())
data_dlogs.plot()
plt.show()
In [5]:
df3 = pd.merge(data_logs, data_dlogs, left_index=True, right_index=True)
df3 = pd.merge(df3, data_logs.shift(1),
left_index=True, right_index=True, suffixes=('', '_lag'))
df3 = pd.merge(df3, data_dlogs.shift(1),
left_index=True, right_index=True, suffixes=('', '_lag')).dropna()
print(df3.tail())
In [6]:
exog = sm.add_constant(df3[['Dlog(C)_lag', 'Dlog(I)', 'log(I)_lag']])
model = sm.OLS(df3['Dlog(C)'], exog).fit()
print(model.summary())