Loop: get series and do operations on them
Posted: Mon Jun 14, 2010 7:25 am
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
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