Loop: get series and do operations on them

For questions regarding programming in the EViews programming language.

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

Danxxx
Posts: 11
Joined: Mon Jun 07, 2010 10:06 am

Loop: get series and do operations on them

Postby Danxxx » 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

EViews Gareth
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

Postby EViews Gareth » Mon Jun 14, 2010 8:01 am

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.
Follow us on Twitter @IHSEViews

Danxxx
Posts: 11
Joined: Mon Jun 07, 2010 10:06 am

Re: Loop: get series and do operations on them

Postby Danxxx » Mon Jun 14, 2010 10:52 am

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.

EViews Gareth
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

Postby EViews Gareth » Mon Jun 14, 2010 11:01 am

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

Danxxx
Posts: 11
Joined: Mon Jun 07, 2010 10:06 am

Re: Loop: get series and do operations on them

Postby Danxxx » Thu Jun 17, 2010 12:28 pm

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.

EViews Gareth
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

Postby EViews Gareth » Thu Jun 17, 2010 1:36 pm

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

bcchen
Posts: 31
Joined: Tue May 02, 2017 8:34 am

Re: Loop: get series and do operations on them

Postby bcchen » Thu Jun 01, 2017 4:20 pm

THANKS!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 15 guests