Page 1 of 1

Loop in procedure

Posted: Sat Oct 13, 2012 4:15 pm
by paretto
Dear Tom,

I do want to implement a loop in a procedure which expands the estimation period by one month.
This is the simple procedure:

procedure taymodel series1 series2 series3 series4 series5 ibegin iend
type series series1 series2 series3 series4 series5
type int ibegin iend

do iend = firstob,iend
linreg(print) series2 firstob iend outge
#constant trend trend2
comp outget(iend)= outge(iend)
end do iend

end unit

But each time I try to pass series to the procedure I receive the error:

## SX23. Expected Variable/Element of Type INTEGER, Got Expression Instead
>>>>do iend = <<<<

There are apparentley problems with the loop, when I switch off the loop the error message disappears.
Whats wrong with the procedure, uisng the code in the main programm and not in the procedure works well.

Thanks a lot in advamce

Re: Loop in procedure

Posted: Sun Oct 14, 2012 10:01 am
by TomDoan
You're using IEND two different ways. It looks like it's the end of your sample, but you're also using it as the loop index. You get the message because a parameter like the IEND from the procedure parameter list is, in effect, a constant within the procedure, so you can't reset it. You need to use some other (local) variable for the loop index:

procedure taymodel series1 series2 series3 series4 series5 ibegin iend
type series series1 series2 series3 series4 series5
type int ibegin iend
local integer thisend

do thisend = firstob,iend
linreg(print) series2 firstob thisend outge
#constant trend trend2
comp outget(thisend)= outge(thisend)
end do iend

end unit

(BTW, did you mean IBEGIN rather than FIRSTOB?)