Page 1 of 1

Recursive sum of series

Posted: Tue Mar 24, 2009 10:01 am
by javiersan
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

Re: Recursive sum of series

Posted: Tue Mar 24, 2009 10:25 am
by EViews Gareth
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.

Re: Recursive sum of series

Posted: Tue Mar 24, 2009 10:38 am
by javiersan
That was it! Thanks.

Javier

Re: Recursive sum of series

Posted: Tue Mar 24, 2009 10:47 am
by EViews Glenn
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.

Re: Recursive sum of series

Posted: Tue Mar 24, 2009 4:40 pm
by javiersan
Thanks a lot. That code is really useful.

Regards,

Javier