library(foreign)
library(AER)
library(npcausal)
library(stargazer)

Instrumental Variables: Setting

library(dagitty)
library(ggdag)
ivgraph<-dagitty("dag{Y<-X; X<-W; X<->Y}") #create graph
#Set position of nodes 
  coords<-list(x=c(X = 0, Y = 2, W=-1),y=c(X = 0, Y = 0, W=0)) 
  coords_df<-coords2df(coords)
  coordinates(ivgraph)<-coords2list(coords_df)
ggdag(ivgraph)+theme_dag_blank()+labs(title="Instrumental Variables",subtitle="Causal IV") #Plot causal graph

“Classical IV” (Wright (1928))

Binary Instrument, Binary Treatment

LATE Theorem

Interpretation of Conditions

Proof

Extension: Adding covariates

ivzgraph<-dagitty("dag{Y<-X; X<-W; X<->Y; Y<-Z; X<-Z; W<-Z}") #create graph
#Set position of nodes 
  coords<-list(x=c(X = 0, Z = -1, Y = 2, W=-1),y=c(X = 0, Z = 0.5, Y = 0, W=0)) 
  coords_df<-coords2df(coords)
  coordinates(ivzgraph)<-coords2list(coords_df)
ggdag(ivzgraph)+theme_dag_blank()+labs(title="Instrumental Variables",subtitle="Causal IV with Covariates") #Plot causal graph

Estimating (Conditional) LATE

Abadie’s kappa

Semiparametric Estimate

Evaluating and Testing Model Conditions

Relevance and Handling Weak IVs

Tests in LATE setting

Interpretation: What is a LATE and why should we care?

What to do about implausible or invalid IV

Extensions: Multi-valued Instrument

Extensions: Continuous Treatment

Software

Example: Survey Experiment

#Load the data set from your directory
#In my case this is saved at
debate<-read.dta("Data/M_Washington_A_Chapter_2010_Dataset.dta")

#Assemble indicator for watched or didn't
debate$actwatch<-(debate$watchdps1=="yes"|debate$watchdps2=="yes")
debate$actwatch[is.na(debate$actwatch)]<-FALSE
debate$actwatch<-as.numeric(debate$actwatch)

#Alternately, use
debate$actwatch<-as.numeric(debate$watchdps)-1 

ols<-lm(formula=bloomsc~actwatch,data=debate)
ols.results<-coeftest(ols,vcov=vcovHC(ols,type="HC3"))

reducedform<-lm(bloomsc~watch,data=debate)
reducedform.results<-coeftest(reducedform,vcov=vcovHC(reducedform,type="HC3"))

firststage<-lm(actwatch~watch,data=debate)
firststage.results<-coeftest(firststage,vcov=vcovHC(firststage,type="HC3"))

ivwatch<-ivreg(formula=bloomsc~actwatch|watch,data=debate)
ivwatch.results<-coeftest(ivwatch,vcov=vcovHC(ivwatch,type="HC3"))
stargazer(ivwatch.results,ols.results,firststage.results,reducedform.results,header=FALSE,
    type="html",
    omit.stat=c("adj.rsq"),
    font.size="tiny", 
    title="Wald Estimate of Debate Watching on Candidate Score")
Wald Estimate of Debate Watching on Candidate Score
Dependent variable:
(1) (2) (3) (4)
actwatch 5.775 -3.134
(8.192) (2.035)
watch 0.205*** 1.234
(0.027) (1.733)
Constant 67.665*** 70.111*** 0.162*** 68.631***
(2.409) (0.985) (0.017) (1.229)
Note: p<0.1; p<0.05; p<0.01

Conditional IV

mydata<-data.frame(y=debate$bloomsc,a=debate$actwatch,z=debate$watch,x1=debate$female,x2=debate$black,x3=debate$white,x4=debate$age)
mydata<-na.omit(mydata)
x=as.matrix(mydata[,4:7])
set.seed(101)
boundsresults<-ivbds(y=mydata$y/100,a=mydata$a,z=mydata$z,x=x,nsplits=5,sl.lib=c("SL.glm","SL.ranger"))
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |======================================================================| 100%
##   parameter          lb         ub      ci.ll     ci.ul
## 1       ATE -0.48626192 0.29688835 -0.5230338 0.3310284
## 2 beta(h_q) -0.52000608 0.27717903 -0.6920250 0.3925359
## 3      LATE  0.02781938 0.02781938 -0.1394741 0.1951129
lateresults<-ivlate(y=mydata$y,a=mydata$a,z=mydata$z,x=x,nsplits=5,sl.lib=c("SL.glm","SL.ranger"))
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |======================================================================| 100%
##   parameter       est         se         ci.ll      ci.ul  pval
## 1      LATE 2.9067270 8.60270865 -1.395458e+01 19.7680359 0.735
## 2  Strength 0.2132277 0.03017744  1.540799e-01  0.2723755    NA
## 3 Sharpness 0.0010000 0.07662264  5.159907e-69  1.0000000    NA
tslswatch<-ivreg(formula=bloomsc~actwatch+female+black+white+age|watch+female+black+white+age,data=debate)
(tslswatch.results<-coeftest(tslswatch,vcov=vcovHC(tslswatch,type="HC3")))
## 
## t test of coefficients:
## 
##              Estimate Std. Error t value  Pr(>|t|)    
## (Intercept) 59.013126   5.025551 11.7426 < 2.2e-16 ***
## actwatch     3.534963   8.631364  0.4095  0.682240    
## female      -0.910754   1.841352 -0.4946  0.621002    
## black       -6.408480   4.122680 -1.5544  0.120450    
## white        1.990523   3.679699  0.5409  0.588686    
## age          0.153922   0.055601  2.7684  0.005756 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Summary

References

Abadie, Alberto. 2003. “Semiparametric Instrumental Variable Estimation of Treatment Response Models.” Journal of Econometrics 113 (2): 231–63.
Ai, Chunrong, and Xiaohong Chen. 2003. “Efficient Estimation of Models with Conditional Moment Restrictions Containing Unknown Functions.” Econometrica 71 (6): 1795–1843.
Andrews, Isaiah, James H Stock, and Liyang Sun. 2019. “Weak Instruments in Instrumental Variables Regression: Theory and Practice.” Annual Review of Economics 11: 727–53.
Balke, Alexander, and Judea Pearl. 1997. “Bounds on Treatment Effects from Studies with Imperfect Compliance.” Journal of the American Statistical Association 92 (439): 1171–76.
Chernozhukov, Victor, and Christian Hansen. 2008. “The Reduced Form: A Simple Approach to Inference with Weak Instruments.” Economics Letters 100 (1): 68–71.
Conley, Timothy G, Christian B Hansen, and Peter E Rossi. 2012. “Plausibly Exogenous.” Review of Economics and Statistics 94 (1): 260–72.
Cornelissen, Thomas, Christian Dustmann, Anna Raute, and Uta Schönberg. 2016. “From LATE to MTE: Alternative Methods for the Evaluation of Policy Interventions.” Labour Economics 41: 47–60. https://doi.org/https://doi.org/10.1016/j.labeco.2016.06.004.
Frölich, Markus. 2007. “Nonparametric IV Estimation of Local Average Treatment Effects with Covariates.” Journal of Econometrics 139 (1): 35–75.
Imbens, Guido W, and Joshua D Angrist. 1994. “Identification and Estimation of Local Average Treatment Effects.” Econometrica 62 (2): 467–75.
Kennedy, Edward H, Sivaraman Balakrishnan, and Max G’Sell. 2020. “Sharp Instruments for Classifying Compliers and Generalizing Causal Effects.” The Annals of Statistics 48 (4): 2008–30.
Kitagawa, Toru. 2015. “A Test for Instrument Validity.” Econometrica 83 (5): 2043–63.
Lal, Apoorva, Mackenzie William Lockhart, Yiqing Xu, and Ziwen Zu. 2021. “How Much Should We Trust Instrumental Variable Estimates in Political Science? Practical Advice Based on over 60 Replicated Studies.” https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3905329.
Mourifié, Ismael, and Yuanyuan Wan. 2017. “Testing Local Average Treatment Effect Assumptions.” Review of Economics and Statistics 99 (2): 305–13.
Mullainathan, Sendhil, Ebonya Washington, and Julia R Azari. 2009. “The Impact of Electoral Debate on Public Opinions: An Experimental Investigation of the 2005 New York City Mayoral Election.” Political Representation, 324–41.
Newey, Whitney K, and James L Powell. 2003. “Instrumental Variable Estimation of Nonparametric Models.” Econometrica 71 (5): 1565–78.
Ogburn, Elizabeth L, Andrea Rotnitzky, and James M Robins. 2015. “Doubly Robust Estimation of the Local Average Treatment Effect Curve.” Journal of the Royal Statistical Society: Series B (Statistical Methodology) 77 (2): 373–96.
Singh, Rahul, and Liyang Sun. 2021. “Automatic Kappa Weighting for Instrumental Variable Models of Complier Treatment Effects.” http://arxiv.org/abs/1909.05244.
Stock, James H, and Motohiro Yogo. 2005. “Testing for Weak Instruments in Linear Iv Regression.” In Identification and Inference for Econometric Models: Essays in Honor of Thomas Rothenberg, 80–108. Cambridge University Press.
Sun, Zhenting. 2021. “Instrument Validity for Heterogeneous Causal Effects.” http://arxiv.org/abs/2009.01995.
Wright, Philip G. 1928. Tariff on Animal and Vegetable Oils. Macmillan Company, New York.
Young, Alwyn. 2021. “Leverage, Heteroskedasticity and Instrumental Variables in Practical Application.” https://personal.lse.ac.uk/YoungA/LeverageandIV.pdf.