help mata sum()
-------------------------------------------------------------------------------
Title
[M-5] sum() -- Sums
Syntax
numeric colvector rowsum(numeric matrix Z [, missing])
numeric rowvector colsum(numeric matrix Z [, missing])
numeric scalar sum(numeric matrix Z [, missing])
numeric colvector quadrowsum(numeric matrix Z [, missing])
numeric rowvector quadcolsum(numeric matrix Z [, missing])
numeric scalar quadsum(numeric matrix Z [, missing])
where optional argument missing is a real scalar that determines how
missing values in Z are treated:
1. Specifying missing as 0 is equivalent to not specifying the
argument; missing values in Z are treated as contributing 0 to
the sum.
2. Specifying missing as 1 (or nonzero) specifies that missing
values in Z are to be treated as missing values and to turn the
sum to missing.
Description
rowsum(Z) and rowsum(Z, missing) return a column vector containing the
sum over the rows of Z.
colsum(Z) and colsum(Z, missing) return a row vector containing the sum
over the columns of Z.
sum(Z) and sum(Z, missing) return a scalar containing the sum over the
rows and columns of Z.
quadrowsum(), quadcolsum(), and quadsum() are quad-precision variants of
the above functions. The sum is accumulated in quad precision and then
rounded to double precision and returned.
Argument missing determines how missing values are treated. If missing
is not specified, results are the same as if missing=0 were specified:
missing values are treated as zero. If missing=1 is specified, missing
values are treated as missing values.
These functions may be used with real or complex matrix Z.
Remarks
All functions return the same type as the argument, real if argument is
real, complex if complex.
Conformability
rowsum(Z, missing), quadrowsum(Z, missing):
Z: r x c
missing: 1 x 1 (optional)
result: r x 1
colsum(Z, missing), quadcolsum(Z, missing):
Z: r x c
missing: 1 x 1 (optional)
result: 1 x c
sum(Z, missing), quadsum(Z, missing):
Z: r x c
missing: 1 x 1 (optional)
result: 1 x 1
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.
Source code
Functions are built in.
Also see
Manual: [M-5] sum()
Help: [M-5] mean(), [M-5] runningsum(), [M-5] cross(); [M-4]
mathematical, [M-4] utility