how to get monthly correlation coefficient by daily data

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

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

cklint
Posts: 8
Joined: Wed Jan 12, 2011 8:48 am
Location: birmingham, uk

how to get monthly correlation coefficient by daily data

Postby cklint » Wed Jun 29, 2011 3:25 am

Following examples are my daily interest rates from 2000-01-02 to 2010-01-31.
I like to obtain correlation coefficient between two variable within each month. How should I do? Do I have to make program?

Thanks in advance.

----------------------------------
data(yyyy-mm-dd) us interest rate uk interest rate
2000-01-02 5.56 6.75
2000-01-02 5.89 6.89
'
'
'
2000-01-31 7.56 9.22
2000-02-01 7.42 8.99
'
'
2000-02-28 8.56 10.35
2000-03-01 8.99 10.44
'
'
2010-01-01 3.25 4.22
'
'
'
2010-01-31 3.00 4.00

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

Re: how to get monthly correlation coefficient by daily data

Postby EViews Gareth » Wed Jun 29, 2011 7:49 am

Yes, you'll have to make a program that loops through the months, calculating and storing the coefficient each time.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: how to get monthly correlation coefficient by daily data

Postby EViews Glenn » Thu Jun 30, 2011 9:54 am

Not quite true. I think we can do better. You probably should still make a program, but I think we can avoid the loops.

The following set of commands computes the by-month correlation for the two series and matches them back to the original month in the workfile.

Code: Select all

' set sample to all (I'm assuming that's what you want) smpl @all ' squared deviations from monthly mean series xdev = x - @meansby(x, @year, @month) series ydev = y - @meansby(y, @year, @month) series xydev = xdev * ydev ' covariances series xvar = @varsby(x, @year, @month) series yvar = @varsby(y, @year, @month) series xycov = @meansby(xydev, @year, @month) ' correlations series xycorr = xycov / (@sqrt(xvar)*@sqrt(yvar))
Note that each observation in the workfile has the corresponding value of the correlation in XYCORR. If you want to get just the set of monthy correlations without repeats, we'll have to subset the series XYCORR. The following code gets the first observation of our correlations in each month and exports to a vector:

Code: Select all

series first = (@date = @minsby(@date, @year, @month)) smpl if first = 1 stom(xycorr, corrvec)
My quick check indicates that this works, but you should do some double checking to make sure that it works for you.

cklint
Posts: 8
Joined: Wed Jan 12, 2011 8:48 am
Location: birmingham, uk

Re: how to get monthly correlation coefficient by daily data

Postby cklint » Thu Jul 07, 2011 7:31 am

Thank you very much. It's great. I think that the function of aggregation should be somewhat extended in user-friendly ways.

econworker
Posts: 39
Joined: Thu Apr 24, 2014 3:51 am

Re: how to get monthly correlation coefficient by daily data

Postby econworker » Fri Mar 27, 2015 3:20 am

Would I ask what is the difference of this approach with rolling correlation by movecor command?

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

Re: how to get monthly correlation coefficient by daily data

Postby EViews Gareth » Fri Mar 27, 2015 7:01 am

The movcor command requires a fixed window length. Months do not have a fixed number of days.

econworker
Posts: 39
Joined: Thu Apr 24, 2014 3:51 am

Re: how to get monthly correlation coefficient by daily data

Postby econworker » Mon Apr 13, 2015 7:38 am

The movcor command requires a fixed window length. Months do not have a fixed number of days.
Correct, months dont have fixed number of days, but then is it possible to generate a monthly roling correlation from weekly data (number of weeks are not fixed), that the correlation values of each week dont be fixed for the Whole month?
Thank you

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

Re: how to get monthly correlation coefficient by daily data

Postby EViews Gareth » Mon Apr 13, 2015 8:07 am

I don't understand your question.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 1 guest