Page 1 of 1

2 For Loops Operating Simultaneously

Posted: Thu Nov 13, 2014 7:29 am
by davey87
Hello,

I have the following code:

Code: Select all

for !j=1 to 89 for !i=0 to 88 for %g f m series nm{%g}{!j} nm{%g}{!j}=p{%g}{!j}-(p{%g}{!i}(-1)-d{%g}{!j}) nm{%g}{!j}.setformat f.0 next next next
As it runs now, the !i loop is treated as nested, however I want both the !i and !j loops to run simultaneously. Is there a way to do this in EViews 8?

If not, do you have any suggestions at how to get around this problem?

Thanks,

Dave

Re: 2 For Loops Operating Simultaneously

Posted: Thu Nov 13, 2014 8:52 am
by EViews Gareth
I'm not 100% sure I follow, but...

Code: Select all

for !j=1 to 89 !i = !j-1 for %g f m series nm{%g}{!j} nm{%g}{!j}=p{%g}{!j}-(p{%g}{!i}(-1)-d{%g}{!j}) nm{%g}{!j}.setformat f.0 next next
?

Re: 2 For Loops Operating Simultaneously

Posted: Thu Nov 13, 2014 10:16 am
by davey87
Thanks! That seem to work. I also found an alternative solution from a previous forum post, which uses a temporary matrix:

Code: Select all

matrix (89,2) looptemp looptemp.fill 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88 for !j=1 to 89 for %g f m series nm{%g}{!j} !age=looptemp(!j,1) !agelag=looptemp(!j,2) nm{%g}{!age}=p{%g}{!age}-(p{%g}{!agelag}(-1)-d{%g}{!age}) nm{%g}{!age}.setformat f.0 next next