running a sequence over subperiods

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

remuct
Posts: 27
Joined: Fri May 12, 2017 6:47 am

running a sequence over subperiods

Postby remuct » Fri Jul 07, 2023 5:20 am

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

EViews Matt
EViews Developer
Posts: 564
Joined: Thu Apr 25, 2013 7:48 pm

Re: running a sequence over subperiods

Postby EViews Matt » Mon Jul 10, 2023 9:40 am

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.

remuct
Posts: 27
Joined: Fri May 12, 2017 6:47 am

Re: running a sequence over subperiods

Postby remuct » Mon Jul 10, 2023 2:54 pm

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

EViews Matt
EViews Developer
Posts: 564
Joined: Thu Apr 25, 2013 7:48 pm

Re: running a sequence over subperiods

Postby EViews Matt » Mon Jul 10, 2023 4:59 pm

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


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 26 guests