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
running a sequence over subperiods
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
-
- EViews Developer
- Posts: 564
- Joined: Thu Apr 25, 2013 7:48 pm
Re: running a sequence over subperiods
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:
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:
Further simplifications are possible if the sample strings and associated indices are related to one another, but that depends on code not shown.
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
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
%specs = "1 " + @str(!d-1) + " " + @str(!d) + " " + @str(!n)
Thanks
-
- EViews Developer
- Posts: 564
- Joined: Thu Apr 25, 2013 7:48 pm
Re: running a sequence over subperiods
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
Who is online
Users browsing this forum: No registered users and 26 guests