[R] MA process in panels

Philipp Grueber philipp.grueber at ebs.edu
Tue Mar 20 17:53:48 CET 2012

Dear R users,

I have an unbalanced panel with an average of I=100 individuals and a total
of T=1370 time intervals, i.e. T>>I. So far, I have been using the plm

I wish to estimate a FE model like:

res<-plm(x~c+v, data=pdata_frame, effect="twoways", model="within",

…where c varies over i and t, and v represents an exogenous impact on x
varying over time but not over i. I discover significant time effects
comparing the above model with a plm(…,effect="individual", …)-model (using

I discover high levels of serial correlation in the errors. Including lags
of x, coefficients are significant at least put to 30 lags. If I set my
dataset to weekly observations (approx. 5 days = 1 week), the coefficients
of the lags are significant at least up to the 15th lag (I didn't test a
larger number of lags). The more lags I include, the less sections can be
included in my sample (the panel is unbalanced, i.e. data is not available
for the whole period for all individuals -- in fact, full data is available
for only few individuals).  

Checking the acf() and pacf() of x, I find that for the large majority of
individuals, x is an MA() process. That's plausible because it would explain
the high levels of autocorrelation. However, I do not know a lot about MA
models for panel data.  

Most books I have found so far only touch on MA processes in panels but do
not discuss the estimation problems and implementation in further details.
Therefore, I have the following questions:

1) Are there any issues specific to panel models with an MA component? 

2) Is there an implementation for panel MA models in R?

3) If not, I have thought about the following solution. Does this approach
provide correct/ reliable results?


#Unfortunately, I was unable to create an appropriate panel dataset with an
MA process in the residuals. Maybe someone has an idea where to find such
data? Nevertheless you should be able to follow my subsequent thoughts:

# I should be able to get my (time- and sectionally) demeaned series as

res1<-plm(x~c+v,data=pdata_frame, effect="twoways", model="within",

# Given the demeaned series, I need to set the first observation(s) in each
cross-section to NA in order to avoid inter-sectional links in the lagged
residuals (i.e. in the MA component).
#Note: Delete the first n observations per section for a MA(n) regression.
For me, an MA(1) process should be fine (I hope):

for ( i in unique(pdata_frame$i)){

#I think I should now be able to use standard ARIMA methods such as 


#Alternatively, I tried to obtain res2 using maxLik() from the maxLik
package, but I am not sure about how to specify the log-likelihood function: 

tslag <- function(x, d=l)
  x <- as.vector(x)
  n <- length(x)

log_Lik<-function(param) {
ll<- -0.5*N*log(2*pi) - N*log(sigma) -
sum(0.5*(dem_yt-(b1*demXt[,1]+b2*demXt[,2]) +


Am I on the right track? Is there an easier way to do this? Did I miss
something important?

Any help is appreciated, thanks a lot in advance!


Philipp Grueber
EBS Universitaet fuer Wirtschaft und Recht
Wiesbaden, Germany

EBS Universitaet fuer Wirtschaft und Recht
FARE Department
Wiesbaden/ Germany
View this message in context: http://r.789695.n4.nabble.com/MA-process-in-panels-tp4489528p4489528.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list