require(ivreg)
require(AER)
require(estimatr)
require(fixest)
set.seed(12345)
n <- 4000
z1 <- rnorm(n)
z2 <- rnorm(n)
w1 <- rnorm(n)
w2 <- rnorm(n)
u <- rnorm(n)
x1 <- z1 + z2 + 0.2*u + 0.1*w1 + rnorm(n)
x2 <- z1 + 0.94*z2 - 0.3*u + 0.1*w2 + rnorm(n)
y <- x1 + x2 + w1 + w2 + u
dat <- data.frame(w1, w2, x1, x2, y, z1, z2)
mod1 <- ivreg::ivreg(y ~ x1 + x2 + w1 + w2 | z1 + z2 + w1 + w2, data = dat)
mod2 <- AER::ivreg(y ~ x1 + x2 + w1 + w2 | z1 + z2 + w1 + w2, data = dat)
mod3 <- estimatr::iv_robust(y ~ x1 + x2 + w1 + w2 | z1 + z2 + w1 + w2,
data = dat, se_type = "classical")
mod4 <- fixest::feols(y ~ w1 + w2 | x1 + x2 ~ z1 + z2, data = dat)
fsw(mod1)
fsw(mod2)
fsw(mod3)
fsw(mod4)
Run the code above in your browser using DataLab