Rolling window correlation

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator

randomlearning
Posts: 8
Joined: Thu Jun 03, 2010 5:28 am

Rolling window correlation

Postby randomlearning » Thu Jun 03, 2010 5:47 am

Hi everyone.

This is my first post in this forum and I am already asking questions. :)

I have two series X, Y, and Z and each one of them has 50 yearly observations. I would like to create a 5-year rolling window for the correlation coefficient for all the possible combinations, but I am struggling with it (I know, I am a newbie...).

I have read this thread, but it seems that that will give me a backward correlation (at each point the statistic give us only the previous 10 years) and I want to use five years of data both before and after. Hope this is clear.

Thanks in advance! :D

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13317
Joined: Tue Sep 16, 2008 5:38 pm

Re: Rolling window correlation

Postby EViews Gareth » Thu Jun 03, 2010 8:00 am

Just put a lead on your series.

i.e.

Code: Select all

@movcor(x(2),y(2),5)
Follow us on Twitter @IHSEViews

randomlearning
Posts: 8
Joined: Thu Jun 03, 2010 5:28 am

Re: Rolling window correlation

Postby randomlearning » Thu Jun 03, 2010 12:23 pm

EViews Gareth wrote:Just put a lead on your series.

i.e.

Code: Select all

@movcor(x(2),y(2),5)


Thanks for your answer. :)

Isn't that leading both series? I guess I don't get how leading both series will give me at each point the correlation for both five years after and before.

Thanks once again.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13317
Joined: Tue Sep 16, 2008 5:38 pm

Rolling window correlation

Postby EViews Gareth » Thu Jun 03, 2010 12:55 pm

Sorry, misunderstood. Put a lead of 5 years on both.
Follow us on Twitter @IHSEViews

randomlearning
Posts: 8
Joined: Thu Jun 03, 2010 5:28 am

Re: Rolling window correlation

Postby randomlearning » Thu Jun 03, 2010 1:37 pm

Thanks, but still is not working. Even when I use this:

Code: Select all

@movcor(x(5),y(5),10)


It does not give me the correct values (I'm checking with another software). For once, by leading the variable, I am getting rid of the first observations so that does not work.

Maybe this example will clarify what I want: Suppose (annual data) X={x1,x2,x3,x4,x5,x6} and Y={y1,y2,y3,y4,y5,y6} and suppose that I want a two year rolling window (two years before and two years after each observation). Therefore, the series should be Correlation={NA, NA, corr({x1,x2,x3,x4,x5},{y1,y2,y3,y4,y5}), corr({x2,x3,x4,x5,x6},{y2,y3,y4,y5,y6}),NA,NA})}

Please, let me know if you need a numeric example.

Thanks.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13317
Joined: Tue Sep 16, 2008 5:38 pm

Re: Rolling window correlation

Postby EViews Gareth » Thu Jun 03, 2010 3:29 pm

Did you check the EViews numbers manually? They seem to work for me:

Code: Select all

create u 6
rndseed 1
series y=rnd
series x=rnd
group g x y


series corr = @movcor(y(2),x(2),5)

'check by making two matrices from the middle two parts, and calculating the correlations
smpl 1 5
matrix s1 = @convert(g)
freeze(cor1) s1.cor

smpl 2 6
matrix s2 = @convert(g)
freeze(cor2) s2.cor
Follow us on Twitter @IHSEViews

randomlearning
Posts: 8
Joined: Thu Jun 03, 2010 5:28 am

Re: Rolling window correlation

Postby randomlearning » Fri Jun 04, 2010 5:37 am

Isn't working for me...

Can I post the series that I'm trying to work with as well as the result I'm getting and I `correct' one?

Thanks.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13317
Joined: Tue Sep 16, 2008 5:38 pm

Rolling window correlation

Postby EViews Gareth » Fri Jun 04, 2010 7:19 am

Sure
Follow us on Twitter @IHSEViews

randomlearning
Posts: 8
Joined: Thu Jun 03, 2010 5:28 am

Re: Rolling window correlation

Postby randomlearning » Fri Jun 04, 2010 8:36 am

You were right. I used @movcor(y(alpha),x(alpha),2*alpha+1) where alpha is the size of the window and it worked.

Thanks! :)

damenic
Posts: 1
Joined: Sat Dec 04, 2010 4:35 am

Re: Rolling window correlation

Postby damenic » Thu Dec 16, 2010 6:35 am

Does anybody know how to calculate rolling window correlation for even number of years?
thanks.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 30 guests