3

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.

Helix123
  • 3,502
  • 2
  • 16
  • 36
Xander
  • 87
  • 1
  • 11

3 Answers3

2

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

LJH
  • 21
  • 2
  • 1
    Thanks for sharing. As you can see from my data, there are no (-)Inf cases. Hopefully, though, this may be helpful for others where this is the case. – Xander Dec 14 '17 at 15:25
1

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.)

Helix123
  • 3,502
  • 2
  • 16
  • 36
  • I guess I don't understand. If the estimator yields a perfect fit, wouldn't it be a valid regressor? And if the other methods don't work? I follow that the error message is useless, but how were you able to determine this? Also, can you clean up your verbiage some? What's a 'between regression'? – Xander Apr 01 '17 at 15:53
0

This problem also arises when one tries to use a variable that consists of strings. For me this exact error arose when I tried to use a data frame that contained a column like

data$column
"1", "2", "3", "4", ...

Replacing the strings with their numerical counterparts using as.numeric(data$column) solves the problem and allows the regression.