Stata 11 help for matrix accum

help matrix accum, help matrix glsaccum, help matrix vecaccum, help matrix opaccum -------------------------------------------------------------------------------

Title

[P] matrix accum -- Form cross-product matrices

Syntax

Accumulate cross-product matrices to form X'X

matrix accum A = varlist [if] [in] [weight] [, noconstant deviations means(M)]

Accumulate cross-product matrices to form X'BX

matrix glsaccum A = varlist [if] [in] [weight] , group(groupvar) glsmat(W|stringvar) row(rowvar) [noconstant]

Accumulate cross-product matrices to form sum_over_i[(X_i)'e_i(e_i)'X_i]

matrix opaccum A = [varlist] [if] [in] , group(groupvar) opvar(opvar) [noconstant]

Accumulate first variable against remaining variables

matrix vecaccum a = varlist [if] [in] [weight] [, noconstant]

varlist in matrix accum and in matrix vecaccum may contain factor variables (except for the first variable in matrix vecaccum varlist); see fvvarlist. varlist may contain time-series operators; see tsvarlist. aweights, fweights, iweights, and pweights are allowed; see weight.

Description

matrix accum accumulates cross-product matrices from the data to form A = X'X.

matrix glsaccum accumulates cross-product matrices from the data by using a specified inner weight matrix to form A = X'BX, where B is a block diagonal matrix.

matrix opaccum accumulates cross-product matrices from the data by using an inner weight matrix formed from the outer product of a variable in the data to form

A = X1'e1e1'X1 + X2'e2e2'X2 + ... + Xk'ekek'Xk

where Xi is a matrix of observations from the ith group of the varlist variables and ei is a vector formed from the observations in the ith group of the opvar variable.

matrix vecaccum accumulates the first variable against remaining variables to form a row vector of accumulated inner products to form a = x1'X, where X = (x2, x3,...).

Also see [M-5] cross() for other routines for forming cross-product matrices.

Options

noconstant suppresses the addition of a "constant" to the X matrix. If noconstant is not specified, it is as if a column of 1s is added to X before the accumulation begins.

deviations, allowed only with matrix accum, causes the accumulation to be performed in terms of deviations from the mean. If noconstant is not specified, the accumulation of X is done in terms of deviations, but the added row and column of sums are not in deviation format (in which case they would be zeros). With noconstant specified, the resulting matrix divided through by N-1, where N is the number of observations, is a covariance matrix.

means(M), allowed only with accum, creates matrix M: 1 x (p+1) or 1 x p (depending on whether noconstant is also specified) containing the means of X.

group(groupvar) is required with glsaccum and opaccum and is not allowed otherwise. In the two cases where it is required, it specifies the name of a variable that identifies groups of observations. The data must be sorted by groupvar.

In glsaccum, groupvar identifies the observations to be individually weighted by glsmat().

In opaccum, groupvar identifies the observations to be weighted by the outer product of opvar().

glsmat(W|stringvar), required with glsaccum and not allowed otherwise, specifies the name of the matrix or the name of a string variable in the dataset that contains the name of the matrix that is to be used to weight the observations in group(). stringvar must be str8 or less.

row(rowvar), required with glsaccum and not allowed otherwise, specifies the name of a numeric variable containing the row numbers that specify the row and column of the glsmat() matrix to use in the inner-product calculation.

opvar(opvar), required with opaccum, specifies the variable used to form the vector whose outer product forms the weighting matrix.

Examples

. sysuse auto . matrix accum A = price weight mpg . matrix list A . matrix accum Cov = price weight mpg, deviations noconstant . matrix Cov = Cov/(r(N)-1) . matrix list Cov

. webuse maccumxmpl . xtdescribe, patterns(11) . sort id t . matrix opaccum B = x1 x2, group(id) opvar(e)

Saved results

matrix acum, glsaccum, opaccum, and vecaccum save the number of observations in r(N). glsaccum (with aweights) and vecaccum also store the sum of the weight in r(sum_w), but accum does not.

Also see

Manual: [P] matrix accum

Help: [P] matrix, [R] ml, [M-4] statistical


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