I have been creating lags for zoo objects using the following econ$gdp4 <- lag(econ$gdp, k = -4, na.pad = TRUE). I have about 6 columns in econ object that I want to create lags for and I want to create lags for periods 1 through 9. Is there a way to use a loop to create these?
I have been creating lags for zoo objects using the following econ$gdp4 <- lag(econ$gdp,
Share
Suppose z is our zoo object. Lets say we want 9 lags for each of columns 2, 3, 4 as well as all columns of the original. Then try:
Also note that a lag of 0 gives back the same column so this gives the original as well as 9 lags of each column: