Search code examples
rfixest

Extract degrees of freedom from a fixest feols object


simple question: Can I extract the final degrees of freedom after a feols estimation using the fixest package?

res = feols(Sepal.Length ~ Sepal.Width + Petal.Length | Species, iris)
summary(res)

I know that there are many fancy ways to specify the df in fixest, but I'd just want the result (depending on which option I choose).

For example in the lfe package using felm, I can do so easily like this:

res = felm(Sepal.Length ~ Sepal.Width + Petal.Length | Species | 0 | 0, iris)
res$df

Thanks!


Solution

  • What you're looking for is: degrees_freedom(res, "resid", vcov = "iid")


    The VCOV has an influence on the values produced by degrees_freedom. Here's an explanation.

    By default:

    • the VCOV is clustered wrt the first fixed-effect (if FEs are present)
    • when the VCOV is clustered, FEs that are nested with the cluster are dropped in the DoF calculation (to avoid over-penalization)

    The number 3 obtained in degrees_freedom(res, "k") is not the number of fixed-effects. It's the number of regressors, excluding the nested FEs (and adding the intercept).

    By changing the way the VCOV is computed, you change the output of degrees_freedom. Here the nestedness is the problem, so you can remove it:

    degrees_freedom(res, "resid", vcov = cluster ~ ssc(fixef.K = "full"))
    #> [1] 145
    

    But the easiest way is to use an "iid" VCOV.


    Agreed the help page only implicitly refers to this by saying that the values depend on the type of VCOV. This could be clearer, I'll try to improve that!