Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed Effects Regression with Interaction Term Causes Error

Tags:

r

plm

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?

like image 761
Sassafras Avatar asked May 23 '13 15:05

Sassafras


People also ask

What do you do when an interaction term is not significant?

If the main effects are significant but not the interaction you simply interpret the main effects, as you suggested. You do not need to run another model without the interaction (it is generally not the best advice to exclude parameters based on significance, there are many answers here discussing that).

Can you include interaction term without main effect?

Is it really necessary to include both main effects when the interaction is present? The simple answer is no, you don't always need main effects when there is an interaction. However, the interaction term will not have the same meaning as it would if both main effects were included in the model.

Can you interpret main effects when interaction is significant?

When you have statistically significant interactions, you cannot interpret the main effect without considering the interaction effects.

What does a significant interaction mean?

A significant interaction effect means that there are significant differences between your groups and over time. In other words, the change in scores over time is different depending on group membership.


2 Answers

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 
like image 96
Anish Sugathan Avatar answered Sep 29 '22 12:09

Anish Sugathan


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.

like image 43
mmgm Avatar answered Sep 29 '22 13:09

mmgm