Diego
Diego

Reputation: 156

R equivalent to Stata's xtregar

I'm doing a replication of an estimation done with Stata's xtregar command, but I'm using R instead.

The xtregar command implements the method from Baltagi and Wu (1999) "Unequally spaced panel data regressions with AR(1) disturbances" paper. As Stata describes it:

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.

So far, for the fixed-effects model, I used the plm package for R. The attempt looks like this:

plm(data=A, y ~ x1 + x2, effect = "twoways", model = "within")

Nevertheless is not complete (comparing to xtregar description) and the results are not quite like the ones Stata provides. Furthermore, Stata's command needs to set a panel variable and a time variable, feature that's (as far as I can tell) absent in the plm environment.

Should I settle with plm or is there another way of doing this?

PS: I searched thoroughly different websites but failed to find a equivalent to Stata's xtregar.

Update

After reading Croissant and Millo (2008) "Panel Data Econometrics in R: The plm Package", specifically seccion 7.4 "Some useful 'econometric' models in nlme" I used something like this for the Random Effects part of the estimation:

gls(data=A, y ~ x1 + x2, correlation = corAR1(0, form = ~ year | pays), na.action = na.exclude)

Nevertheless the following has results closer to those of Stata

lme(data=A, y ~ x1 + x2, random = ~ 1 | pays, correlation = corAR1(0, form = ~ year | pays), na.action = na.exclude)

Upvotes: 4

Views: 1105

Answers (1)

Nicolás Velasquez
Nicolás Velasquez

Reputation: 5898

Try {panelAR}. This is a package for regressions in panel data that addresses AR1 type of autocorrelations. Unfortunately, I do not own Stata, so I can not test which correlation method to replicate in 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.
    )

Upvotes: 2

Related Questions