2 For Loops Operating Simultaneously

For questions regarding programming in the EViews programming language.

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

davey87
Posts: 24
Joined: Tue Feb 05, 2013 12:18 pm

2 For Loops Operating Simultaneously

Postby davey87 » Thu Nov 13, 2014 7:29 am

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

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

Re: 2 For Loops Operating Simultaneously

Postby EViews Gareth » Thu Nov 13, 2014 8:52 am

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
?

davey87
Posts: 24
Joined: Tue Feb 05, 2013 12:18 pm

Re: 2 For Loops Operating Simultaneously

Postby davey87 » Thu Nov 13, 2014 10:16 am

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


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests