2

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.

Eric
  • 528
  • 1
  • 8
  • 26

1 Answers1

5

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)
Julian
  • 6,586
  • 2
  • 9
  • 33
  • Thanks. I am still not sure whether this works as I see my run time is extremely long only for the feols code itself. The code is still not completing its running. I never experienced this problem when running all other types of IV regressions in R. I also carefully followed the formula syntax as suggested in your link as well. Is there a way to expediate the runtime to see whether I can get desired results? – Eric Apr 23 '22 at 12:41
  • Maybe have a look here: https://github.com/lrberge/fixest#benchmarking Usually `fixest` is very fast, but it might be that it does not perform so well for IVs. – Julian Apr 23 '22 at 12:46
  • I’m sorry to hear that. – Eric Apr 24 '22 at 02:45