Change certain characters of a series name within a loop

For questions regarding programming in the EViews programming language.

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

Young
Posts: 8
Joined: Wed Aug 13, 2014 7:46 am

Change certain characters of a series name within a loop

Postby Young » Tue Aug 19, 2014 6:18 am

Hello

I have a set of tickers that are constructed from a country code, a category identifier, and several "markers" that indicate various operations that should be performed on the ticker (seasonally adjust, frequency conversion, etc.). A typical ticker is thus aud_emp_0_1_0_0

Here I perform x12 seasonal adjustment on all series in the workfile depending on whether the value in position 11 of the series name is 0 (no seasonal adjustment needed) or 1 (seasonal adjustment needed). First I have to limit the sample to dates without NAs. After adjustment, I want to change the value of position 11 to 0 for all the series that went through the adjustment. the x12 process appends "_sa" to the name of each variable that is adjusted.

I tried to break down the ticker into its components, and then substitute the correct component "0" in position 11 (which in the code below is %iname4). I have tried "@replace" and a bunch of other options but either they are not the right choice or I don't have the syntax correct.

From the error messages it seems clear that there is nothing in the variables %iname1, %iname2, etc. because the code creates variables with the correct number of underscores and a 0 (as in "___0___").

group sa
%END=@DATESTR(@NOW)
%list=@wlookup("*","series")
for %j {%list}
%first = {%j}.@first
if %j <>na then
series {%j} =@recode({%j}=na,{%j}(-1),{%j})
endif
smpl %first %end
if @mid(%j,11,1)=1 then
{%j}.x12
%iname1=@left(%j_sa,3)
%iname2=@mid(%j_sa,5,3)
%iname3=@mid(%j_sa,9,1)
%iname4=@mid(%j_sa,11,1)
%iname5=@mid(%j_sa,13,1)
%iname6=@mid(%j_sa,15,1)
%iname7=@mid(%j_sa,17,2)
rename {%j}_sa {%iname1}_{%iname2}_{%iname3}_0_{%iname5}_{%iname6}_{%iname7}
else
series {%j}_sa={%j}
endif
sa.add {%j}_sa
next

If I add curly braces in the %iname1 etc definitions (as here):

%iname1=@left({%j}_sa,3)

The error message is

aud_emp_0_1_0_0_sa cannot be converted to a string in %iname1=@left(aud_emp_0_1_0_0_sa,3)

Experimenting with @str did not help

Any help would be much appreciated.

Thank you

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

Re: Change certain characters of a series name within a loop

Postby EViews Gareth » Tue Aug 19, 2014 8:07 am

You need to use strings inside all of your @left/@mid functions.

Young
Posts: 8
Joined: Wed Aug 13, 2014 7:46 am

Re: Change certain characters of a series name within a loop

Postby Young » Tue Aug 19, 2014 11:00 am

lurched through it but got it, thanks.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests