Search code examples
rregressioninstrumentspanel-datadiagnostics

Fixed effect instrumental variable (IV) regression with available diagnostic tests


May I please know an R package and code to run fixed effect instrumental variable (IV) regression with available diagnostic tests (e.g., weak instrument test, exogeneity test (using Wu-Hausman), Sargan test)?

I know plm code provides the fixed effect IV regressions but its diagnostic tests are not available unfortunately.

Even if I run the iv_robust code from estimatr package and specify as diagnostics = TRUE, it produces a warning message saying

"In iv_robust(.. : Will not return diagnostics if fixed_effects are used."

So no diagnostics can be run in fixed effect using iv_robust code either.

I also have both x and x^2 endogenous variables. I wonder what is the best way to run the fixed effect IV regression and how to do the diagnostic tests for these as well.


Solution

  • You could take a look at the very nice fixest package from L. Bergé: R Fixest Package: IV Estimation Without Further Exogenous Variables (For the syntax with IV's).

    The fitstat function can compute all of your required tests, e.g.

    fitstat(yourmodel, type = "ivf")
    

    or you can put them directly inside the table with etable, e.g.

    library(fixest)
    gravity = feols(log(Euros) ~ log(dist_km) | Destination + Origin, trade)
    
    
    etable(gravity, fitstat = ~  r2 + wald.p + wf)