Jude Ryan
2010-Nov-18 22:51 UTC
[R] how do I build panel data/longitudinal data models with AR terms using the plm package or any other package
Hi All, I am doing econometric modeling of panel data (fixed effects). We currently use Eviews to do this, but I have discovered a bug in Eviews 7 and am exploring the use of R to build panel data models / longitudinal data models. I looked at the plm package but do not see how I can incorporate AR terms in the model using the plm package. I have an Eviews model with two AR terms, AR(1) and AR(2), and I am trying to replicate that model using R (and SAS too, if possible) as the fitted values in Eviews for panel data (fixed effects) appear to be wrong. In Eviews I tried a second approach and explicitly coded the fixed effects as dummy variables but the standard errors I get are very different from using the panel data options in Eviews, and thus the final model selected could be very different based on these two approaches. Can I incorporate AR terms in a panel data model using the plm package, and if so, how? Also, are there any other packages like nlme, lme4, .. that will let me build panel data models / longitudinal data models with AR terms? Do any of these packages let you build panel data models / longitudinal data models specifying both AR and MA terms? Looking at the ACF and PCAF it seems that some of the error processes are best/more compactly represented by a combination of AR and MA terms, but unfortunately Eviews only lets you use AR terms for panel data and getting rid of the cross-sections in the panel data and building ARIMA models, which let you specify both AR and MA terms for the error process, will mean building separate models for each cross-section. Besides, we do not have that much data to build time series models and panel data methods let us circumvent the limited data issue. It is my understanding (but I could be wrong) that some of the SAS procs, like HPMIXED, let you specify only one AR term for panel data so I am hoping there is some R package that will let me replicate what I can do in Eviews, and possibly even go beyond what Eviews can do by specifying both AR and MA terms. Thanks in advance for your time, Jude Ryan MarketShare Partners 1270 Avenue of the Americas, Suite # 2702 New York, NY 10020 http://www.marketsharepartners.com Work: (646)-745-9916 ext: 222 Cell: (973)-943-2029 [[alternative HTML version deleted]]
Millo Giovanni
2010-Nov-19 09:22 UTC
[R] R: how do I build panel data/longitudinal data models with AR terms using the plm package or any other package
Hello Jude. Please find my remarks below, with '##' ________________________________ Da: Jude Ryan [mailto:jryan@marketsharepartners.com] Inviato: giovedì 18 novembre 2010 23:52 A: R-help@r-project.org Cc: yves.croissant@univ-reunion.fr; Millo Giovanni Oggetto: how do I build panel data/longitudinal data models with AR terms using the plm package or any other package Hi All, I am doing econometric modeling of panel data (fixed effects). We currently use Eviews to do this, but I have discovered a bug in Eviews 7 and am exploring the use of R to build panel data models / longitudinal data models. I looked at the plm package but do not see how I can incorporate AR terms in the model using the plm package. ## Two possible meanings here: either you want autoregressive y or autoregressive errors 1) y = rho1*y(-1) + rho2*y(-2) + Xb + e or 2) y = Xb + u, u = rho1*u(-1) + rho2*u(-2) 1) is easy: just use lags, like fm <- y ~ lag(y) + lag(y,2) + x but be aware of the Nickell bias: your estimator needs T-asymptotics. I have an Eviews model with two AR terms, AR(1) and AR(2), ## ...then, chances are you want 2) ! all my other remarks below apply to this second case (while 1) would fail for lack of strict endogeneity) and I am trying to replicate that model using R (and SAS too, if possible) as the fitted values in Eviews for panel data (fixed effects) appear to be wrong. In Eviews I tried a second approach and explicitly coded the fixed effects as dummy variables but the standard errors I get are very different from using the panel data options in Eviews, and thus the final model selected could be very different based on these two approaches. Can I incorporate AR terms in a panel data model using the plm package, and if so, how? ## As of now, no. We plan to add feasible AR(1) à la Baltagi, but it won't be tomorrow. This is also because ---> Also, are there any other packages like nlme, lme4, .. that will let me build panel data models / longitudinal data models with AR terms? ## Yes. You can try 'nlme' and its newer sibling 'lme4'. I'm sure it can do random effects + AR(1), and sure you can put in the FEs as dummies; there are probably more elegant solutions but I'm not that familiar with it myself. For an introduction from the econometrician's viewpoint, see here http://www.jstatsoft.org/v27/i02 Ch. 7 Do any of these packages let you build panel data models / longitudinal data models specifying both AR and MA terms? Looking at the ACF and PCAF it seems that some of the error processes are best/more compactly represented by a combination of AR and MA terms, but unfortunately Eviews only lets you use AR terms for panel data and getting rid of the cross-sections in the panel data and building ARIMA models, which let you specify both AR and MA terms for the error process, will mean building separate models for each cross-section. Besides, we do not have that much data to build time series models and panel data methods let us circumvent the limited data issue. ## The issue here is, of course, cross-sectional poolability. The ARMA process in the errors should be the same for each individual. I am confident that you may find something in 'nlme''s rich error covariance structures. If you do, another possibility to get rid of the FEs and use standard methods is using first-difference data (but of course this modifies the errors' covariance specification, and you should reparameterize it). It is my understanding (but I could be wrong) that some of the SAS procs, like HPMIXED, let you specify only one AR term for panel data so I am hoping there is some R package that will let me replicate what I can do in Eviews, and possibly even go beyond what Eviews can do by specifying both AR and MA terms. ## If you're comfortable with ML, you could as well try to write down the likelihood and optimize it. There are facilities in package 'maxLik'. Thanks in advance for your time, Jude Ryan MarketShare Partners 1270 Avenue of the Americas, Suite # 2702 New York, NY 10020 http://www.marketsharepartners.com Work: (646)-745-9916 ext: 222 Cell: (973)-943-2029 ## No ready solutions, sorry. HTH, Giovanni Giovanni Millo Research Dept., Assicurazioni Generali SpA Via Machiavelli 4, 34132 Trieste (Italy) tel. +39 040 671184 fax +39 040 671160 [[alternative HTML version deleted]]