为什么在 PLM model.matrix 中给出一个全为 0 的列?怎么解决?
Why in PLM model.matrix gives a column with all 0s? How to solve?
我是运行一个使用plm函数的个人级固定效应ols。在相关模型中,我回归了一个具有 2 个水平的自变量,该自变量在受试者之间(受试者间治疗)和另一个具有 2 个水平的自变量在受试者内(在受试者治疗内)变化。
plm 的摘要不显示在主体内变化的自变量的系数。检查 model.matrix 我注意到感兴趣的列由全零组成。
有什么办法可以解决这个问题吗?也许诉诸不同类型的对比?或者在设计上不可能像这样在固定效应模型中估计受试者内变量的影响?
如有任何帮助,我们将不胜感激。
#Reproducible example (unrelated with my actual dataset)
structure(list(DOILN = c(4.3207, 4.1675, 4.0718, 3.8239, 3.6247,
2.044, 1.3759, 1.4596, 1.486, 4.3136), ROSLN = c(-2.0178, -2.2647,
-4.0632, -3.9933, -3.441, -3.6077, -2.8291, -2.6271, -2.4051,
-1.7239), IRATE = c(-0.0295, -0.1228, 0.00288, 0.03388, -0.0295,
0.00288, 0.03849, 0.03388, 0.07165, 0.04809), GDPGROW = c(0.11731,
0.07891, 0.05072, 0.05745, 0.11731, 0.05072, 0.02142, 0.05745,
0.06645, -0.01765), ISOCode = structure(c(4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 3L), .Label = c("BRA", "CHN", "IND", "RUS"), class = "factor"),
ISOCodeBRA = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ISOCodeRUS = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 0), ISOCodeIND = c(0, 0, 0, 0, 0,
0, 0, 0, 0, 1), ISOCodeCHN = c(0, 0, 0, 0, 0, 0, 0, 0, 0,
0)), .Names = c("DOILN", "ROSLN", "IRATE", "GDPGROW", "ISOCode",
"ISOCodeBRA", "ISOCodeRUS", "ISOCodeIND", "ISOCodeCHN"), row.names = c("120453-2010",
"120453-2011", "120453-2012", "120453-2014", "133431-2010", "133431-2012",
"133431-2013", "133431-2014", "133431-2015", "200448-2009"), class = c("pdata.frame",
"data.frame"), index = structure(list(GCKey = structure(c(1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L), .Label = c("120453", "133431",
"200448"), class = "factor"), FiscalY = structure(c(2L, 3L, 4L,
6L, 2L, 4L, 5L, 6L, 7L, 1L), .Label = c("2009", "2010", "2011",
"2012", "2013", "2014", "2015"), class = "factor")), .Names = c("GCKey",
"FiscalY"), row.names = c(915L, 647L, 35L, 41L, 83L, 68L, 220L,
330L, 497L, 1219L), class = c("pindex", "data.frame")))
mod <-plm(ROSLN ~ DOILN + GDPGROW + IRATE + factor(ISOCode),
data = dat, model = "within")
model.matrix(mod)
summary(mod)
我认为问题在于您使用的是内部模型,GCKey
中的 ISOCode
没有变化 - 这是索引。
> table(index(dat)$GCKey, dat$ISOCode)
BRA CHN IND RUS
120453 0 0 0 4
133431 0 0 0 5
200448 0 0 1 0
因此,将内变换应用于 ISOCode
虚拟回归量会生成全零向量。例如,如果您使用 model='pooling'
,您会看到一个更符合您预期的模型矩阵。
我是运行一个使用plm函数的个人级固定效应ols。在相关模型中,我回归了一个具有 2 个水平的自变量,该自变量在受试者之间(受试者间治疗)和另一个具有 2 个水平的自变量在受试者内(在受试者治疗内)变化。
plm 的摘要不显示在主体内变化的自变量的系数。检查 model.matrix 我注意到感兴趣的列由全零组成。
有什么办法可以解决这个问题吗?也许诉诸不同类型的对比?或者在设计上不可能像这样在固定效应模型中估计受试者内变量的影响?
如有任何帮助,我们将不胜感激。
#Reproducible example (unrelated with my actual dataset)
structure(list(DOILN = c(4.3207, 4.1675, 4.0718, 3.8239, 3.6247,
2.044, 1.3759, 1.4596, 1.486, 4.3136), ROSLN = c(-2.0178, -2.2647,
-4.0632, -3.9933, -3.441, -3.6077, -2.8291, -2.6271, -2.4051,
-1.7239), IRATE = c(-0.0295, -0.1228, 0.00288, 0.03388, -0.0295,
0.00288, 0.03849, 0.03388, 0.07165, 0.04809), GDPGROW = c(0.11731,
0.07891, 0.05072, 0.05745, 0.11731, 0.05072, 0.02142, 0.05745,
0.06645, -0.01765), ISOCode = structure(c(4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 3L), .Label = c("BRA", "CHN", "IND", "RUS"), class = "factor"),
ISOCodeBRA = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ISOCodeRUS = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 0), ISOCodeIND = c(0, 0, 0, 0, 0,
0, 0, 0, 0, 1), ISOCodeCHN = c(0, 0, 0, 0, 0, 0, 0, 0, 0,
0)), .Names = c("DOILN", "ROSLN", "IRATE", "GDPGROW", "ISOCode",
"ISOCodeBRA", "ISOCodeRUS", "ISOCodeIND", "ISOCodeCHN"), row.names = c("120453-2010",
"120453-2011", "120453-2012", "120453-2014", "133431-2010", "133431-2012",
"133431-2013", "133431-2014", "133431-2015", "200448-2009"), class = c("pdata.frame",
"data.frame"), index = structure(list(GCKey = structure(c(1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L), .Label = c("120453", "133431",
"200448"), class = "factor"), FiscalY = structure(c(2L, 3L, 4L,
6L, 2L, 4L, 5L, 6L, 7L, 1L), .Label = c("2009", "2010", "2011",
"2012", "2013", "2014", "2015"), class = "factor")), .Names = c("GCKey",
"FiscalY"), row.names = c(915L, 647L, 35L, 41L, 83L, 68L, 220L,
330L, 497L, 1219L), class = c("pindex", "data.frame")))
mod <-plm(ROSLN ~ DOILN + GDPGROW + IRATE + factor(ISOCode),
data = dat, model = "within")
model.matrix(mod)
summary(mod)
我认为问题在于您使用的是内部模型,GCKey
中的 ISOCode
没有变化 - 这是索引。
> table(index(dat)$GCKey, dat$ISOCode)
BRA CHN IND RUS
120453 0 0 0 4
133431 0 0 0 5
200448 0 0 1 0
因此,将内变换应用于 ISOCode
虚拟回归量会生成全零向量。例如,如果您使用 model='pooling'
,您会看到一个更符合您预期的模型矩阵。