我使用 Arai 的 (2015) 方法(特别是第 4 页的 mclx 函数)为我在 R 中的 lm 生成集群稳健的标准错误(http://www.ne.su.se/polopoly_fs/1.216115.1426234213!/menu /标准/文件/clustering1.pdf)。
我使用面板数据并尝试生成双向集群稳健标准错误(按年份和按国家/地区)。
我的问题是,虽然我得到了每个自变量的系数估计值,但我得到了一些(不是所有)变量的标准误差、t 统计数据和 p 值的 NA。
我检查了相关主题,但找不到此问题的答案。特别是,它与数据结构无关,因为所有数据都是“数字”的,没有多重共线性问题,每个集群维度(即年份和国家)都有足够的观察值......
mclx() 函数如下所示:
### Write function for Multiple dimension SE clustering
mclx <-
function(fm, dfcw, cluster1, cluster2){
library(sandwich)
library(lmtest)
cluster12 = paste(cluster1, cluster2, sep="")
M1 <- length(unique(cluster1))
M2 <- length(unique(cluster2))
M12 <- length(unique(cluster12))
N <- length(cluster1)
K <- fm$rank
dfc1 <- (M1/(M1-1))*((N-1)/(N-K))
dfc2 <- (M2/(M2-1))*((N-1)/(N-K))
dfc12 <- (M12/(M12-1))*((N-1)/(N-K))
u1 <- apply(estfun(fm), 2,
function(x) tapply(x, cluster1, sum))
u2 <- apply(estfun(fm), 2,
function(x) tapply(x, cluster2, sum))
u12 <- apply(estfun(fm), 2,
function(x) tapply(x, cluster12, sum))
vc1 <- dfc1*sandwich(fm, meat=crossprod(u1)/N)
vc2 <- dfc2*sandwich(fm, meat=crossprod(u2)/N)
vc12 <- dfc12*sandwich(fm, meat=crossprod(u12)/N)
vcovMCL <- (vc1+vc2-vc12)*dfcw
coeftest(fm, vcovMCL)
}
然后,我指定我的多元线性模型并调用结果:
### cluster on two variables (year and anation)
mclx(fm, 1, data$year, data$nation)
不幸的是,我无权在此处发布数据。当我使用 Arai (2015) 提供的测试数据时,问题不会发生,但我无法弄清楚我的数据存在问题。所以,也许有人有一个大致的想法,为什么标准误差、t 统计量和 p 值的某些参数估计会产生 NA,以及如何避免这种情况?我会非常感谢任何提示...