Double Loop within rolling regression
Posted: Thu Mar 06, 2014 4:54 pm
Hi,
I have been through the rolling regression forum and the common response thread that deals with pulling "things" out of objects to place elsewhere.
I am trying to run 2 Quandt-Andrews test for every regression in the loop @ .10 trimming and another @.49 trimming. esesentially a double loop within a loop (well i think thats the only way to do it).
I can get the value out of the table and into "Table s" but in the next loop the following saved data overwrites the previous. I want to make it so that it save on line 1,3,5,7,9...... for all .10 trimmings and each subsequent even line (2,4,6....) for .49 trimming.
example in the table
sample 1 120 .10 results
sample 1 120 .49 results
sample 2 121 .10 results
sample 2 121 .49 results
I know i need a variable that cunts the amount of equations ran but because i have one already and the way I have constructed my for loops i am just running in circles.
Thank you
this is what i have:
'run rolling regression
' set window size
!window =120
' set step size
!step =1
' get size of workfile
!length = @obsrange
' declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'table to hold each grab from the frozen table
table s
'variable keeping track of how many rolls we've done
!j=0
' move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
' set sample to estimation period
smpl @first+!i-1 @first+!i+!window-2
' estimate equation
eq1.ls y c x1 x2
for !c=0 to 5 step 2
!h=!c+1
eq1.ubreak 10 @ c
freeze(tab) eq1.ubreak 10 @ c 'freeze table
s(!h,5)=@val(tab(11,2)) 'deposit contents at (11,2) into table s
s(!h,6)=@val(tab(11,4)) 'deposit contents at (11,2) into table s
tab.copyrange a4 a4 s a!h }
tab.copyrange a5 a5 s b!h } ' these are all non numerical data to be stored in the table and the copyrange function is the easiest way i know how
tab.copyrange a2 a2 s c!h }
tab.copyrange a11 a11 s d!h }
d tab
next
for !k=1 to 5 step 2
!r=!k
eq1.ubreak 49 @ c
freeze(tab1) eq1.ubreak 49 @ c
s(!r,5)=@val(tab1(11,2))
s(!r,6)=@val(tab1(11,4))
tab1.copyrange a4 a4 s a!r
tab1.copyrange a5 a5 s b!r
tab1.copyrange a2 a2 s c!r
tab1.copyrange a11 a11 s d!r
d tab1
next
next
thanks in advance
I have been through the rolling regression forum and the common response thread that deals with pulling "things" out of objects to place elsewhere.
I am trying to run 2 Quandt-Andrews test for every regression in the loop @ .10 trimming and another @.49 trimming. esesentially a double loop within a loop (well i think thats the only way to do it).
I can get the value out of the table and into "Table s" but in the next loop the following saved data overwrites the previous. I want to make it so that it save on line 1,3,5,7,9...... for all .10 trimmings and each subsequent even line (2,4,6....) for .49 trimming.
example in the table
sample 1 120 .10 results
sample 1 120 .49 results
sample 2 121 .10 results
sample 2 121 .49 results
I know i need a variable that cunts the amount of equations ran but because i have one already and the way I have constructed my for loops i am just running in circles.
Thank you
this is what i have:
'run rolling regression
' set window size
!window =120
' set step size
!step =1
' get size of workfile
!length = @obsrange
' declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'table to hold each grab from the frozen table
table s
'variable keeping track of how many rolls we've done
!j=0
' move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
' set sample to estimation period
smpl @first+!i-1 @first+!i+!window-2
' estimate equation
eq1.ls y c x1 x2
for !c=0 to 5 step 2
!h=!c+1
eq1.ubreak 10 @ c
freeze(tab) eq1.ubreak 10 @ c 'freeze table
s(!h,5)=@val(tab(11,2)) 'deposit contents at (11,2) into table s
s(!h,6)=@val(tab(11,4)) 'deposit contents at (11,2) into table s
tab.copyrange a4 a4 s a!h }
tab.copyrange a5 a5 s b!h } ' these are all non numerical data to be stored in the table and the copyrange function is the easiest way i know how
tab.copyrange a2 a2 s c!h }
tab.copyrange a11 a11 s d!h }
d tab
next
for !k=1 to 5 step 2
!r=!k
eq1.ubreak 49 @ c
freeze(tab1) eq1.ubreak 49 @ c
s(!r,5)=@val(tab1(11,2))
s(!r,6)=@val(tab1(11,4))
tab1.copyrange a4 a4 s a!r
tab1.copyrange a5 a5 s b!r
tab1.copyrange a2 a2 s c!r
tab1.copyrange a11 a11 s d!r
d tab1
next
next
thanks in advance