help for statsmat

Produce matrix of descriptive statistics

statsmat varlist [if exp] [in range] [weight] [ , stat(list_of_statistics) matrix(matname) by(byvar) missing xpose listwise magic(#) matlist_options ]


statsmat computes descriptive statistics for varlist and places them in any specified matrix matname. By default, the statistics are minimum, quartiles, maximum, mean and standard deviation: these and/or other statistics returned by summarize, or easily computable from what it returns, may be specified. The statistics are by default computed for those observations which are non-missing across the varlist. aweights and fweights may be specified.


stat(list_of_statistics) specifies the statistics desired, from the following list:

one of statistic ------ --------- n N count number of non-missing observations sum sum sum_w sum of weight mean mean sd SD standard deviation Var var variance se SE semean standard error of the mean skew skewness skewness kurt kurtosis kurtosis min minimum max maximum p percentiles 1, 5, 10, 25, 50, 75, 90, 95, 99 q percentiles 25, 50, 75 (quartiles) p1 1st percentile p5 5th percentile p10 10th percentile p25 25th percentile p50 med median 50th percentile (median) p75 75th percentile p90 90th percentile p95 95th percentile p99 99th percentile iqr IQR interquartile range (p75 - p25) range range (max - min) zero 0 0 (filler if desired for later editing) extra . . (filler if desired for later editing) (Stata 8 up)

matrix(matname) specifies the name of a matrix in which statistics are to be placed. This option is not required, but saving results in a matrix is the main rationale for statsmat.

by(byvar) is allowed only with a single varname in varlist. Results are given separately for the groups of observations defined by distinct values of byvar, which is usually a categorical variable.

missing specifies that results should also be produced for those observations for which byvar is missing. The default is to omit them.

matlist_options are those allowed with matrix list. See matrix.

xpose specifies transposing the matrix from the default, with statistics as columns, to statistics as rows.

listwise specifies that statistics are to be shown for all non-missing values in each variable.

magic(#) specifies a number to be used to denote statistics that are missing. In Stata 7, matrices may not contain missing numbers: in statsmat, as in tabstat, the number 1e+300 is, by default, used instead. In Stata 8 and 9, missing values are shown by default, but magic() may be used to over-ride that if desired. Other numbers may be specified: for example, if all results shown will be zero or positive, magic(-999) might be convenient. The strong presumption is that at some point downstream users will edit such numbers to denote missing explicitly.


. use auto

. statsmat price mpg rep78, mat(out1)

. statsmat price mpg rep78, mat(out2) s(mean sd p50)

. statsmat price mpg rep78 if foreign, mat(out3)

. statsmat price mpg rep78, mat(out4) s(mean sd skew kurt) f(%3.2f)

. statsmat price, by(rep78) f(%9.0f) s(n min q max)

. outtable using myout4, mat(out4) replace


Nicholas J. Cox, Durham University, U.K. n.j.cox@durham.ac.uk

Christopher F Baum, Boston College, USA baum@bc.edu


Petia Petrova inspired this program.

Also see

On-line: summarize, matrix, tabstat, outtable (if installed), univar (if installed)