Changing Data Frequency inside Rats Program
Changing Data Frequency inside Rats Program
Dear Tom,
I have the following problem. I am running a VAR in monthly fequency. I want to obtain the structural residuals of one of the equations, which are of course also in monthly frequency. Then I want to aggregate those structural residuals to the quarterly frequency to use them as regressors in a rergession where the dependent variable has the quarterly frequency. I would like to do all of that in one program file. What I basicly want to apply is an identification scheme of Kilian (2009) "Not all oil price shocks are alike: Disentangling Deamand and Supply Shocks in the Crude Oil Market"(Part III).
So is it possible to read in monthly data, then work on it, create quarterly data, then read in a different data set which has a quarterly frequecy and that all within one rpf?
Thank you in advance
Jules
I have the following problem. I am running a VAR in monthly fequency. I want to obtain the structural residuals of one of the equations, which are of course also in monthly frequency. Then I want to aggregate those structural residuals to the quarterly frequency to use them as regressors in a rergession where the dependent variable has the quarterly frequency. I would like to do all of that in one program file. What I basicly want to apply is an identification scheme of Kilian (2009) "Not all oil price shocks are alike: Disentangling Deamand and Supply Shocks in the Crude Oil Market"(Part III).
So is it possible to read in monthly data, then work on it, create quarterly data, then read in a different data set which has a quarterly frequecy and that all within one rpf?
Thank you in advance
Jules
Re: Changing Data Frequency inside Rats Program
Yes. You can do a new CALENDAR instruction at any time. Note that that has no effect on the actual data that's already been created. If you do
cal(m) 1960:1
set test 1 2017:4 = %ran(1.0)
cal(q) 1960:1
then test, which has 688 entries, will now, if you print it, run to 2131:4. So just make sure that you compress anything that you create at monthly frequency that you still need at quarterly. Something like
set qtest 1 2017:1 = (test(3*t)+test(3*t-1)+test(3*t-2))/3.0
will average quarterly average test to qtest.
cal(m) 1960:1
set test 1 2017:4 = %ran(1.0)
cal(q) 1960:1
then test, which has 688 entries, will now, if you print it, run to 2131:4. So just make sure that you compress anything that you create at monthly frequency that you still need at quarterly. Something like
set qtest 1 2017:1 = (test(3*t)+test(3*t-1)+test(3*t-2))/3.0
will average quarterly average test to qtest.
Re: Changing Data Frequency inside Rats Program
Thank you for the help.
In the example below the aggregation method to quarterly data works fine if you take 1960:1 as the start date. But how sould I proceed if I have a different series starting within one quarter and ending within one? For example:
How would I aggregate test2 to the quarterly frequency?
Thank you
Best
Jules
In the example below the aggregation method to quarterly data works fine if you take 1960:1 as the start date. But how sould I proceed if I have a different series starting within one quarter and ending within one? For example:
Code: Select all
cal(m) 2004:2 2016:11
set test 2004:2 2016:11 = %ran(1.0)
set test2 2004:8 2016:11 = test
Thank you
Best
Jules
Re: Changing Data Frequency inside Rats Program
What does that mean? You don't even start with a full quarter.
Re: Changing Data Frequency inside Rats Program
Thats right. What I want to do is to aggegate test2 from the next full quarter onwards to a quarterly series. The next full quarter would be 2004:Q4 and the Last full quarter would be 2016:Q3. How would I do this ? The Thing ist that I have a set of residuals of a monthly regression where the Data Start at 2004:02 and end in 2016:11. The series of residuals, due to the lags in the regression, starts at 2004:08. And I need to Aggregate that series to the quarterly frequency.
Re: Changing Data Frequency inside Rats Program
If you just do what I showed, it will be NA if there isn't a full quarter of data.
Re: Changing Data Frequency inside Rats Program
I am sorry but I am confused...
test2 ranges from 2004:08 to 2016:11. Calender is: cal(m) 2004:2 2016:11.
So do I have to do the following:
cal(m) 2004:1
set test2Q 1 2016:11 = (test2(3*t)+test2(3*t-1)+test2(3*t-2))/3.0
cal(q) 2004:1
Or am I understanding something here completely wrong?
Best Jules
test2 ranges from 2004:08 to 2016:11. Calender is: cal(m) 2004:2 2016:11.
So do I have to do the following:
cal(m) 2004:1
set test2Q 1 2016:11 = (test2(3*t)+test2(3*t-1)+test2(3*t-2))/3.0
cal(q) 2004:1
Or am I understanding something here completely wrong?
Best Jules
Re: Changing Data Frequency inside Rats Program
If you're trying to convert data, you want the two calendar settings to be compatible. Is there any reason you can't use
cal(m) 2004:1
for the monthly values? If you stick with the cal(m) 2004:2, you'll have to adjust the 3*t-xx values to pick out the correct entries for a quarter. With the months and quarters aligned in:
test2(3*t)+test2(3*t-1)+test2(3*t-2)
3*t will pick up months 3,6,9,12,... 3*t-2 will be months 2,5,8,... and 3*t-1 will be 1,4,7,... thus the sum will cover all three months that define a quarter. If the monthly calendar isn't aligned, you'll end up adding up months 2,3 and 4; then 5,6,7, etc.
cal(m) 2004:1
for the monthly values? If you stick with the cal(m) 2004:2, you'll have to adjust the 3*t-xx values to pick out the correct entries for a quarter. With the months and quarters aligned in:
test2(3*t)+test2(3*t-1)+test2(3*t-2)
3*t will pick up months 3,6,9,12,... 3*t-2 will be months 2,5,8,... and 3*t-1 will be 1,4,7,... thus the sum will cover all three months that define a quarter. If the monthly calendar isn't aligned, you'll end up adding up months 2,3 and 4; then 5,6,7, etc.
Re: Changing Data Frequency inside Rats Program
My data start at 2004:02. Thats why I am not using cal(m) 2004:1. Is it possible simply to set cal(m) 2004:1 at the beginning when I am reading in the data, getting an NA for the missing values, then do all the regressions and apply the aggregation method you described without all the complicated adjustments you mentioned by stating "you'll have to adjust the 3*t-xx values to pick out the correct entries for a quarter"?
In case that this doesn't work how would I have to adjust the 3*t-xx values in the test2 example?
The second quarter starts at entry 3 so I would have to use
cal(q) 2004:2
set test2 1 2016:11 = (x(3*t)+x(3*t+1)+x(3*t+2))/3
right?
Thanks a lot for the help
Best
Jules
In case that this doesn't work how would I have to adjust the 3*t-xx values in the test2 example?
The second quarter starts at entry 3 so I would have to use
cal(q) 2004:2
set test2 1 2016:11 = (x(3*t)+x(3*t+1)+x(3*t+2))/3
right?
Thanks a lot for the help
Best
Jules
Re: Changing Data Frequency inside Rats Program
If you have usable dates on the data file, it doesn't matter what you set as the start of the calendar as it will place the data based upon dates on the file, so yes, it would just give you an NA for the 1st element.
Yes. If you go from cal(m) 2004:2 to cal(q) 2004:2, then you want 3*t, 3*t+1 and 3*t+2.
Yes. If you go from cal(m) 2004:2 to cal(q) 2004:2, then you want 3*t, 3*t+1 and 3*t+2.
Re: Changing Data Frequency inside Rats Program
Thanks Tom, it works!
I also don't need "1 2016:11" in "set test2 1 2016:11 = (x(3*t)+x(3*t+1)+x(3*t+2))/3" right`?
Best Jules
I also don't need "1 2016:11" in "set test2 1 2016:11 = (x(3*t)+x(3*t+1)+x(3*t+2))/3" right`?
Best Jules
Re: Changing Data Frequency inside Rats Program
Correct. The range on the SET (by default) is the full workspace length, which will still be the length of the monthly information. So that will compute a bunch of NA's at the end, but will certainly give you all the observations that actually have full data.