help mata runningsum()
-------------------------------------------------------------------------------
Title
[M-5] runningsum() -- Running sum of vector
Syntax
numeric vector runningsum(numeric vector x [, missing])
numeric vector quadrunningsum(numeric vector x [, missing])
void _runningsum(y, numeric vector x [, missing])
void _quadrunningsum(y, numeric vector x [, missing])
where optional argument missing is a real scalar that determines how
missing values in x are treated:
1. Specifying missing as 0 is equivalent to not specifying the
argument; missing values in x are treated as contributing 0 to
the sum.
2. Specifying missing as 1 specifies that missing values in x are to
be treated as missing values and turn the sum to missing.
Description
runningsum(x) returns a vector of the same dimension as x containing the
running sum of x. Missing values are treated as contributing zero to the
sum.
runningsum(x, missing) does the same but lets you specify how missing
values are treated. runningsum(x, 0) is the same as runningsum(x).
runningsum(x, 1) specifies that missing values are to turn the sum to
missing where they occur.
quadrunningsum(x) and quadrunningsum(x, missing) do the same but perform
the accumulation in quad precision.
_runningsum(y, x [, missing]) and _quadrunningsum(y, x [, missing]) work
the same way, except that rather than returning the running-sum vector,
they store the result in y. This method is slightly more efficient when
y is a view.
Remarks
The running sum of (1, 2, 3) is (1, 3, 6).
All functions return the same type as the argument, real if argument is
real, complex if complex.
Conformability
runningsum(x, missing), quadrunningsum(x, missing):
x: r x 1 or 1 x c
missing: 1 x 1 (optional)
result: r x 1 or 1 x c
_runningsum(y, x, missing), _quadrunningsum(y, x, missing):
input:
x: r x 1 or 1 x c
y r x 1 or 1 x c (contents irrelevant)
missing: 1 x 1 (optional)
output:
y: r x 1 or 1 x c
Diagnostics
If missing = 0, missing values are treated as contributing zero to the
sum; they do not turn the sum to missing. Otherwise, missing values turn
the sum to missing.
_runningsum(y, x, missing) and _quadrunningsum(y, x, missing) abort with
error if y is not p-conformable with x and of the same eltype. The
contents of y are irrelevant.
Source code
Functions are built in.
Also see
Manual: [M-5] runningsum()
Help: [M-5] sum(); [M-4] mathematical, [M-4] utility