Page 1 of 1

Loop: get series and do operations on them

Posted: Mon Jun 14, 2010 7:25 am
by Danxxx
Hi,

I have lots of series that I have to: copy in from various workfiles, change their names, and multiply them by a number. There will be hundreds of series.

So I set up a string with all the info, used @wsplit to make it into a string vector, then used control variables to work through it (see below for three series).
I'm just wondering: a) is there a limit to the size of the string, and b) is there a better way to do this?

PS: Is there a continuation character I can use within a string so I can wrap it like so:
"wf_intl Q001sdm worldgdp 0.001
wf_usa Q111xp2f realexp 1
wf_mf S03Q allman 10 "

I tried _ but that didn't work.



'Program to collect data, change name, and multiply by a factor
wfcreate wf_all Q 1990 2010
string sallinfo = _
"wf_intl Q001sdm worldgdp 0.001 wf_usa Q111xp2f realexp 1 wf_mf S03Q allman 10 "
svector vallinfo
vallinfo = @wsplit(sallinfo)
scalar numobs = @rows(vallinfo)
scalar numrows = numobs/4
for !i = 1 to numrows
!j = 4*!i - 3
%sourcefile = vallinfo(!j)
%sourcename = vallinfo(!j+ 1)
%newname=vallinfo(!j+2)
%mult = vallinfo(!j+3)
copy {%sourcefile}::{%sourcename}
rename {%sourcename} {%newname}
series {%newname} = {%newname} * {%mult}
next

Re: Loop: get series and do operations on them

Posted: Mon Jun 14, 2010 8:01 am
by EViews Gareth
I'm not sure on the size limit of a string (if there is one). Seems to me the way you're doing it is fine.

You don't necessarily need to put them into an svector, you could just leave them in the string and use the @word function to loop through them.

Re: Loop: get series and do operations on them

Posted: Mon Jun 14, 2010 10:52 am
by Danxxx
Thanks, I didn't know about @word

I'm still trying to arrange the big string in a user-friendly way (i.e. in rows, one for each series).
It appears there is no continuation character for word wrapping a string. So I'll probably do something like this:

string sallinfo = ""
sallinfo = sallinfo + " " + "wf_intl Q001sdm worldgdp 0.001"
sallinfo = sallinfo + " " + "wf_usa Q111xp2f realexp 1 "
sallinfo = sallinfo + " " + "wf_mf S03Q allman 10 "


It looks better in fixed font, with all the spaces intact; you get four columns so it's easy to see what's what.

Re: Loop: get series and do operations on them

Posted: Mon Jun 14, 2010 11:01 am
by EViews Gareth
Could you contemplate having 4 separate strings, one for each of the information types? Then your parsing code could look something like:

Code: Select all

for !i=1 to @wcount(%sfiles) %sourcefile = @word(%sfiles,!i) %sourcename = @word(%snames,!i) %newname = @word(%nnames,!i) %mult = @word(%mults,!i) next

Re: Loop: get series and do operations on them

Posted: Thu Jun 17, 2010 12:28 pm
by Danxxx
All the source info (~100 series) must be entered by hand. So I just wanted an easy format in the program file so a person can see the workfile, sername etc. next to each other.

Re: Loop: get series and do operations on them

Posted: Thu Jun 17, 2010 1:36 pm
by EViews Gareth
Well, a slightly better way would be:

Code: Select all

string sallinfo = "wf_intl Q001sdm worldgdp 0.001" + " " + _ "wf_usa Q111xp2f realexp 1 " + " " + _ "wf_mf S03Q allman 10 " + " " + _ etc...

Re: Loop: get series and do operations on them

Posted: Thu Jun 01, 2017 4:20 pm
by bcchen
THANKS!