Rolling Covariance

Econometrics questions and discussions
Jules89
Posts: 140
Joined: Thu Jul 14, 2016 5:32 am

Rolling Covariance

Unread post by Jules89 »

Dear Tom,

I have a very simple prolem. When I have two series x and y, how can I calculate a rolling covariance between the two.
For example I want to calculate cov(x(t),y(t)) for t=1,...,20. Then I want to calculate cov(x(t),y(t)) for t=2,...,21 and so on. Then I want to save the covariance for later calculation within each iteration of the loop.

The cross instruction works well for printing the values, but I don't know how to safe the values. My code is

start = some date
end = some date +20

Code: Select all

do i = 0, 1813

   cross(from=0, to=0,covariances,results=cov) x y start+i end+i

end do i
Thank you

best jules
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Rolling Covariance

Unread post by TomDoan »

That's a rather short window, isn't it?

At any rate, the bookkeeping for rolling window analyses is largely the same regardless of what you're computing. See rollingcausality.rpf and the handling of causetests series. In your case, the statistic that you want to save on each trip through is cov(1).
Jules89
Posts: 140
Joined: Thu Jul 14, 2016 5:32 am

Re: Rolling Covariance

Unread post by Jules89 »

Thanks Tom,

cov(1) was the command I was serching for.


Best Jules
Post Reply