4
votes

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)
1
Can you provide sample data and the result you expect (i.e., the result of Stata commant)?Kota Mori
By the way, you can set the panel variable and time variable by index argument! It is in the example section of ?plm.Kota Mori
@KotaMori thanks for your comments! I completely missed the index option, I'll look into it! As for the sample and result I'll edit the question to add thatDiego
I'm also looking for this and I don't find it in the plm documentation. Your code in any case simply estimates a model with individual specific intercepts and time dummies (by the way, plm is bad at that! Very slow and quickly out of memory!). Maybe this helps: stats.stackexchange.com/questions/6469/… as pglm exists as wellJakob
This is more a CrossValidated question imho...pietrodito

1 Answers

2
votes

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