Syntax error in nested loops

For questions regarding programming in the EViews programming language.

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

JRMeyer
Posts: 4
Joined: Mon May 09, 2016 10:50 am

Syntax error in nested loops

Postby JRMeyer » Mon May 09, 2016 11:20 am

Good day.
I have been trying to edit some data series in a set of nested "For" loops. I wish to copy data from a specified date through to the end of the sample. Some of the data series in the groups are 'NA', which is not a problem for me. The code I am using is as follows:

Code: Select all

For !k = 1 to !NBasins ' For each of the Basins %S = basin_id(!K) ' Grab the Kth ID %Z = final_date(!k) ' Identify the date of the final element in the series %name = "g_stshare_{%s}" ' For each grouped set of state shares For !i=1 to {%name}.@count ' For each column series in the group %st = {%name}.@seriesname(!i) ' Get the series' name {%st}.fill(s) @elem({%st}, {%Z} ) ' Fill the series with the observation corresponding to the final date Next ' Go to the next column in the group Next ' Go to the next Basin
Essentially I am looping through several groups (called "Basins"), each of which has between 1 and 9 data series. I have established a vector "Final_Date" that identifies the last date for which any data is present in the group. I wish to then copy the values at that date (@elem(series, Final_Date)) to all the remaining months of my sample.

When I run the program I am confronted with the error message "Syntax error in control statement in "Next"". I have browsed through the forum boards & stared in stupefaction for an absurdly long time at my code, without enlightenment. Would anybody be able to tell me what I have done incorrectly?

Thank you.

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

Re: Syntax error in nested loops

Postby EViews Gareth » Mon May 09, 2016 12:34 pm

Try:

Code: Select all

%name = "g_stshare_" + %s

JRMeyer
Posts: 4
Joined: Mon May 09, 2016 10:50 am

Re: Syntax error in nested loops

Postby JRMeyer » Mon May 09, 2016 1:20 pm

Thanks Gareth! That resolves the syntax error, and then confronts me with the fact that none of the series have actually been filled with the expected (or any) values. I was thinking of trying @recode, but the fill command seems more in keeping with my original intent. Any thoughts?

Edit: Never mind, I found it. I just needed to use fill(s,L) instead of just fill(s), so that it looped through all the remaining months. Thanks for your assistance!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests