help mata mm_variance0()
-------------------------------------------------------------------------------

Title

mm_variance0() -- Population variance

Syntax

real matrix mm_variance0(X, w)

real matrix mm_meanvariance0(X, w)

where

X: real matrix X (rows are observations, columns variables)

w: real colvector w

Description

mm_variance0(X, w) returns the population variance matrix of X. mm_variance0() differs from official Stata's variance() (see help for mean()) in that it divides the deviation cross products by N instead of N-1, where N is the number of observations. Essentially,

mm_variance0(X, w) = variance(X, w) * (N-1)/N

However, mm_variance0() also produces correct results if N==1.

mm_meanvariance0(X, w) returns mean(X,w)\mm_variance0(X,w).

w specifies the weight. Specify w as 1 to obtain unweighted results. Rows of X or w that contain missing values are omitted from the calculation, which amounts to casewise deletion.

Remarks

None.

Conformability

mm_variance0(X, w), X: n x k w: n x 1 or 1 x 1 result: k x k

mm_meanvariance0(X, w), X: n x k w: n x 1 or 1 x 1 result: (k+1) x k

Diagnostics

The functions omit from the calculation rows that contain missing values unless all rows contain missing values. Then the returned result contains all missing values.

Source code

mm_variance0.mata, mm_meanvariance0.mata

Author

Ben Jann, ETH Zurich, jann@soz.gess.ethz.ch

Also see

Online: help for [M-5] mean(), moremata