如何从面板模型的 coeftest() 中获取整个协方差矩阵
How can I get the entire covariance matrix from coeftest() of a panel model
我 运行 使用 plm
包进行面板回归,如下所示:
library("plm")
Data <- data.frame(id = c(rep("a",50), rep("b", 50)),
y = rnorm(100),
x = c(rnorm(50), rnorm(50, sd = 5)),
z = c(rnorm(50), rnorm(50, sd = 3)))
panelmodel <- plm(y ~ x + z,
data = Data,
effect = "individual",
model = "within",
index = "id")
我想调整我的聚类标准误差,我可以使用 lmtest
包来做到这一点,例如:
library("lmtest")
coeftest(panelmodel,
vcov = vcovHC(panelmodel,
type = "sss"), # I need this exact type of standard errors
cluster = "id")
但我需要这里用于计算标准误差的聚类调整协方差矩阵。上面使用了未调整的协方差矩阵,它是这样的:
vcovHC(panelmodel, type = "sss")
但这还没有调整。如何获得 coeftest 计算出的 return 调整后标准误差的协方差矩阵?我需要它来进一步计算不同的协方差。
不幸的是,multiwayvcov
包不能与 plm 对象一起使用,所以一个已经出局了。
查看文档:?plm::vcovHC.plm
:vcovHC(panelmodel, type = "sss")
已经是您要查找的内容,它与 vcovHC(panelmodel, type = "sss", cluster = "group")
相同。
您传递给 coeftest()
(而不是 vcovHC()
)的参数 cluster
未被评估,因为它是函数的未知参数以及它传递给的函数(至少以你的例子为例)。你可以通过比较这三个命令的结果来查看,它们都是一样的:
coeftest(panelmodel, vcov. = vcovHC(panelmodel, type = "sss"))
coeftest(panelmodel, vcov. = vcovHC(panelmodel, type = "sss"), cluster = "id")
coeftest(panelmodel, vcov. = vcovHC(panelmodel, type = "sss"), cluster = "nonsense")
我 运行 使用 plm
包进行面板回归,如下所示:
library("plm")
Data <- data.frame(id = c(rep("a",50), rep("b", 50)),
y = rnorm(100),
x = c(rnorm(50), rnorm(50, sd = 5)),
z = c(rnorm(50), rnorm(50, sd = 3)))
panelmodel <- plm(y ~ x + z,
data = Data,
effect = "individual",
model = "within",
index = "id")
我想调整我的聚类标准误差,我可以使用 lmtest
包来做到这一点,例如:
library("lmtest")
coeftest(panelmodel,
vcov = vcovHC(panelmodel,
type = "sss"), # I need this exact type of standard errors
cluster = "id")
但我需要这里用于计算标准误差的聚类调整协方差矩阵。上面使用了未调整的协方差矩阵,它是这样的:
vcovHC(panelmodel, type = "sss")
但这还没有调整。如何获得 coeftest 计算出的 return 调整后标准误差的协方差矩阵?我需要它来进一步计算不同的协方差。
不幸的是,multiwayvcov
包不能与 plm 对象一起使用,所以一个已经出局了。
查看文档:?plm::vcovHC.plm
:vcovHC(panelmodel, type = "sss")
已经是您要查找的内容,它与 vcovHC(panelmodel, type = "sss", cluster = "group")
相同。
您传递给 coeftest()
(而不是 vcovHC()
)的参数 cluster
未被评估,因为它是函数的未知参数以及它传递给的函数(至少以你的例子为例)。你可以通过比较这三个命令的结果来查看,它们都是一样的:
coeftest(panelmodel, vcov. = vcovHC(panelmodel, type = "sss"))
coeftest(panelmodel, vcov. = vcovHC(panelmodel, type = "sss"), cluster = "id")
coeftest(panelmodel, vcov. = vcovHC(panelmodel, type = "sss"), cluster = "nonsense")