Recursive sum of series

For questions regarding programming in the EViews programming language.

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

javiersan
Posts: 184
Joined: Mon Jan 19, 2009 8:18 am

Recursive sum of series

Postby javiersan » Tue Mar 24, 2009 10:01 am

Hi,

I want to create a series that sums other series in a workfile and I am unsure about the syntax:

The code underneath does not work but I believe illustrates what I am trying to do:

For %latam arg bra chl col ecu per ury ven
For %abovline curr good serv fact tran
series lat8_{%abovline}_ltm= lat8_{%abovline}_ltm+{%latam}_{%abovline}_ltm
next
next

So that I obtain:
lat8_curr_ltm=arg_curr_ltm+bra_curr_ltm+chl_curr_ltm+...

Any suggestions will be appreciated.

Regards,

Javier

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

Re: Recursive sum of series

Postby EViews Gareth » Tue Mar 24, 2009 10:25 am

A quick look indicates that your code should work, although, of course, you'd have to set the output series equal to zero before the loop starts.

javiersan
Posts: 184
Joined: Mon Jan 19, 2009 8:18 am

Re: Recursive sum of series

Postby javiersan » Tue Mar 24, 2009 10:38 am

That was it! Thanks.

Javier

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Recursive sum of series

Postby EViews Glenn » Tue Mar 24, 2009 10:47 am

Slightly off-topic note for instructional purposes. A slightly different approach uses the @rsum

Code: Select all

For %aboveline curr good serv fact tran %names = "" For %latam arg bra chl col ecu per ury ven %names = %names + " " + %latam +"_" + %aboveline + "_ltm" next group {%aboveline} {%names} series {%aboveline}_sum = @rsum({%aboveline}) delete {%aboveline} next
This may be useful if you wish to do something slightly more complicated like computing the means or variances across the series.

javiersan
Posts: 184
Joined: Mon Jan 19, 2009 8:18 am

Re: Recursive sum of series

Postby javiersan » Tue Mar 24, 2009 4:40 pm

Thanks a lot. That code is really useful.

Regards,

Javier


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests