如何解决使用梯度和粗麻布矩阵手动计算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 举报,一经查实,本站将立刻删除。