[双向FE模型在R中给出“空模型”

问题描述 投票:1回答:1

我正在尝试使用plm在R中运行2路固定效果模型。我正在尝试通过市政投票对某项事件进行治疗。

我想在市政当局和全民公决固定影响下运行该模型。每行或每个单元都是一对市政*公投。

我正在尝试使用以下方法拟合模型:

model_2fe <- plm(vote.ant.immig ~ pre.post, data = clean.df, effect = "twoways", index = c("municipality.code", "ref.code")) 

而且我继续得到以下内容:

Error in plm.fit(data, model, effect, random.method, random.models, random.dfcor, : empty model

[如果有帮助,则pre.post是表明治疗情况(1,0)的因子,vote.ant.immig是数字对象,city.city.code是因子,参考代码也是如此。

有人可以帮我吗?谢谢!

r lm panel-data plm
1个回答
0
投票

使用?plm::detect.lindep中的提示,您可以查看经过双向固定效果转换后的数据外观。这是一些代码,可以帮助您到达那里:

dat <- pdata.frame(<inputdata>, index = c("municipalitycode", "refcode"))

fml <- voteantimmig ~ prepost
mf <- model.frame(dat, fml)
modmat_2FE <- model.matrix(mf, model = "within", effect = "twoways")
all(abs(modmat_2FE) < 0.0000000000001) # TRUE
## look at your transformed data in modmat_2FE -> all zero -> empty model

## Analyse why this is the case, per individual, per time period:
modmat_FEi <- model.matrix(mf, model = "within", effect = "individual")
all(abs(modmat_FEi) < 0.0000000000001) # FALSE
## look at your transformed data in modmat_FEi
unique(modmat_FEi) # not so many different values
## look at your transformed data in modmat_FEi with individual and time index next to it: 
modmat_FEiindexes <- cbind(modmat_FEi, dat$municipalitycode, dat$refcode)
## => not much variation left within each individual. 

modmat_FEt <- model.matrix(mf, model = "within", effect = "time")
all(abs(modmat_FEt) < 0.0000000000001) # TRUE
## look at your transformed data in modmat_FEt -> all zero
© www.soinside.com 2019 - 2024. All rights reserved.