Page 1 of 1

Syntax error in nested loops

Posted: Mon May 09, 2016 11:20 am
by JRMeyer
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.

Re: Syntax error in nested loops

Posted: Mon May 09, 2016 12:34 pm
by EViews Gareth
Try:

Code: Select all

%name = "g_stshare_" + %s

Re: Syntax error in nested loops

Posted: Mon May 09, 2016 1:20 pm
by JRMeyer
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!