For loop with multiple controll variables

For questions regarding programming in the EViews programming language.

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

ed.sc
Posts: 6
Joined: Thu May 29, 2014 7:21 am
Contact:

For loop with multiple controll variables

Postby ed.sc » Wed Sep 10, 2014 9:04 am

Hello,

First of all, I am using EViews 7.2. :D

I have got a question concerning to "For Loops": I know how those loops work and how they can be nested, but I seek for a possibility do write a for-loop which performs a simultaneous update of two or more control variables each iteration. This would mean that with each "next" command both variables update. I give an example:

Code: Select all

for !time=0 to 32 step 4 !AND? !i=1 to 9 step 1 series forecast!i = forecast!time next
The problem is, that if I nest both loops like

Code: Select all

for !time=0 to 32 step 4 for !i=1 to 9 step 1 series forecast!i = forecast!time next next
The result is completely different as you all know: The inner loop performs its tasks for each value of the outer loop. But what I actually whish to do in this simple example is to "rename" forecast0 into forecast1 and forecast4 into forecast2 etc. I want to emphasize that my question is not about how to rename a series, but to find a way that two control variables within a loop update simultaneously.


I would appreciate help very much!

Greetings from Heidelberg, Germany!

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: For loop with multiple controll variables

Postby EViews Gareth » Wed Sep 10, 2014 9:23 am

EViews doesn't have that functionality built in to numerical for loops.

You could do it with a temporary matrix though:

Code: Select all

matrix(9,2) looptemp looptemp.fill 0,4,8,12,16,20,24,28,32,1,2,3,4,5,6,7,8,9 for !j=1 to 9 !time=looptemp(!j,1) !i=looptemp(!j,2) next

ed.sc
Posts: 6
Joined: Thu May 29, 2014 7:21 am
Contact:

Re: For loop with multiple controll variables

Postby ed.sc » Sat Sep 13, 2014 6:08 am

Hello,

thank you for your reply! I will try this.

K


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest