Nesting loops

For questions regarding programming in the EViews programming language.

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

ecardamone
Posts: 40
Joined: Wed Sep 17, 2014 12:23 pm

Nesting loops

Postby ecardamone » Wed Oct 15, 2014 2:00 pm

Hi,

I think I am trying to nest loops, but not successfully :(

This is a simplified version of what I have:
%x = "rd"
%z = "go"

for %j tot p
q_us{%z}{%j}_{%x}.label(S) BEA
for %k gdp private
q_US{%z}{%j}_{%x}.displayname US, GO $2009, {%k}
next
next

Ultimately, I want the label 'source' (S) for 'tot' and 'p' to be the same, but the display name should differ - 'tot' should correspond to 'gdp' and 'p' to 'private'. However, when I run this, 'private' shows up as the display name for both.

Can someone help, please? Thanks!!

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

Re: Nesting loops

Postby EViews Gareth » Wed Oct 15, 2014 2:29 pm

You can't do what you want with two loops.

I think I would do it this way:

Code: Select all

%x = "rd" %z = "go" %js = "tot p" %dnames = "gdp private" for !j = 1 to @wcount(%js) %j = @word(%js,!j) %k = @word(%dnames, !j) q_us{%z}{%j}_{%x}.label(S) BEA q_US{%z}{%j}_{%x}.displayname US, GO $2009, {%k} next

ecardamone
Posts: 40
Joined: Wed Sep 17, 2014 12:23 pm

Re: Nesting loops

Postby ecardamone » Thu Oct 16, 2014 6:07 am

Thank you, Gareth! You are a genius!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest