Re: [R] regression using a lagged dependent variable as explanatory variable

From: Achim Zeileis <>
Date: Sun 16 Oct 2005 - 02:04:10 EST

On Sat, 15 Oct 2005, giacomo moro wrote:

> Hi,
> I would like to regress y (dependent variable) on x (independent variable) and y(-1).
> I have create the y(-1) variable in this way: ly<-lag(y, -1)
> Now if I do the following regression lm (y ~ x + ly) the results I obtain are not correct.

The reason is that lm() itself does not match time series by their time attribute (and apart from the "tsp" attribute x and lag(x, -1) are the same vector). On ?lm there is a description what you could do to create a time series and then apply lm().
As Gabor already wrote, there are two convenience interfaces available in the packages dyn and dynlm.

> Can someone tell me the code to use in R in order to perform a regression using as explanatory variable a lagged dependent variable?
> My best regards,
> Giacomo
> ---------------------------------
> [[alternative HTML version deleted]]
> ______________________________________________
> mailing list
> PLEASE do read the posting guide!
> mailing list PLEASE do read the posting guide! Received on Sun Oct 16 02:22:50 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:55:29 EST