mm_variance0() -- Population variance
real matrix mm_variance0(X, w)
real matrix mm_meanvariance0(X, w)
X: real matrix X (rows are observations, columns variables)
w: real colvector w
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.
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
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.
Ben Jann, ETH Zurich, email@example.com
Online: help for [M-5] mean(), moremata