[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Precision problem with running sums in Mata
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
Ben Jann, lic. rer. soc.
Tel. +41 1 632 55 58
Fax +41 1 632 10 54
* For searches and help try: