{smcl} {* 27sept2004}{...} {hline} help for {hi:moments} {hline} {title:Moment-based statistics} {p 8 17 2}{cmd:moments} [{it:varlist}] [{cmd:if} {it:exp}] [{cmd:in} {it:range}] [{it:weight}] [{cmd:,} {cmdab:all:obs} {cmdab:f:ormat(}{it:numeric_format(s)}{cmd:)} {cmdab:m:atname(}{it:matrix_name}{cmd:)} {it:tabdisp_options} {cmd:variablenames} ] {p 8 17 2}{cmd:moments} {it:varname} [{cmd:if} {it:exp}] [{cmd:in} {it:range}] [{it:weight}] [{cmd:,} {cmdab:all:obs} {cmd:by(}{it:varlist}{cmd:)} {cmdab:f:ormat(}{it:numeric_format(s)}{cmd:)} {cmdab:m:atname(}{it:matrix_name}{cmd:)} {it:tabdisp_options} ] {p 4 4 2}{cmd:by ... :} may be used with {cmd:moments}: see help on {help by}. {p 4 4 2} {cmd:aweight}s and {cmd:fweight}s are allowed; see help {help weights}. {title:Description} {p 4 4 2}{cmd:moments} calculates mean, standard deviation, skewness and kurtosis for {it:varlist}. Any string variables in {it:varlist} are ignored. {title:Options} {p 4 8 2}{cmd:allobs} specifies use of the maximum possible number of observations for each variable. The default is to use only those observations for which all variables in {it:varlist} are not missing. {p 4 8 2}{cmd:by()} specifies one or more variables defining distinct groups for which moment-based statistics should be calculated. {cmd:by()} is allowed only with a single {it:varname}. The choice between {cmd:by:} and {cmd:by()} is one of precisely what kind of output display is required. The display with {cmd:by:} is clearly structured by groups while that with {cmd:by()} is more compact. To show moments for several variables and several groups with a single call to {cmd:moments}, the display with {cmd:by:} is essential. {p 4 8 2}{cmd:format()} controls the display format of mean, standard deviation, skewness and kurtosis, as follows. Up to four numeric formats may be given. The first numeric format given controls the display of the mean; any second numeric format that of the standard deviation; any third numeric format that of the skewness, and any fourth numeric format that of the kurtosis. Formats not specified default to {cmd:%9.3f}. {p 4 8 2}{cmd:matname()} specifies the name of a matrix in which to save the results of (the last set of) calculations. There will be 5 columns. The columns will contain n, mean, standard deviation, skewness and kurtosis. {p 4 8 2}{it:tabdisp_options} are options of {help tabdisp} other than {cmd:format()}. {p 4 8 2}{cmd:variablenames} specifies that the variable names of {it:varlist} should be used in display. The default is to use variable labels to indicate a set of variables. {title:Examples} {p 4 8 2}{cmd:. moments} {p 4 8 2}{cmd:. moments price-foreign}{p_end} {p 4 8 2}{cmd:. moments price-foreign, format(%5.1f %5.1f)} {p 4 8 2}{cmd:. bysort rep78: moments mpg} {title:Author} {p 4 4 2}Nicholas J. Cox, University of Durham, U.K.{break} n.j.cox@durham.ac.uk {title:Also see} {p 4 13 2}help for {help summarize}, help for {help tabstat}