Today

Some Important Data Relationships (1)

Marriage vs. Margarine

Some Important Data Relationships (2)

Marriage vs. Drowning

Some Important Data Relationships (3)

Space vs. Sociology

What’s going on here?

Simulation (Code 1)

tl<-100 #Length of simulated series
set.seed(74) #Initialize random number generator
e1<-ts(rnorm(tl)) #standard normal shocks
e2<-ts(rnorm(tl)) #additional independent standard normal
rho<-1 #AR parameter
yUR1<-numeric(tl-1)
yUR2<-numeric(tl-1)
for(s in 1:(tl-1)){
  #Random Walk initialized at 0
  yUR1[s+1]<-rho*yUR1[s]+e1[s]
  #Independently generated separate random walk
    yUR2[s+1]<-rho*yUR2[s]+e2[s]
}

Simulation (Code 2)

#Represent as same length time series
UR1<-ts(yUR1[1:tl-1])
UR2<-ts(yUR2[1:tl-1])
simulatedseries<-cbind(UR1,UR2)#Collect as Matrix
#Library for time series regression
library(dynlm)
#Regress indepent series
spuriousreg<-dynlm(formula=yUR1~yUR2,data=simulatedseries)
spursum<-summary(spuriousreg)

Simulation (Code 3)

#Plot
ts.plot(simulatedseries, gpars=
  list(main="Two Independent Simulated Random Walks", 
  ylab="Series value",lty=c(1,2),col=c("red","blue")))
  legend("bottomleft",bty="n",
  expression("Random Walk 1", "Random Walk 2"),
  lty=1:2,col=c("red","blue"))
text(60,2,"Coef= ") 
text(78,2,spursum$coef[2])
text(60,1,"t-value= ") 
text(78,1,spursum$coef[6])
text(60,0,"p-value= ") 
text(81,0,spursum$coef[8])

Simulation: 2 independent random walks

Explanation: Spurious Regression

Multiple integrated series

Non-spurious relationships

Cointegration

Testing for cointegration

Lettau and Ludvigson: Code 1

#Load data on c, a, y from Lettau's website
library(readr) #Library to read .csv files
#download data from Lettau's website
cay_current<-read_csv(
  "http://faculty.haas.berkeley.edu/
  lettau/data/cay_current.csv",
  skip=1)
#Rename c to remove space
cay_current$c<-cay_current$`c (pce)`

Lettau and Ludvigson: Code 2

#Test for unit roots in each series, 
# under null with possible drift and trend
library(tseries)
#Run Phillips-Perron tests for each series
c.pp<-pp.test(cay_current$c)
a.pp<-pp.test(cay_current$a)
y.pp<-pp.test(cay_current$y)
#Set as time series for use in commands
cc<-as.ts(cay_current$c)
aa<-as.ts(cay_current$a)
yy<-as.ts(cay_current$y)

Macroeconomic Example: Lettau & Ludvigson (2004)

## Warning: package 'readr' was built under R version 4.1.2

Cointegration tests

Application: L&L data (Code)

#Run OLS
caylm<-lm(cc~aa+yy)
library(stargazer)
stargazer(caylm,header=FALSE,type="html",
  no.space=TRUE,report="vc",omit.table.layout = "ns-=a")
#Show whether residual appears to have unit root
cayresid<-as.ts(caylm$residuals)
autoregression<-dynlm(cayresid~L(cayresid))
stargazer(autoregression,header=FALSE,type="html",
    no.space=TRUE,report="vc",
    omit.table.layout = "ns-=a")

Application: L&L data

Dependent variable:
cc
aa 0.249
yy 0.782
Constant -0.616
Dependent variable:
cayresid
L(cayresid) 0.922
Constant -0.0002

Formal test of cointegration (Code)

#Run Phillips-Ouliaris test on c,a,y
caytest<-po.test(data.frame(cc,aa,yy))
caytest

Formal test of cointegration

## 
##  Phillips-Ouliaris Cointegration Test
## 
## data:  data.frame(cc, aa, yy)
## Phillips-Ouliaris demeaned = -14.98, Truncation lag parameter = 2,
## p-value = 0.15

Estimation under cointegration

Dynamic OLS estimates (Code)

#Dynamic OLS with 4 leads and lags
dynOLS<-dynlm(cc~aa+yy+L(diff(aa),-4:4)+L(diff(yy),-4:4))
library(lmtest)
library(sandwich)
dynresults<-coeftest(dynOLS,vcovHAC) #HAC errors
stargazer(dynresults,header=FALSE,type="html",
    keep=c(1,2,21), no.space=TRUE,
    omit.table.layout = "ns-=a")

Dynamic OLS estimates of cointegrating coefficients

Dependent variable:
aa 0.273***
(0.052)
yy 0.759***
(0.057)
Constant -0.671***
(0.115)

Combining long run and short run relationships

Error correction model using L&L residuals (Code)

#Calculate cointegrating residual from 
#   dynamic OLS estimated coefficients
cay<-cc-dynOLS$coefficients[2]*aa
      -dynOLS$coefficients[3]*yy
      -dynOLS$coefficients[1]
#Run error correction regression
ecm<-dynlm(d(aa)~L(cay)+L(d(aa))+L(d(cc))+L(d(yy)))
#Calculate HAC standard errors
ecmresults<-coeftest(ecm,vcovHAC)
#Display Results
stargazer(ecmresults,header=FALSE,type="html", 
    no.space=TRUE,omit.table.layout = "ns-=a")

Error correction model using L&L residuals

Dependent variable:
L(cay) 0.111*
(0.059)
L(d(aa)) 0.226**
(0.110)
L(d(cc)) 0.265
(0.161)
L(d(yy)) -0.153
(0.152)
Constant 0.004**
(0.002)

Conclusions