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
using strings in for loops
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: using strings in for loops
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!
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
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_?
%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
Hi,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.
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
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)
genr sim_!i = simvar(!i,1)
Re: using strings in for loops
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
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
You'll have to be more specific - you've always been able to loop over strings.
Who is online
Users browsing this forum: No registered users and 0 guests
