Time Series Regression in R
The dynlm
package is probably the easiest option for adding lagged variables to a regression in R. The workhorse regression function lm
is a general regression function, accommodating all kinds of data, so working with lagged variables can be a hassle.
Suppose you want to estimate a bivariate VAR model of x and y, with three lags of each variable. You could do that using dynlm
like this:
library(dynlm)
dynlm(y ~ L(x, 1:3) + L(y, 1:3))
dynlm(x ~ L(x, 1:3) + L(y, 1:3))
You can click here for a more detailed example
⤺ Back to the List of Computing Posts