Error computing Robust Standard errors in Panel re

2019-04-02 02:47发布

问题:

I am using the plm library to run fixed effect regressions and the sandwich,lmtest libraries to compute robust standard errors. I have no problem running the regressions, but in some instances when I go to compute the standard errors I get the following error:

library(plm)
library(sandwich)
library(lmtest)

fe_reg <- plm(y ~ x + I(x^2)+factor(date), data=reg_data, index=c("id","date"), model="within")
coeftest(fe_reg, vcov.=vcovHC(fe_reg, type="HC1"))

RRuntimeError: Error in solve.default(crossprod(demX))
  system is computationally singular: reciprocal condition number = 1.84726e-25

I do not have any problems computing the coefficients or the "normal" standard errors (ie homoscedastic). Also, I have no problem computing the robust standard errors when I omit the quadratic term:

fe_reg <- plm(y ~ x +factor(date), data=reg_data, index=c("id","date"), model="within")  

Anyone have any idea what is going on? If the design matrix were singular then the coefficients should not have been computed, so I don't understand where the issue is coming from when computing the standard errors.

Thanks!

回答1:

If I remember correctly, plm is not very verbose. I think it is possible to have a singular matrix but plm does not complain. lm is usually more verbose. So try

 lm_mod1 <- lm(y ~ x + I(x^2)+factor(date), data=reg_data)
 summary(lm_mod1)

lmwill tell you in it's summary output if there is a problem calculating one coefficient (coefficient is NA in the table and there should be a note at the top of the output as well). Edit: The note at top of lm's summary output should be "Coefficients: (1 not defined because of singularities)" in this case.

Edit There is another possibility why the coeftest is not working: If your model.matrix contrains very large values as well as very small values, solve might not be able to solve the system of linear equations by computation in the vcovHC function. Thus, have a look at model.matrix(y ~ x + I(x^2)+factor(date), data=reg_data) if this is the case. If so, try rescaling some variables (e.g. multiply oder divide by 100 oder 1000 [also log() makes sense sometimes). Take care, the interpretation of the coefficients changes due to the change of scales!