I want to do an IV regression in Fixed-Effect Models with diagnostics (Wu-Hausman, weak instrument, etc.). I tried three options, each with its problem--
y is dependent variable
x1 is the endogenous independent variable
c1, c2, c3 are control variables
inst is the instrument variable
City and Year are two factors for fixed effects
fit_ivreg = ivreg(data, y ~ x1 + c1 + c2 + c3 + City + Year | inst + c1 + c2 + c3 + City + Year)
summary(fit_ivreg, diagnostics = T)
The problem of this model is that I am not sure if this is fixed-effect model at all.
fit_plm = plm(data, y ~ x1 + c1 + c2 + c3 | inst + c1 + c2 + c3, effect = "twoways", model = "within", index = c("City", "Year"), inst.method = 'baltagi')
summary(fit_plm)
This works, but there is no statistical diagnostics at all.
fit_fixest = feols(data, y ~ c1 + c2 + c3 | City + Year | x1 ~ inst)
summary(fit_fixest)
There is diagnostics. But the output result of this model is COMPLETELY different from that of my plm model above. I am really confused.
I would go for plm
or fixest
. Those packages are made for panel model, e.g. fixed effects and instrumental variables. I think you should set effect=individual
, twoway is different. See how to define panel IDs and then select the fe, default is individual oneway effects. It can also be time oneway effect or both, twoway effects.
# Fixed Effects Instrument Variables
# Data
data("Produc", package = "plm")
# PLM
library(plm)
model_plm <- plm(pcap ~ unemp + water + util | water + util + pc + gsp,
data=Produc, effect = "individual", model = "within", index=c("state", "year"))
model_plm$coefficients
unemp water util
80.0067927 0.8989423 1.3288631
# FIXEST
library(fixest)
model_iv_fe <- feols(pcap ~ water + util | state | unemp ~ pc + gsp,
Produc, panel.id = ~ state + year)
model_iv_fe$coefficients
fit_unemp water util
80.0067927 0.8989423 1.3288631
See, the estimates are identical.
So, you already gave the answer to your question. fixest
does panel estimation with instruments and reports nice diagnostics.
You can read more about package differences in SE: R plm vs fixest package - different results?