Skip to content

Instantly share code, notes, and snippets.

@BioSciEconomist
Created January 29, 2019 20:35
Show Gist options
  • Save BioSciEconomist/74fa3af103a28a03581c441b86ea0b61 to your computer and use it in GitHub Desktop.
Save BioSciEconomist/74fa3af103a28a03581c441b86ea0b61 to your computer and use it in GitHub Desktop.
Instrumental Variables Demo Using ivreg
# *-----------------------------------------------------------------
# | PROGRAM NAME: ivreg demo.R
# | DATE: 1/29/19
# | CREATED BY: MATT BOGARD
# | PROJECT FILE:
# *----------------------------------------------------------------
# | PURPOSE: demo of ivreg
# *----------------------------------------------------------------
# make up data (this took some thought)
treat <- c(1,1,1,1,1,1,0,1,1,0,0,0,0,0)
lifestyle <-c('H','H','H','H','H','H','H','N','N','N','N','N','N','N')
wtchg <- c(-12,-10,-9,-11,-12,-10,-8,-8,-2,5,8,10,-5,-2)
calories <-c(2000,2000,3000,3000,2000,2000,2000,3000,3000,5000,5000,5000,3000,3000)
push <- c(1,0,0,1,1,0,0,1,1,0,0,1,0,0)
dat1 <- data.frame(treat,lifestyle,wtchg,calories,push)
library(AER)
# estimate local average treatment effecit or b_iv uisng 'push' as an instrumental variable
late <- ivreg(wtchg ~ treat | push,data =dat1)
summary(late)
summary(late, vcov = sandwich, df = Inf, diagnostics = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment