Hi,
I am trying to get a program that loops multiple rolling regressions and saves some of the results in matrixes. My sample is composed of multiple series (the larger sample is over 5000 series and the smallest one composed of 1353 series) each series contains a maximum of 82 observations (some have data missing at the beginning, some at the end, some on both the beginning and the end). The frequency of my data is monthly(the series in the work file are so defined. The equation I am using is a standard ls regression similar to this one : series(x) c proxy1 proxy2 proxy3
What I would like the program to achieve is to run for each series, a rolling regression (using the equation above) on the previous 36 observations (1 to 36, 2 to 37, etc...) so a maximum of 46 regressions per series (missing observations might not allow for some the regressions to be computed).
Furthermore i would like the coefficients for each of the regressions to be saved in a matrix as well as the r2. If possible I would like one matrix for each coefficient (one for r2, one for c, one for proxy1, etc), that matrix containing that same coefficient for each regression in each series. So a total of 5 matrixes.
I picked up a rolling regression basic program which I changed to my window size and equation. It works when used on complete series (without missing observations, series num100 to num109 for example), but stops as soon as I encounter a series with missing data.
My problems are multiple:
1.)how can I get the program to keep on going after encoutering missing data which made that particular regression impossible.
2.)Is it possible to save each coefficient separately and in one matrix (one matrix per coefficient and that matrix would include that particular coefficient for each series and rolling regression)
3.)This problem is similar to the previous one but for r2 as with my program so far it always saves them in the first column of the matrix, therefore erasing the previous results.
I have uploaded the work file I use for the smaller sample of 1353 series as well as my program thus far.
I am using Eviews 7.1
I hope I was comprehensible and thank you in advance for you answer.
Amaury
looped rolling regression
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: looped rolling regression
This should get you on the right track:
Code: Select all
matrix(46, 1353) r2
matrix(46, 1353) coef1
matrix(46, 1353) coef2
matrix(46, 1353) coef3
matrix(46, 1353) coef4
for !k = 1 to 1353
statusline rolling series num{!k}
!window = 36
!step = 1
!lenght = @obsrange
equation eq{!k}
!nrolls = @round ((!lenght-!window)/!step)
' matrix (4,!nrolls) coefs{!k}
!rowcounter = 1
!j = 0
for !i = 1 to !lenght - !window +1-!step step !step
!j = !j+1
smpl @first+!i-1 @first+!i + !window - 2
if @obs(num{!k}) > 5 then
eq{!k}.ls num{!k} c big_proxy hy_proxy def_proxy
r2(!rowcounter) = eq{!k}. @r2
!rowcounter = !rowcounter+1
'colplace(coefs{!k}, eq{!k}. @coefs, !j)
coef1(!j,!k) = eq{!k}.@coef(1)
coef2(!j,!k) = eq{!k}.@coef(2)
coef3(!j,!k) = eq{!k}.@coef(3)
coef4(!j,!k) = eq{!k}.@coef(4)
endif
next
next
Re: looped rolling regression
Thank you Garteh it works perfectly, except for the R2.
The program runs on the complete sample without interruption and I get the 4 matrixes for the coefficients but the R2 matrix still only has one column with of 46 r2 so I don t get them for each equation the program ran.
EDIT: OK,
I added this line : r2(!j,!k) = eq{!k}.@r2
after the coefficients placement in their respective matrixes and it seems to be working.
Thanks again!
The program runs on the complete sample without interruption and I get the 4 matrixes for the coefficients but the R2 matrix still only has one column with of 46 r2 so I don t get them for each equation the program ran.
EDIT: OK,
I added this line : r2(!j,!k) = eq{!k}.@r2
after the coefficients placement in their respective matrixes and it seems to be working.
Thanks again!
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: looped rolling regression
Yeah, I didn't do the R2 bit, figuring you'd be able to figure it out :D
Who is online
Users browsing this forum: No registered users and 2 guests
