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
Loop: get series and do operations on them
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13319
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Loop: get series and do operations on them
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.
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.
Follow us on Twitter @IHSEViews
Re: Loop: get series and do operations on them
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.
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.
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13319
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Loop: get series and do operations on them
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
Follow us on Twitter @IHSEViews
Re: Loop: get series and do operations on them
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.
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13319
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Loop: get series and do operations on them
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...
Follow us on Twitter @IHSEViews
Who is online
Users browsing this forum: No registered users and 15 guests