我正在复制使用 Stata 的 xtregar
所做的估计。命令,但我使用的是 R。xtregar
command 实现了 Baltagi 和 Wu (1999) “不等距面板数据回归与 AR(1) 干扰”论文中的方法。正如Stata描述的那样:
xtregar fits cross-sectional time-series regression models when the disturbance term is first-order autoregressive. xtregar offers a within estimator for fixed-effects models and a GLS estimator for random-effects models. xtregar can accommodate unbalanced panels whose observations are unequally spaced over time.
到目前为止,对于固定效应模型,我使用了
plm
R 的包。尝试如下所示:plm(data=A, y ~ x1 + x2, effect = "twoways", model = "within")
然而并不完整(与
xtregar
描述相比)并且结果与 Stata 提供的结果不太一样。此外,Stata 的命令需要设置一个面板变量和一个时间变量,该功能(据我所知)在 plm
中不存在。环境。我应该和
plm
和解吗?或者有另一种方法吗?PS:我彻底搜索了不同的网站,但没有找到与 Stata 相同的
xtregar
.更新
在阅读了 Croissant 和 Millo(2008 年)“R 中的面板数据计量经济学:
plm
包”,特别是第 7.4 节“nlme
中的一些有用的‘计量经济学’模型”之后,我在估计的随机效应部分使用了类似的东西:gls(data=A, y ~ x1 + x2, correlation = corAR1(0, form = ~ year | pays), na.action = na.exclude)
尽管如此,以下结果与Stata的结果更接近
lme(data=A, y ~ x1 + x2, random = ~ 1 | pays, correlation = corAR1(0, form = ~ year | pays), na.action = na.exclude)
最佳答案
试试 {panelAR}
.这是一个面板数据回归包,用于解决 AR1 类型的自相关。
不幸的是,我没有 Stata,所以我无法测试在 panelCorrMethod
中复制哪种相关方法
library(panelAR)
model <-
panelAR(formula = y ~ x1 + x2,
data = A,
panelVar = 'pays',
timeVar = 'year',
autoCorr = 'ar1',
rho.na = TRUE,
bound.rho = TRUE,
panelCorrMethod ='phet' # You might need to change this parameter. 'phet' uses the HW Sandwich stimator for heteroskedasticity cases, but others are available.
)
关于R 相当于 Stata 的 xtregar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39585090/