Page 1 of 1

running a sequence over subperiods

Posted: Fri Jul 07, 2023 5:20 am
by remuct
Hi, I want to run over two subperiods [1, !d-1] and [!d, !n] defined as the strings subp1 and subp2, the SAME list of instructions where a time increment !i is used. One way of doing this is :

smpl {subp1}
for !i=1 to !d-1
list of instructions
next
smpl {subp2}
for !i=!d to !n
list of instructions
next

There is surely a shorter way of programming this without repeating the list of instructions. Is there?
Thanks

Re: running a sequence over subperiods

Posted: Mon Jul 10, 2023 9:40 am
by EViews Matt
Hello,

There are a couple of ways you could eliminate the redundancy in your program. You could move the common code to a subroutine, after which your program would look something like this:

Code: Select all

subroutine foo list of instructions endsub smpl {subp1} for !i=1 to !d-1 call foo next smpl {subp2} for !i=!d to !n call foo next
You'd need to work about appropriate parameters for the subroutine and double-check that it still generates all the correct side effects.

Alternatively, you could employ an additional loop over the two sets of specifications, (subp1, 1, !d-1) and (subp2, !d, !n), a la:

Code: Select all

%specs = "subp1 1 " + @str(!d-1) + " subp2 " + @str(!d) + " " + @str(!n) for %smpl %start %end {%specs} smpl {{%smpl}} for !i=%start to %end list of instructions next next
Further simplifications are possible if the sample strings and associated indices are related to one another, but that depends on code not shown.

Re: running a sequence over subperiods

Posted: Mon Jul 10, 2023 2:54 pm
by remuct
Thank you so much, the second way was the kind of approach I was seeking. If I do that way, am I obliged to give a name to each sub-period, here subp1 and subp2, since these names do not appear anywhere in the program, therefore seem not to be useful? That is, can I write the first sentence as:

%specs = "1 " + @str(!d-1) + " " + @str(!d) + " " + @str(!n)

Thanks

Re: running a sequence over subperiods

Posted: Mon Jul 10, 2023 4:59 pm
by EViews Matt
Certainly, with the appropriate downstream changes:

Code: Select all

%specs = "1 " + @str(!d-1) + " " + @str(!d) + " " + @str(!n) for %start %end {%specs} smpl %start %end ' Only needed if the 'list of instructions' includes operations affected by the sample for !i=%start to %end list of instructions next next