3

我在 1990 年至 2010 年间在美国运行人口普查区的空间面板模型(使用 splm),并使用基于距离或连续性的相邻矩阵。但我也想对人口普查区所在城市的标准误差进行聚类。

在面板模型(plm)中有一种方法可以做到这一点(使用后估计函数“vcovHC”,然后是“coeftest”(见这里))但我没有看到也无法找到一种方法来做到这一点splm 对象。当我运行相同的代码时,我收到错误"Error in terms.default(object) : no terms component nor attribute."There are a lot of questions about clustering with other models,但没有关于 splm 包的问题,​​因此非常感谢任何帮助。

这可以在 Stata 中使用 XSLME 包完成,包括:调用结束时的 vce(cluster "group_var"),但是在 3 个面板上超过 37k+ 个案例时,Stata 崩溃。

具有相同问题的假设示例如下:

library(splm)
library(spdep)    
data("Insurance")
    data(itaww)
    sw <- mat2listw(itaww)

    myformula <- rgdp ~ agen + school + fam 
    myresults <- spml(myformula,
                      data = Insurance,
                      listw = sw,
                      model = "within",
                      lag = FALSE,
                      effect = "individual",
                      spatial.error = "b")
    summary(myresults)

    results_vcov <- vcovHC(myresults, type = "HC0", cluster = "group")

## same thing but with plm
library(plm)
    myplmresults <- plm(myformula,
                        data = Insurance,
                        model = "within")
    summary(myplmresults)

    results_vcov <- vcovHC(myplmresults, type = "HC0", cluster = "group")
    library(lmtest)
    coeftest(myplmresults, vcov = results_vcov)
4

0 回答 0