# *******************************
# Instrumental variables exercise
# *******************************
# Set the seed so our work is replicable
set.seed(1234)
# Draw some random variables
x1 <- rnorm(n=100, mean=3, sd=0.5)
x2 <- rnorm(n=100, mean=2, sd=2)
x3 <- rnorm(n=100, mean=2, sd=1)
# Draw one more random variable from a normal distribution
x4 <- rnorm(n=100, mean=0, sd=3)
# The x1 that we observe actually has some funny ingredients
# x1 is equal to the random data we drew above, plus some x3
# and some x4. What you see below is the final data generating
# process for the x1 that we observe (the x1 in our dset). */
x1 <- x1 + x3 + x4
# Draw some "unobservable" stuff for the DGP of y
u <- rnorm(n=100, mean=0, sd=1)
# Create the dependent variable y
y <- 5 + 2*x1 - 4*x2 + u
# Can we recover the true effect of x1 on y? (=2)