R - 面板数据分析和稳健标准误差的固定效应

R - fixed effect of panel data analysis and robust standard errors

我正在通过R中的plm包处理面板数据。现在我正在考虑组(城市)、时间以及组和时间两种方式的固定效应模型。因为我通过 Breusch-Pagan 检验检测到异方差性,所以我计算了稳健的标准误差。

我阅读了帮助 ?vcovHC,但我无法完全理解如何使用 coeftest

我当前的代码是:

library(plm)
library(lmtest)
library(sandwich)

fem_city <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "individual")
fem_year <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "time")
fem_both <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "twoways")

coeftest(fem_city, vcovHC(fem_city, type = 'HC3', cluster = 'group')
coeftest(fem_year, vcovHC(fem_city, type = 'HC3', cluster = 'time')

为了计算稳健的标准误,coeftest的代码是否合适?我想知道如何分别为 effect = 'individualeffect = 'time' 设置 cluster 选项。 比如我设置coeftest codes:

cluster = 'group' in plm of fem_city for effect = 'individual' in coeftest

cluster = 'time' in plm of fem_year for effect = 'time' in coeftest

这种方式合适吗?

以及,如何计算 cityyear 两者的稳健标准误差?

如果要在用作单个索引的变量上进行聚类(在您的示例中为 city),请设置 cluster='group'

如果要在用作时间索引的变量上进行聚类(在您的示例中为year),请设置cluster='time'

即使对于固定效应单向个体模型,您也可以在时间索引上进行聚类。

要对两个索引变量进行聚类,您不能使用 plm::vcovHC。从提供双聚类(DC = 双聚类)的相同包中查看 vcovDC,例如,

coeftest(fem_city, vcovDC(fem_city)