我正在尝试类似的方法,但是,我找不到直接的解决方案。我正在估计一个在 fe 模型上存在滞后和领先的事件研究。以下对我有用:
ES1<-plm(total_thefts ~ lag6 + lag5 + lag4 + lag3 + lag2 + E + lead1 + lead2 + lead3 + lead4 + lead5 + lead6 + factor(month) + factor(year), data = panel, model="within")
由于 plm 没有直接的方法来估计稳健的标准误差,我手动进行并替换原来的:
G <- length(unique(panel$id))
c <- G/(G - 1)
robust_se <- coeftest(ES1, c * vcovHC(ES1, type = 'HC1', cluster = 'group'))
ES1<-summary(ES1)
ES1$coefficients[,2:4] <- robust_se[,2:4]
之后,我按照post 分离我感兴趣的系数并估计 CI 波段 (95%):
coefs <- tidy(ES1[["coefficients"]])
coefs$conf.low <- coefs$Estimate+c(-1)*coefs$Std..Error*qt(0.975,42)
coefs$conf.high <- coefs$Estimate+c(1)*coefs$Std..Error*qt(0.975,42)
最后,我保留我感兴趣的参数并绘制事件研究:
interest <- c("lag6","lag5","lag4","lag3","lag2","E","lead1","lead2","lead3","lead4","lead5","lead6")
coefs <- subset(coefs,coefs$.rownames%in%interest)
coefs$time <- c(seq(-6,-2,1),seq(0,6,1))
ggplot(coefs, aes(time, Estimate))+
geom_line() +
geom_point()+
geom_pointrange(aes(ymin = conf.low, ymax = conf.high))+
geom_hline(yintercept = 0, linetype = 2) +
ggtitle(paste0("N: ",nobs(ES1),", Sample: ",pdim(ES1)$nT$n,", Buff: 1000m"))) +
theme(plot.title = element_text(hjust = 0.5)))