Page 1 of 1

For loop with multiple controll variables

Posted: Wed Sep 10, 2014 9:04 am
by ed.sc
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!

Re: For loop with multiple controll variables

Posted: Wed Sep 10, 2014 9:23 am
by EViews Gareth
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

Re: For loop with multiple controll variables

Posted: Sat Sep 13, 2014 6:08 am
by ed.sc
Hello,

thank you for your reply! I will try this.

K