0

I want to test a constrained vs an unconstrained model.

Estimates are obtained with fixest (I cannot use the build-in function "wald" in my case).

Here is an example:

library("fixest")

data(airquality)

est_nc <- feols(Ozone ~ Solar.R + Wind + poly(Temp, 3), airquality)
est_c <- feols(Ozone ~ Solar.R + Wind, airquality)

To test the difference, I would usually use anova() :

anova(est_c, est_nc)

But anova() doesn't work with fixest objects. Do you know any other function that could replace it for fixest objects please ?

yacx
  • 167
  • 2
  • 13

1 Answers1

0

I've just computed it manually. By changing the fixest specific function to lm equivalents, I was able to reproduce the results of anova() so the baseline should be ok.

The function degrees_freedom() should use the number of degrees of freedom that account for SE clustering. But I'm still not 100% sure that is the correct way to compute the F-stat with clustered SE, so use this with caution.

library("fixest")

# modc: a fixest object for the constrained model
# mocnc: a fixest object for the unconstrained model

my_ftest <- function(modc, modnc)
{
  df_dif <- (degrees_freedom(modc, type="resid") - degrees_freedom(modnc, type="resid"))
  df_nc <- degrees_freedom(modnc, type="resid")
  fstat <- ((modc$ssr - modnc$ssr) / df_dif) / (modnc$ssr / df_nc)
  pvf <- pf(fstat, df_dif, df_nc, lower.tail = FALSE)
  print(paste(paste("The F-statistic is", fstat, sep=" "), paste("and the p-value is", pvf, sep=" "), sep=" "))
}

my_ftest(est_c, est_nc)
yacx
  • 167
  • 2
  • 13