【发布时间】:2019-05-01 09:37:39
【问题描述】:
我试图在 plm 之后使用 clubSandwich 包中的 vcovCR() 为我的模拟数据(我用于功率模拟)指定一个集群变量,但我收到以下错误消息:
“[.data.frame(eval(mf$data, envir), , index_names) 中的错误:选择了未定义的列”
我不确定这是否特定于 vcovCR() 或关于 R 的一般内容,但谁能告诉我我的代码有什么问题? (我在How to cluster standard errors of plm at different level rather than id or time?看到了一个相关的帖子,但它并没有解决我的问题)。
我的代码:
N <- 100;id <- 1:N;id <- c(id,id);gid <- 1:(N/2);
gid <- c(gid,gid,gid,gid);T <- rep(0,N);T = c(T,T+1)
a <- qnorm(runif(N),mean=0,sd=0.005)
gp <- qnorm(runif(N/2),mean=0,sd=0.0005)
u <- qnorm(runif(N*2),mean=0,sd=0.05)
a <- c(a,a);gp = c(gp,gp,gp,gp)
Ylatent <- -0.05*T + a + u
Data <- data.frame(
Y = ifelse(Ylatent > 0, 1, 0),
id = id,gid = gid,T = T
)
library(clubSandwich)
library(plm)
fe.fit <- plm(formula = Y ~ T, data = Data, model = "within", index = "id",effect = "individual", singular.ok = FALSE)
vcovCR(fe.fit,cluster=Data$id,type = "CR2") # doesn't work, but I can run this by not specifying cluster as in the next line
vcovCR(fe.fit,type = "CR2")
vcovCR(fe.fit,cluster=Data$gid,type = "CR2") # I ultimately want to run this
【问题讨论】:
-
对我来说看起来像是 clubSandwich 中的一个错误,并且已经在此处报告:github.com/jepusto/clubSandwich/issues/38
-
谢谢。但它适用于其他数据集。例如:
library(clubSandwich) library(plm) data("Produc", package = "plm") plm_FE <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc, index = c("state","year"), effect = "individual", model = "within") vcovCR(plm_FE, type="CR2",cluster = Produc$state)
标签: r plm standard-error