This one might be a little easier to follow for programming beginners though.

Code: Select all

`'create some data`

create u 800

series y=nrnd

series x1=nrnd

series x2=nrnd

series z=nrnd

'-------------------------------------------------------------------------------------

'run rolling regression

' set window size

!window = 750

' set step size

!step = 40

' get size of workfile

!length = @obsrange

' declare equation for estimation

equation eq1

'calculate number of rolls

!nrolls = @round((!length-!window)/!step)

'matrix to store coefficient estimates

matrix(3,!nrolls) coefmat ' where 3 is the number of coefficients

'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 - where the equation is y=c(1) + c(2)*x1 + c(3)*x2

eq1.ls y c x1 x2

'store coefficients

colplace(coefmat,eq1.@coefs,!j)

next

show coefmat