Control Variables already defined in nested FOR loop

For questions regarding programming in the EViews programming language.

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

Dave_the_Forecaster
Posts: 16
Joined: Fri Aug 16, 2013 1:52 am

Control Variables already defined in nested FOR loop

Postby Dave_the_Forecaster » Wed Oct 30, 2013 3:32 am

Hi, sorry if someone has posted a topic about this already. I've written the following loop:

Code: Select all

%series_list = "econ1 econ2 econ3" For %portfolio port1 port2 port3 For %model test1 test2 test3 test4 %temp= "%" + %portfolio + "_" + %model wfopen {%temp} %current_wf1=@wfname For %series {%series_list} Pageselect New_Port if @isobject(%series)=1 then copy(overwrite) {%current_wf1}::New_Port\{%series} {%wf1_name}::Economics\{%series}_{%portfolio}_{%model} else statusline %series does not exist in workfile %temp endif next wfuse {%current_wf1} wfclose next next
where port1_test1 etc are pre-defined string variables containing the file name and path of previously saved workfiles.

The problem I'm having is that when the code runs the final iteration of the 3rd loop, it tries to run it again, replacing the control variable %series with econ3 and so the program falls over.

I've tried resetting %series="" at the end of the loop but that causes a similar error.

Hope I've explained my problem well. Any ideas??

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

Re: Control Variables already defined in nested FOR loop

Postby EViews Gareth » Wed Oct 30, 2013 8:12 am

I cannot see anything particularly wrong with the loop structure. Indeed a simple test of the loop structure seems to indicate it is fine:

Code: Select all

create u 10 table a !i = 1 %series_list = "econ1 econ2 econ3" For %portfolio port1 port2 port3 For %model test1 test2 test3 test4 %temp= "%" + %portfolio + "_" + %model For %series {%series_list} a(!i,1) = %portfolio a(!i,2) = %model a(!i,3) = %series !i = !i+1 next next next


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests