Page 1 of 1

using strings in for loops

Posted: Wed Oct 01, 2008 5:32 am
by neilblake
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

Posted: Wed Oct 01, 2008 8:05 am
by EViews Gareth
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.

Posted: Thu Oct 02, 2008 1:42 am
by neilblake
Thanks. Does EViews 7 have a target release date?

Posted: Thu Oct 02, 2008 7:23 am
by EViews Gareth
Not yet.

Re: using strings in for loops

Posted: Mon Oct 13, 2008 3:44 am
by oth76
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!

Re: using strings in for loops

Posted: Tue Oct 14, 2008 12:57 am
by Vladimir_Yorrick
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_?

Re: using strings in for loops

Posted: Tue Jan 06, 2009 4:42 am
by prush
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

Re: using strings in for loops

Posted: Tue Jan 06, 2009 9:06 am
by EViews Gareth
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)

Re: using strings in for loops

Posted: Thu Dec 15, 2016 8:23 am
by pleiby
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

Re: using strings in for loops

Posted: Thu Dec 15, 2016 8:36 am
by EViews Gareth
You'll have to be more specific - you've always been able to loop over strings.