Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Precision problem with running sums in Mata

From   "Jann Ben" <>
To   <>
Subject   st: Precision problem with running sums in Mata
Date   Wed, 17 Aug 2005 15:41:28 +0200


I would like to create the running sum from a real vector
in Mata. My first try to create the running sum vector was

 : R = C
 : for (i=2; i<=rows(R); i++) R[i] = R[i-1] + R[i]

where C is a column vector. Unfortunately, the result from 
the above code is not precise enough in my application. My 
second try was 

 : R = J(rows(C),1,.)
 : for (i=2; i<=rows(R); i++) R[i] = quadsum(C[|1 \ i|])

which, in fact, produces accurate results. However, this 
version of the code is rather slow.

My question: Does anyone have a better idea how to create 
accurate running sums in an efficient way? Can 
-quadcross()- somehow be used for this purpose?

I think it would be nice if official Mata had built-in 
functions for creating running sums (e.g. -quadrunsum()-).


Swiss Federal Institute 
of Technology Zurich (ETH)
ETH Zentrum SEW E 28
CH-8092 Zurich

Ben Jann, lic. rer. soc.
Scheuchzerstrasse 70
Tel. +41 1 632 55 58
Fax  +41 1 632 10 54

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index