Regression of fixed effects with the term interaction causes an error

I am trying to evaluate a panel dataset with an interaction term for geographic areas (LoadArea, DischargeArea) that denotes a route. Using the specification of fixed effects, she does not like the term interaction (LoadArea * DischargeArea) and produces the following error when summing 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 normal OLS regression, replacing plm with the lm function. The question is why it does not work for my model?

+6
source share
3 answers

This is a collinearity problem between your variables.

The lm command automatically puts NA in a beta vector for variables that were not evaluated due to colinearity, but PLM does not.

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

 LoadArea + DischargeArea + LoadArea:DischargeArea 

After that, PLM will humiliate them.

In this case, and without additional information about your data, I assume that one of these variables is perfectly collinear with one of the factor levels in:

 as.factor(Laycan.Day.Diff) 

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

To determine which variables are collinear, you can 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 humiliation. This other column describes the data table operations that I used in detail above.

Code output above:

 > demeaned_var1 demeaned_var2 demeaned_var1 1 1 demeaned_var2 1 1 

This will tell you which humiliated vars are completely collinear.

+4
source

Note that plm () plays fine well, its summary.plm () function, which breaks badly! A deeper penetration of the function reveals the problem in the part where it calculates R ^ 2.

Read more here about the same issue in stackexchange

Fast and not-so-elegant workarounds include:

(1) Replacing LoadArea: DischargeArea with LoadArea * DischargeArea

(2) Manually create a separate interaction variable

 LoadxDischarge <- LoadArea*DischargeArea 
+5
source

A method of obtaining at least standard errors, etc. is to use

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

Source: https://habr.com/ru/post/945698/


All Articles