[R] What is the best way to lag a time series?

Christian Schoder schoc152 at newschool.edu
Sun Dec 26 08:49:00 CET 2010


Dear R-users,

I've been using R for a while and I am very satisfied! Unfortunately, I
still have not figured out an efficient and general way to construct and
use lags of time series, especially when I need to work with different
packages. 

Let me give an example. I have two time series x and y and I want to
estimate a variaty of distributed lags models and run different tests
(autocorrelation, etc). It is obvious that I need to be able to lag x
and y in a flexible way. So far, my temporary solution was to construct
the lags manually (x1,..,xn and y1,..,yn) in a spreadsheet and import it
to R, which is not very satisfactory because it does not allow for much
flexibility.  

Is there a straighforward command which allows me to easily construct a
lag when required and which allows me to, for example, use the lm()
command to fit a dynamic model and the bgtest() command to perform the
breusch-godfrey test on the same model? 

Is it adviseable to use time series objects which consist of many time
series (like a dataframe) or is it better to have it contain only one
time series? 

I would be grateful for any hints and links.

Thx!
Christian



More information about the R-help mailing list