Rolling Covariance

Econometrics questions and discussions

Rolling Covariance

Unread postby Jules89 » Mon Jun 25, 2018 7:57 am

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
Jules89
 
Posts: 140
Joined: Thu Jul 14, 2016 5:32 am

Re: Rolling Covariance

Unread postby TomDoan » Mon Jun 25, 2018 10:55 am

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).
TomDoan
 
Posts: 7388
Joined: Wed Nov 01, 2006 5:36 pm

Re: Rolling Covariance

Unread postby Jules89 » Tue Jun 26, 2018 7:18 am

Thanks Tom,

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


Best Jules
Jules89
 
Posts: 140
Joined: Thu Jul 14, 2016 5:32 am


Return to General Econometrics

Who is online

Users browsing this forum: No registered users and 3 guests