See ?rollapply in the zoo package.
On Thu, May 6, 2010 at 6:20 PM, Dipankar Basu <basu.15 at gmail.com>
wrote:> Hi All,
>
> I am using R 2.11.0 on a Ubuntu machine. I have a time series data set and
> want to run rolling regressions with it. Any suggestions would be useful.
>
> Here are the details:
>
> (1) I convert relevant variables into time series objects and compute first
> differences:
>
> vad <- ts(data$ALLGVA/data$GDPDEF, start=1948, frequency=1)
> emp <- ts(data$ALLEMP, start=1948, frequency=1)
> vad.dif1 <- diff(vad)
> emp.dif1 <- diff(emp)
>
> (2) I make a data set:
>
> d <-
>
ts.union(emp.chng=emp.dif1,lag.emp.chng=lag(emp.dif1,-1),twolag.emp.chng=lag(emp.dif1,-2),
>
>
vad.chng=vad.dif1,lag.vad.chng=lag(vad.dif1,-1),twolag.vad.chng=lag(vad.dif1,-2))
>
> (3) I run regressions:
>
> reg2 <- lm(emp.chng~vad.chng+lag.vad.chng+lag.emp.chng, data=d)
>
> What I would like to do is to run this regression with a 10 year moving
> window. So, the first regression should use data from 1948-58, the second
> from 1949-59 and so on.. the last should use data from 1999-2009. Any
> suggestions?
>
> Deepankar