plm 包中的内部模型和随机模型的问题 [英] Problems with within and random models in plm package

查看:90
本文介绍了plm 包中的内部模型和随机模型的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 plm 包,但我遇到了随机和模型内的问题,这些错误会显示空模型".但是,模型不是空的.在 plm.fit 的源代码中,错误的来源是这样的(从我的头顶写...)

I am working with plm package and I have problem with random and within models, which are giving errors which says "empty model". However, the model is not empty. In the source code for plm.fit, where the error originates it says something like (writing from the top of my head...)

X <- model.matrix(formula,data, lhs=1,...)
if (ncol(X) == 0) stop("empty model")

但是,如果我尝试使用我输入到原始函数中的命令来复制这种行为,它会给出 ncol(X) 为 17 或类似的值.

however if I try to replicate this behaviour with the commands I am inputing into the original function, it gives ncol(X) is 17 or something like that.

我的代码是(数据删除...):

My code is (data deleted...):

library(sampleSelection)
library(foreign)
library(censReg)
library(plm)
library(micEcon)
library(ggplot2)

data <- read.dta('kpfull1.dta')
summary(data)
attach(data)

data$profit_share <- p91/tnsvp
data$debt_assets <- d91/naba
data$naba3 <- naba^3
data$difprofit <- p91-p90
data$agri <- (mind==1)*1
data$hi <- (mind==2)*1
data$li <- (mind==3)*1
data$constr <- (mind==4)*1
data$trans <- (mind==5)*1
data$trade <- (mind==6)*1
data$rd <- (mind==7)*1
data$ser <- (mind==8)*1
data$fin <- (mind==9)*1
data$for1 <- data[,7]
detach(data)
data1 <- data
panel <- pdata.frame(data, c("num","rnd"))

testovaci <- plm(tb ~ profit_share  + debt_assets + naba + naba3 + for1 + dom + difprofit + agri + hi + li + constr + trans + trade + rd + ser + fin, data = panel, model = "within")
summary(testovaci)

model.matrix(tb ~ profit_share  + debt_assets + naba + naba3 + for1 + dom + difprofit + agri + hi + li + constr + trans + trade + rd + ser + fin, data)

model.matrix(tb ~ profit_share  + debt_assets + naba + naba3 + for1 + dom + difprofit + agri + hi + li + constr + trans + trade + rd + ser + fin, panel)

谢谢,Tomáš Křehlík.

Thanks, Tomáš Křehlík.

推荐答案

Giovanni Millo 在 R-help 中的回答:

Answered in R-help by Giovanni Millo:

亲爱的托马斯,亲爱的名单,

Dear Tomas, dear list,

跟进,因为在此期间我通过私人方式获得了数据沟通.正如我所怀疑的,这个问题隐藏在一些缺乏数据的时间变化.事实上,OLS 工作正常:

a follow-up, as in the meantime I got the data by private communication. The problem, as I suspected, is hidden in some lack of time variability in the data. In fact, OLS works fine:

% fm 是公式,data 是数据集,panel 是转化为 pdata.frame 的数据集代码>

% fm is the formula, data is the dataset, panel is the dataset transformed as a pdata.frame

summary(lm(fm, data))

%(输出正常,省略)

就像plm池化"一样

summary(plm(fm, panel, model="pooling"))

单向(个体)效应池化模型

Oneway (individual) effect Pooling Model

%(输出正常,省略)

但是 FE 失败了:

summary(plm(fm, panel, model="within"))

plm.fit(formula,) 中的错误data, model, effect, random.method, inst.method) : 空模型

和各种 RE 方法一样

as do the various RE methods

summary(plm(fm, panel, model="random"))

plm.fit(formula,) 中的错误data, model = "within", effect = effect) : 空模型

...如果您查看错误消息,很明显它是有问题的内部/FE 部分(RE 方法基于 FE估计误差分量).事实上,试图面板差异任何右侧变量都会导致全为零(NaN 用于方差份额,即 0/0),例如第一个:

...and if you look at the error message, it is clear that it is the within/FE part that has problems (RE methods are based on FE for estimating the error components). In fact, trying to panel-difference any right-hand side variable results in all zeros (NaNs are for variance shares, which are 0/0), e.g. the first one:

summary(diff(panel$profit_share))

总平方和:0 id 时间NaN NaN

但实际上每个人都一样.所以(内部转换)模型实际上是空的,正如原始错误消息所说.现在我不有时间深入研究数据,但是rhs变量都看对我来说是时间常数...

but it is really the same for each. So the (within transformed) model is actually empty, as the original error message says. Now I don't have time to look deeply into the data, but the rhs variables all look time-constant to me...

因此,名单上的小组成员的要点是:主要原因数据引起的错误是不良指标,其次是不良数据可变性;诊断它的第一步是运行 lm() 然后 plm(...,模型=池化").lm() 失败=> 错误的数据,错误的公式;plm(...,"pooling") 失败=> 索引基本上有问题;其他面板方法失败=> 最有可能的数据可变性问题.

The takeaway for panel guys on the list, therefore, is: main cause for data-induced error is bad indices, second one is bad data variability; first step to diagnose it is running lm() and then plm(..., model="pooling"). lm() fails=> bad data, bad formula; plm(..., "pooling") fails=> something basically wrong with indices; other panel methods fail=> most likely data variability problems.

最好的,乔瓦尼

PS 我试图通过对 RE 模型的 ML 估计来规避这个问题,但是没办法,我得到了一个奇异的矩阵错误:所以数据真的是身体不适

PS I tried to circumvent the issue by ML estimation of an RE model but no way, I got a singular matrix error: so the data really are ill-conditioned

library(nlme) remod<-lme(tb ~profit_share + Debt_assets + naba +naba3 + for1 + dom + diffprofit + agri + hi + li + constr + trans +贸易 + rd + ser + fin, random=~1|num, data=data) Errore insolve.default(estimates[dimE[1] - (p:1), dimE[2] - (p:1), drop =FALSE]) : il sistema è numericamente singolare: valore di condizionedi reciprocità = 3.93401e-25

这篇关于plm 包中的内部模型和随机模型的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆