program for a system with iterative leas squares
Posted: Sat Mar 28, 2015 3:13 pm
Hi,
I'm trying to writte a program to do rolling regression with iterative least squares in the following system of equations:
U=C(1) + C(2)*U(-1) + C(3)*U(-2)
W= C(4) +C(5)*INF(-1)+C(9)*U+C(9)*0.99 *C(3)*U(-1)
I wrote the following program that does not provide the right results:
' set window size
!window = 60
!step = 1
!length = @obsrange
equation eq1
equation eq2
!nrolls = @round((!length-!window)/!step)
'matrix to store coefficient estimates
matrix(3,!nrolls) coefmat1 ' where 3 is the number of coefficients
matrix(3,!nrolls) sdmat1
matrix(3,!nrolls) tmat1
matrix(3,!nrolls) coefmat2 ' where 3 is the number of coefficients
matrix(3,!nrolls) sdmat2
matrix(3,!nrolls) tmat2
!j=0
for !i = 5 to !length-!window+1-!step step !step
!j=!j+1
smpl @first+!i-1 @first+!i+!window-2
eq1.ls(DERIV=AA) U=C(1) + C(2)*U(-1) + C(3)*U(-2)
eq2.ls(DERIV=AA) W= C(4) +C(5)*INF(-1)+C(9)*U+C(9)*0.99*C(3)*U(-1)
colplace(coefmat1,eq1.@coefs,!j)
colplace(sdmat1,eq1.@stderrs,!j)
colplace(tmat1,eq1.@tstats,!j)
' colplace(coefmat2,eq2.@coefs,!j)
' colplace(sdmat2,eq2.@stderrs,!j)
'colplace(tmat2,eq2.@tstats,!j)
next
show coefmat1
'show coefmat2
I get to run this program but the stored coefficients are not the "iteractive" coefficients.
I wonder if someone could help me writting such a program. Thank you
I'm trying to writte a program to do rolling regression with iterative least squares in the following system of equations:
U=C(1) + C(2)*U(-1) + C(3)*U(-2)
W= C(4) +C(5)*INF(-1)+C(9)*U+C(9)*0.99 *C(3)*U(-1)
I wrote the following program that does not provide the right results:
' set window size
!window = 60
!step = 1
!length = @obsrange
equation eq1
equation eq2
!nrolls = @round((!length-!window)/!step)
'matrix to store coefficient estimates
matrix(3,!nrolls) coefmat1 ' where 3 is the number of coefficients
matrix(3,!nrolls) sdmat1
matrix(3,!nrolls) tmat1
matrix(3,!nrolls) coefmat2 ' where 3 is the number of coefficients
matrix(3,!nrolls) sdmat2
matrix(3,!nrolls) tmat2
!j=0
for !i = 5 to !length-!window+1-!step step !step
!j=!j+1
smpl @first+!i-1 @first+!i+!window-2
eq1.ls(DERIV=AA) U=C(1) + C(2)*U(-1) + C(3)*U(-2)
eq2.ls(DERIV=AA) W= C(4) +C(5)*INF(-1)+C(9)*U+C(9)*0.99*C(3)*U(-1)
colplace(coefmat1,eq1.@coefs,!j)
colplace(sdmat1,eq1.@stderrs,!j)
colplace(tmat1,eq1.@tstats,!j)
' colplace(coefmat2,eq2.@coefs,!j)
' colplace(sdmat2,eq2.@stderrs,!j)
'colplace(tmat2,eq2.@tstats,!j)
next
show coefmat1
'show coefmat2
I get to run this program but the stored coefficients are not the "iteractive" coefficients.
I wonder if someone could help me writting such a program. Thank you