# How to change the observation for the first lag in an AR(1) model?

I run a simple AR(1) model in my analysis using ols:

ar.ols(df$y, order.max = 1))  However, I work with generations as my unit of analysis. Therefore, the first lag of y would be the observation of y at time t-30. How can I specify this in the AR(1) model in R? ## 1 Answer If $$y_t$$ and $$y_{t-1}$$ are actually 30 observations apart, for AR(1) you can do the following: lm( tail(df$$y,-30) ~ head(df$$y,-30) )  This assumes the first observation is the oldest. If your variable has the first observation being the newest, switch head with tail. This would also imply overlapping observations. For AR(2) you would do lm( tail(df$$y,-60) ~ tail(head(df$$y,-30),-30) + head(df$y,-60) )


If you wish to trade off the added estimation efficiency due to overlapping observations for computational efficiency, you may use every 30th data point as follows:

n=length(df$$y) m=floor(n/30) index=seq(from=n,to=(n-m*30),by=-30) g=df$$y[index] # g contains every 30th observation of y dropping the oldest few
ar.ols(g, order.max = 1)) # for AR(1)
ar.ols(g, order.max = 2)) # for AR(2)

• If I misunderstood your setup, just let me know. Will update. – Richard Hardy Oct 21 at 10:21
• Thank you for your advice. Unfortunately, this does not work, because my dataset has about 100'000 observations and I therefore cannot regress the last 30 on the first 30 observations of y. I would like to set up an AR(I) and in a second step also an AR(II) process by comparing the correlation between an indicator in one generation and the one in the previous generation(s), whereas the generation length is assumed to be 30 years. – R-User Oct 21 at 12:07
• @R-User, note that my code does not regress the last 30 on the first 30. There is a minus sign in front. tail(df$y,-30) drops the first 30, while head(df$y,-30) drops the last 30 observations. I still do not understand the structure of your data: do your have yearly observations but are interested in generations (30 years)? Would looking at every 30th data point be what you are interested in? If so, my proposed code also works and will be slightly more efficient as it utilizes overlapping observations rather than just deleting 29 out of every 30 observations. But you could do that, too. – Richard Hardy Oct 21 at 12:53
• Thanks for the explanation. My datastructure is as follows: I do have yearly data consisting of moving averages over 30 years (e.g. the y of 1915 contains the average y for the generation 1900-1930, etc.). Now the aim is e.g. to regress the y of 1915 on the one of 1885 (as the second one is the average for the generation 1870-1900) in order to find the correlation between the two generations. – R-User Oct 21 at 13:13
• @R-User, then I think my code is just what you need. Alternatively, if you want to avoid overlapping observations and trade off a little bit of precision for computational efficiency, I will include code for that. – Richard Hardy Oct 21 at 13:17