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
how to get monthly correlation coefficient by daily data
Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason
-
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
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
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.
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:
My quick check indicates that this works, but you should do some double checking to make sure that it works for you.
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))
Code: Select all
series first = (@date = @minsby(@date, @year, @month))
smpl if first = 1
stom(xycorr, corrvec)
Re: how to get monthly correlation coefficient by daily data
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
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
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
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?The movcor command requires a fixed window length. Months do not have a fixed number of days.
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
I don't understand your question.
Who is online
Users browsing this forum: No registered users and 1 guest
