错误计算Panel回归模型(plm,R)中的稳健标准误差 [英] Error computing Robust Standard errors in Panel regression model (plm,R)

查看:290
本文介绍了错误计算Panel回归模型(plm,R)中的稳健标准误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用plm库运行固定效应回归,并使用lmtest测试库来计算可靠的标准误差.运行回归没有问题,但是在某些情况下,当我计算标准误差时,会出现以下错误:

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.

谢谢!

推荐答案

如果我没记错的话,plm不太冗长.我认为可以有一个奇异矩阵,但plm不会抱怨. lm通常更详细.所以尝试

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)

lm会在汇总输出中告诉您是否存在计算一个系数的问题(表中的系数为NA,并且在输出的顶部也应有一个注释). 编辑:在这种情况下,lm摘要输出顶部的注释应为系数:(由于奇异而未定义1)".

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.

编辑还有一种可能的原因是coeftest无法正常工作: 如果您的model.matrix约束值既很大又很小,则solve可能无法通过vcovHC函数中的计算来求解线性方程组.因此,如果是这种情况,请查看model.matrix(y ~ x + I(x^2)+factor(date), data=reg_data).如果是这样,请尝试重新缩放某些变量(例如,将乘数除以100乘以1000,[有时log()也有意义).请注意,系数的解释会随着标度的变化而变化!

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!

这篇关于错误计算Panel回归模型(plm,R)中的稳健标准误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆