使用梯度和粗麻布矩阵手动计算pglm的鲁棒标准误差

问题描述

我想为使用pglm函数生成的固定效应泊松模型手动计算鲁棒的标准误差,该函数不同于plm函数,它确实支持三明治误差矩阵。这使得无法使用标准vcovHC()函数来计算标准错误,因为它确实知道如何以从pglm结果中理解的格式提取术语(请参见Robust Standard Errors: Poisson Panel Regression (pglm,lmtest)https://stats.stackexchange.com/questions/273152/vcovhc-heteroskedasticity-in-pooled-and-panel-probit)。 / p>

在网络上,我发现了以下方法来计算集群健壮的标准错误

library(readstata13)
library(pglm)
library(lmtest)
library(MASS)

ships<-readstata13::read.dta13("http://www.stata-press.com/data/r13/ships.dta")
ships$lnservice=log(ships$service)
res1 <- pglm(accident ~ op_75_79+co_65_69+co_70_74+co_75_79+lnservice,family = poisson,data = ships,effect = "individual",model="within",index = "ship")
summary(res1)

standard_se<-ginv(-res1$hessian)
coeftest(res1,standard_se)

# Similar to e(sample) in STATA
esample<-as.numeric(rownames(as.matrix(res1$gradientObs)))
fc <- ships[esample,]$ship #isolates the groups used in estimation

# Calculates the new Meat portion of our covariance matrix
m <- length(unique(fc))
k <- 5
u <- res1$gradientObs
u.clust <- matrix(NA,nrow=m,ncol=k)
for(j in 1:k){
  u.clust[,j] <- tapply(u[,j],fc,sum)
}
cl.vcov <-ginv(-res1$hessian)%*%( t(u.clust) %*% (u.clust))%*%ginv(-res1$hessian)
coeftest(res1,cl.vcov)

但是,我需要的是鲁棒的,而不是集群鲁棒的标准错误。任何人都可以阐明如何使用渐变和粗麻布矩阵手动进行此操作吗?

任何帮助将不胜感激。谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)