从最固定的 feols 对象中提取自由度

Extract degrees of freedom from a fixest feols object

简单问题: 我可以使用 fixest 包在 feols 估计后提取最终的自由度吗?

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

我知道有很多奇特的方法可以在 fixst 中指定 df,但我只想要结果(取决于我选择的选项)。

例如在 lfe 包中使用 felm,我可以像这样轻松地做到这一点:

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

谢谢!

有个degrees_freedom

> degrees_freedom(res, type = "k")
[1] 3
> degrees_freedom(res, type = "resid")
[1] 147
> degrees_freedom(res, type = "t")
[1] 2

通过改变type,可以获得不同的自由度即?degrees_freedom显示

type - Character scalar, equal to "k", "resid", "t". If "k", then the number of regressors is returned. If "resid", then it is the "residuals degree of freedom", i.e. the number of observations minus the number of regressors. If "t", it is the degrees of freedom used in the t-test. Note that these values are affected by how the VCOV of x is computed, in particular when the VCOV is clustered.


或者可以使用

fitstat(res, "g", simplify = TRUE)

或者可能是

unname(res$fixef_sizes)

我们可能会在缩放协方差矩阵的attributes中summary之后找到它们,检查str(summary(res))

attr(summary(res)$cov.scaled, 'dof.K')
# [1] 3

您要找的是:degrees_freedom(res, "resid", vcov = "iid")


VCOV 对 degrees_freedom 产生的值有影响。这里有一个解释。

默认:

  • VCOV 与第一个固定效应聚类(如果存在 FE)
  • 当 VCOV 聚类时,与聚类嵌套的 FEs 在 DoF 计算中被丢弃(以避免过度惩罚)

degrees_freedom(res, "k")得到的数字3不是固定效应数。它是回归量的数量,不包括嵌套的 FE(并添加截距)。

通过更改 VCOV 的计算方式,您可以更改 degrees_freedom 的输出。这里的嵌套是问题,所以你可以删除它:

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

但最简单的方法是使用“iid”VCOV。


同意帮助页面只是通过说这些值取决于 VCOV 的类型来隐含地提到这一点。这可能会更清楚,我会努力改进!