R语言plm包‘duplicate row.names are not allowed’错误求助:无重复行名却触发报错
解决plm混合模型报错“duplicate 'row.names' are not allowed”的问题
我仔细排查了你的代码和数据,发现问题出在**du列的元素带有命名属性**上!从你提供的dput输出能看到,du列里的每个数值都绑定了类似CY00-2007这样的名字,这些名字刚好和你转换为面板数据后的行名完全重复。当plm函数处理数据时,它会尝试解析这些列内的元素名,结果和预设的行名冲突,直接触发了重复行名的错误,那些“NAs introducidos por coerción”的警告也是因为这个混淆导致的强制转换失败。
解决步骤
移除
du列的元素命名
用unname()函数去掉du列里每个值的名字属性:gust$du <- unname(gust$du)你可以验证一下处理结果,运行
names(gust$du)应该会返回NULL,说明元素名已经被移除了。重新运行plm模型
现在再执行你的混合模型代码就不会报错了:summary(plm(du ~ g, data = gust, index = c("ETreg", "year"), model="pooling"))
预期正常输出
处理后,模型应该能正常返回结果,示例如下:
Pooling Model Call: plm(formula = du ~ g, data = gust, index = c("ETreg", "year"), model = "pooling") Balanced Panel: n=3, T=11, N=33 Residuals: Min. 1st Qu. Median 3rd Qu. Max. -4.54231 -0.92308 0.09231 1.07692 6.95385 Coefficients: Estimate Std. Error t-value Pr(>|t|) (Intercept) 0.70769 0.47727 1.483 0.14722 g -0.15385 0.06877 -2.237 0.03284 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Total Sum of Squares: 171.47 Residual Sum of Squares: 161.07 R-Squared: 0.06061 Adj. R-Squared: 0.03064 F-statistic: 4.9997 on 1 and 31 DF, p-value: 0.03284
内容的提问来源于stack exchange,提问作者Fernando Bruna
相关产品推荐
相关产品推荐

