' set window size 
!window = 60

' set step size
!step = 1

' get size of workfile
!length = @obsrange

' declare equation for estimation
equation Model2

'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)

'vector to store r2s
vector(!nrolls) r2s

'matrix to store coefficient estimates
matrix(!nrolls,6)  betas ' where 6 is the number of coefficients

'matrix to store tstat estimates of coefficient
matrix(!nrolls,6)  tstatistics ' where 6 is the number of coefficients

'matrix to store pvalue estimates of coefficient
matrix(!nrolls,6)  pvalues ' where 6 is the number of coefficients

'Catching start and end points
%start = "@first" '@otod(@ifirst(ser))   
%end = "@last"   '@otod(@ilast(ser))

' 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
   %first = @otod(@dtoo(%start)+!i-1)
   %last = @otod(@dtoo(%start)+!i+!window-2)
   smpl {%first} {%last}

' estimate equation
%cmd = Model2.@command
Model2.{%cmd}

'store r2s in vector
   r2s(!i) = Model2.@r2

'store coefficients in matrix
 rowplace(betas,@transpose(Model2.@coefs),!j)

'store tstats in matrix
 rowplace(tstatistics,@transpose(Model2.@tstats),!j)

'store pvalues in matrix
 rowplace(pvalues,@transpose(Model2.@pvals),!j)

next

show betas
show tstatistics
show pvalues
show r2s


