Fixed Effects Regression with Interaction Term Causes Error

五迷三道 提交于 2019-12-01 17:27:36

问题


I am trying to estimate a panel dataset with an interaction term for geographical areas (LoadArea, DischargeArea) which signifies a route. Using the fixed effects specification, it does not like the interaction term (LoadArea * DischargeArea) and produces the following error when you summarize the regression:

mult_fe<-plm(log(DayRate)~LoadArea *DischargeArea + factor(Laycan.Day.Diff) + CapUtil + Age
+ I(Age^2) + WFRDWT + lag_BDTI, data=mult_reg1,model="within");


summary(mult_fe)
Error in crossprod(t(X), beta) : non-conformable arguments

This works fine in a normal OLS regression replacing plm with the lm function. Question is why isn't it working for my model?


回答1:


This is a problem of collinearity among your variables.

The lm command automatically places NAs in the beta vector for variables that were not estimated due to colinearity, but PLM does not.

When you have LoadArea*DischargeArea PLM will three variables to your model:

LoadArea + DischargeArea + LoadArea:DischargeArea

After that PLM will demean them.

In this case, and without further information on your data my guess is that one of these variables is perfectly collinear with one of the factors levels in:

as.factor(Laycan.Day.Diff)

In your case I would try to estimate the model without the factor. If it works you know the factors are causing the problem. If it comes to that you can then convert each factor to a explicit 0/1 dummy and add them one by one until you understand where the problem is coming from.

To determine which variables are collinear you could try something like:

require(data.table)
tmp      <- data.table(var1=1:10,var2=55:64,userid=rep(c(1,2),5))
cols     <- c('var1','var2')
newnames <- c('demeaned_var1','demeaned_var2')
tmp[,(newnames):=.SD-lapply(.SD,mean),.SDcols=cols,by=userid]
cor(tmp[,newnames,with=F])

Line 5 is the demeaning. This other stack overflow post describes the operations of the data.table that i used above in detail.

The output of the code above will be:

> 
              demeaned_var1 demeaned_var2
demeaned_var1             1             1
demeaned_var2             1             1

This will tell you which demeaned vars are perfectly collinear.




回答2:


Please note that plm() is playing fine all along, its the summary.plm() function that's breaking bad! Delving deeper into the function reveals the trouble in the part where it calculates R^2.

Read more here on the same problem at stackexchange

Quick and not so elegant workarounds include:

(1) Replacing LoadArea:DischargeArea with LoadArea*DischargeArea

(2) Manually create separate interaction variable

LoadxDischarge <- LoadArea*DischargeArea 



回答3:


A way to get at least the standard errors etc. is to use

library("sandwich")
library("lmtest")
coeftest(mult_fe)


来源:https://stackoverflow.com/questions/16718616/fixed-effects-regression-with-interaction-term-causes-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!