using strings in for loops

For questions regarding programming in the EViews programming language.

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

neilblake
Posts: 21
Joined: Tue Sep 30, 2008 4:19 am

using strings in for loops

Postby neilblake » Wed Oct 01, 2008 5:32 am

Is it possible to use a strip to predefine a list of mnemonics and then to use them in a loop? For example I would like to do something like this:

%country="UK US"

for %c %country
series prod{%c}=gdp{%c}/emp{%c}
next

where %country is a list of country suffixes which I want to use in the loop that starts "for %c...."

This does not work as the command substitutes "UK US" (i.e. in quotation marks) rather than just UK US. Is that a string function that lets you use the contents of the string without the quotation marks? I know this is a trivial example but if I could get it to work it would be very useful for much bigger applications

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

Postby EViews Gareth » Wed Oct 01, 2008 8:05 am

Hi.

Unfortunately not. The only thing I can suggest is that you put the strings in a table, then you can reference them one at a time.

We've made this much easier/better for EViews 7.

neilblake
Posts: 21
Joined: Tue Sep 30, 2008 4:19 am

Postby neilblake » Thu Oct 02, 2008 1:42 am

Thanks. Does EViews 7 have a target release date?

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

Postby EViews Gareth » Thu Oct 02, 2008 7:23 am

Not yet.

oth76
Posts: 4
Joined: Mon Oct 13, 2008 3:22 am

Re: using strings in for loops

Postby oth76 » Mon Oct 13, 2008 3:44 am

I propose as intermediate solution to try this :

for %c UK US
genr prod{%c}=gdp{%c}/emp{%c}
next

I try it, it is OK!

Vladimir_Yorrick
Posts: 16
Joined: Tue Oct 14, 2008 12:40 am

Re: using strings in for loops

Postby Vladimir_Yorrick » Tue Oct 14, 2008 12:57 am

This doesn't answer your question since it doesn't make use of loops but I have been using something like this:

%North_America = "Canada Costa_Ric Cuba Dominican El_Salvad Guatemala Honduras Mexico Nicaragua Panama Trinidad USA"
%South_America = "Argentina Bolivia Brazil Chile Colombia Ecuador Paraguay Peru Uruguay Venezuela"
%EU15 = "Austria Belgium_a Denmark Finland France Germany Greece Ireland Italy Netherlan Portugal Spain Sweden United_Ki"

pool countries
countries.def {%North_America} {%South_America} {%EU15}
countries.genr prod_? = gdp_?/emp_?

prush
Posts: 3
Joined: Tue Jan 06, 2009 2:54 am

Re: using strings in for loops

Postby prush » Tue Jan 06, 2009 4:42 am

Hi.

Unfortunately not. The only thing I can suggest is that you put the strings in a table, then you can reference them one at a time.

We've made this much easier/better for EViews 7.
Hi,

I'm also trying to loop using string variables and have tried constructing a table for them as suggested (simplified version of code below). Unfortunately I am presented with the error:
"simvar is not a series in "genr sim_1=@elem(simvar,1)""
Does this mean that @elem can not be used with tables? Could you please advise as to how to get around this problem?

Thank you


table simvar
simvar(1,1) = "r1"
simvar(2,1) = "rf2"
simvar(3,1) = "r3"
simvar(4,1) = "r4"
simvar(5,1) = "r5"
simvar(6,1) = "r6"
simvar(7,1) = "r7"
simvar(8,1) = "r8"
simvar(9,1) = "r9"
simvar(10,1) = "r10"
simvar(11,1) = "r11"
simvar(12,1) = "r12"

for !i = 1 to 12
genr sim_{!i} = @elem(simvar,{!i})
next

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

Re: using strings in for loops

Postby EViews Gareth » Tue Jan 06, 2009 9:06 am

You are correct; @elem cannot be used with tables. To reference a cell in a table just use parenthesis:

genr sim_!i = simvar(!i,1)

pleiby
Posts: 1
Joined: Mon Oct 10, 2016 12:57 pm

Re: using strings in for loops

Postby pleiby » Thu Dec 15, 2016 8:23 am

This older thread suggest the capability will be added in Eviews 7.
Can anyone please point me to how you can loop over a set of strings in EViews 9?

Thanks
Paul

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

Re: using strings in for loops

Postby EViews Gareth » Thu Dec 15, 2016 8:36 am

You'll have to be more specific - you've always been able to loop over strings.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 0 guests