Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with Error: 0 (non-NA) cases plm package?

Tags:

r

statistics

plm

I know this has been asked, and I've looked at at least 10 threads on this topic, but I still can't understand it. I'm using the plm package to estimate a random effects model on some panel data. I have a model that I have specified, but when I insert an additional variable that does not contain any NA's, I get the following error message.

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  0 (non-NA) cases

I have pared it down as much as possible to the following:

plm(dependent ~ varA + varB + varC + varD, data=mydata,
    model="random", index=c("Name", "Month"), na.action=na.exclude)

Without varA the model works fine. In place of VarA, I can insert other variables that I have at my disposal, and some will work while others will not.

My data can be obtained here.

I have tried using na.omit(mydata), which works sometimes but not reliably.

Any insight would be appreciated.

like image 862
Xander Avatar asked Sep 11 '25 17:09

Xander


2 Answers

This is an old post by now but it is the only reference to this specific issue posted on line. I just had this issue using the plm package and the plm function specifically. I figured out that the error message is misleading in this case. In my case the number of complete cases (see function complete.cases()) was not 0 and I couldn't figure out why the plm function was giving me this error message.

After digging through my data, I figured out that the issue was actually the presence of entries in my data having the value -Inf or Inf. I simply replaced those entries by NA (irony!) and the plm function ran smoothly.

Note that using the lm function for the same regression formula actually gave me this actual error message:

"Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in 'y'"

This is clearly more informative of what is really happening.

Best regards

like image 139
LJH Avatar answered Sep 13 '25 05:09

LJH


This happens due to the specifics of your data and the model and this is, thus, rather a statistical question:

The between regression used in the default random effects method of Swamy-Arora (random.method = "swar") is not estimable for this model (4 individuals (Name in your data) while at the same time trying to estimate 4 covariates and intercept), thus the model is not estimable with the default RE estimator. You can try a different random effects method, e.g., set random.method to "amemiya" or "walhus".

plm(dependent ~ varA + varB + varC + varD, data=mydata, 
    model="random", index=c("Name", "Month"), random.method = "amemiya")

(Yes, the error message of plm could be improved here.)

like image 42
Helix123 Avatar answered Sep 13 '25 07:09

Helix123