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" <[email protected]>
To   <[email protected]>
Subject   st: Precision problem with running sums in Mata
Date   Wed, 17 Aug 2005 15:41:28 +0200

Hi,

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()-).

Thanks,
ben






--------------------------
Swiss Federal Institute 
of Technology Zurich (ETH)
Sociology
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
[email protected]
http://www.socio.ethz.ch/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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