我正在做一个包含固定效果模型和系统GMM估算的项目。我想为此使用plm软件包。但是,当我运行回归时,会收到错误消息:
“ plm.fit(公式,数据,模型,效果,random.method,random.models, 0(非NA)案例”
我已将问题追溯到plm包中使用的滞后函数:当我尝试在data.frame的列上使用它时,它仅返回所有不等于0的滞后的NA值(即当前值) 。
我还在plm软件包中包含的数据帧上尝试了该功能,并且该功能可以按预期工作。因此,我认为这可能是由于我的数据帧被先前的数据操作保存为tbl_df,但是将其保存为数据帧也无法解决问题。
以下代码显示了部分数据,我将其转换为pdata.frame,然后对其运行了固定效果模型。这导致了上面提到的错误消息。然后我分别检查了滞后函数,发现它在我的数据集上无法正常工作。
library(plm)
example <- structure(list(
X = c(
1L, 37L, 89L, 145L, 215L, 295L, 391L, 503L,
504L, 616L, 617L
), countrycode = structure(c(
2L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 2L, 1L, 2L
), .Label = c("ALB", "ARG"), class = "factor"),
year = c(
1970L, 1975L, 1980L, 1985L, 1990L, 1995L, 2000L,
2005L, 2005L, 2010L, 2010L
), rgdppc = c(
3611.53200479887,
3800.75962232602, 3978.31086065157, 4387.38321845057, 5553.84269266385,
10810.9468450015, 12719.6544787325, 5920.55446541169, 12511.9821473033,
9544.73991912729, 15841.658208159
), growth = c(
0.134499926825177,
0.0510688869844671, 0.0456563749718093, 0.0978756492215904,
0.235757093672094, 0.666069152314748, 0.162589176374155,
0.205953161751015, -0.0164616369654098, 0.477560104733307,
0.235956308809754
), pop_growth = c(
0.0726537583373137, 0.0837385279741412,
0.0753099311604224, 0.0780944388423599, 0.0742106054169795,
0.066915782210657, 0.0572695650290527, -0.0138011742778001,
0.0548156893291569, -0.0460748632561909, 0.051732718162242
), Gini = c(
0.468112837531106, 0.441088756489684, 0.417000047344437,
0.392382688333824, 0.367346706677727, 0.34287710283137, 0.352476770021164,
0.221846080582856, 0.333761509816487, 0.180112255727025,
0.319847139735362
), bcGini = c(
0.561735405037327, 0.529306507787621,
0.500400056813324, 0.470859226000588, 0.440816048013272,
0.411452523397644, 0.422972124025397, 0.266215296699427,
0.400513811779785, 0.21613470687243, 0.383816567682435
),
bcwGini = c(
0.645650701245952, 0.60225255667686, 0.563484696480372,
0.525119712533559, 0.487339228077908, 0.451398810473532,
0.461104421570223, 0.322099208203327, 0.434846178826301,
0.263971449718222, 0.414250358008174
), capgrowth = c(
0.117957011507009,
0.178649110088593, 0.173653210113507, 0.0785021513269335,
-0.00224558647600759, 0.0267416371475058, 0.10224003699156,
0.508306023156432, -0.000946393858047401, 0.42009422610586,
0.155065623868424
), mschool = c(
6.33, 6.69, 7.06, 7.46, 7.86,
8.26, 8.66, 9.4, 9.06, 9.68, 9.43
)
), row.names = c(NA, -11L), class = "data.frame")
pexample <- pdata.frame(example, index = c("countrycode", "year"))
mod1 <- plm(growth ~ plm::lag(log(rgdppc), 1) + pop_growth + capgrowth +
plm::lag(log(mschool), 1), data = pexample,
effect = "twoways", model = "within",
index = c("countrycode", "year"), na.action = "na.omit")
plm::lag(pexample$growth, 0:2)
以下代码显示了在包含的数据帧上应使用滞后函数的情况。
data("EmplUK", package = "plm")
E <- pdata.frame(EmplUK, index = c("firm", "year"))
head(plm::lag(E$emp, 0:2))
这是我的SessionInfo的输出:
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_0.8.0.1 readr_1.3.1 plm_1.7-0 Formula_1.2-3
loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 rstudioapi_0.10 magrittr_1.5 hms_0.4.2 MASS_7.3-51.4
[6] tidyselect_0.2.5 lattice_0.20-38 R6_2.4.0 rlang_0.3.4 styler_1.1.0
[11] tools_3.6.0 grid_3.6.0 nlme_3.1-139 maxLik_1.3-4 miscTools_0.6-22
[16] lmtest_0.9-37 assertthat_0.2.1 tibble_2.1.1 crayon_1.3.4 bdsmatrix_1.3-3
[21] purrr_0.3.2 glue_1.3.1 sandwich_2.5-1 compiler_3.6.0 pillar_1.3.1
[26] backports_1.1.4 pkgconfig_2.0.2 zoo_1.8-5
我正在使用RStudio版本1.2.1335
有人对此问题有经验吗? 任何帮助将不胜感激。