Transcription of Stata: Software for Statistics and Data Science | Stata
1 Compact table of summary statisticsDescriptionQuick startMenuSyntaxOptionsRemarks and examplesAcknowledgmentsReferenceAlso seeDescriptiontabstatdisplays summary Statistics for a series of numeric variables in one table. It allows youto specify the list of Statistics to be displayed. Statistics can be calculated (conditioned on) substantial flexibility in terms of the Statistics presented and the format ofthe startMean ofv1displayed usingv1 s display formattabstat v1, formatSame as above, but use format with 2 significant digits and a commatabstat v1, format(% )Nonmissing observations, mean, standard error, and coefficient of variation forv1tabstat v1, Statistics (n mean semean cv)Quartiles and interquartile range ofv1andv2tabstat v1 v2, Statistics (q iqr)Same as above, but report Statistics separately for each level ofcatvartabstat v1 v2, by(catvar) Statistics (q iqr)Same as above, but display a separate column for each statistictabstat v1 v2, by(catvar) Statistics (q iqr) columns( Statistics )
2 MenuStatistics>Summaries, tables, and tests>Other tables>Compact table of summary statistics12 tabstat Compact table of summary statisticsSyntaxtabstatvarlist[if][in][w eight][,options]optionsDescriptionMainby (varname)group Statistics by variablestatistics(statname[..])report specified statisticsOptionslabelwidth(#)width forby()variable labels; default islabelwidth(16)varwidth(#)variable width; default isvarwidth(12)columns(variables)display variables in table columns; the defaultcolumns( Statistics )display Statistics in table columnsformat[(%fmt)]display format for Statistics ; default format is% casewise deletion of observationsnototaldo not report overall Statistics ; use withby()missingreport Statistics for missing values ofby()variablenoseparatordo not use separator line betweenby()categorieslongstubmake left table stub widersavestore summary Statistics inr()byis allowed; see [D] andfweights are allowed; see[U] Main by(varname)specifies that the Statistics be displayed separately for each unique value ofvarname;varnamemay be numeric or string.
3 For instance,tabstat heightwould present the overall meanof height, by(sex)would present the mean height of males, and of females,and the overall mean height. Do not confuse theby()option with thebyprefix (see [D]by); bothmay be (statname[..])specifies the Statistics to be displayed; the default is equivalent tospecifyingstatistics(mean). (stats()is a synonym forstatistics().) Multiple statisticsmay be specified and are separated by white space, such asstatistics(mean sd). Availablestatistics aretabstat Compact table of summary Statistics 3statnameDefinitionstatnameDefinitionmea nmeanp11st percentilecountcount of nonmissing observationsp55th percentilensame ascount p1010th percentilesumsump2525th percentilemaxmaximummedianmedian (same asp50)minminimump5050th percentile (same asmedian)rangerange=max min p7575th percentilesdstandard deviationp9090th percentilevariancevariancep9595th percentilecvcoefficient of variation (sd/mean)p9999th percentilesemeanstandard error of mean (sd/ n)iqrinterquartile range=p75 p25skewnessskewnessqequivalent to specifyingp25 p50 p75kurtosiskurtosis Options labelwidth(#)specifies the maximum width to be used within the stub to display the labels of theby()variable.
4 The default islabelwidth(16).8 # (#)specifies the maximum width to be used within the stub to display the names of the vari-ables. The default isvarwidth(12).varwidth()is effective only withcolumns( Statistics ).Settingvarwidth( ) # (variables| Statistics )specifies whether to display variables or Statistics in the columnsof the (variables)is the default when more than one variable is (%fmt)specify how the Statistics are to be formatted. The default is to use a% that each variable s Statistics be formatted with the variable s display format; see[D] (%fmt)specifies the format to be used for all column width is the maximum width of these formats. The minimum column width is ninedisplay casewise deletion of observations. Statistics are to be computed for the samplethat is not missing for any of the variables invarlist.
5 The default is to use all the nonmissingvalues for each for use withby(); it specifies that the overall Statistics not be that missing values of theby()variable be treated just like any other value andthat Statistics should be displayed for them. The default is not to report the Statistics for theby()==missinggroup. If theby()variable is a string variable,by()==""is considered to mean that a separator line between theby()categories not be that the left stub of the table be made wider so that it can include names of thestatistics or variables in addition to the categories ofby(varname). The default is to describe thestatistics or variables in a ignored ifby(varname)is not that the summary Statistics be returned inr(). The overall (unconditional) statisticsare returned in matrixr(StatTotal)(rows are Statistics , columns are variables).
6 The conditionalstatistics are returned in the matricesr(Stat1),r(Stat2),.., and the names of the correspondingvariables are returned in the macrosr(name1),r(name2),..4 tabstat Compact table of summary statisticsRemarks and command is probably most easily understood by going through a series of 1We have data on the price, weight, mileage rating, and repair record of 22 foreign and 52 domestic1978 automobiles. We want to summarize these variables for the different origins of the use (1978 automobile data). tabstat price weight mpg rep78, by(foreign) summary Statistics : MeanGroup variable: foreign (Car origin)foreignprice weight mpg summary Statistics can be requested via thestatistics()option. The group totals can besuppressed with tabstat price weight mpg rep78, by(foreign) stat(mean sd min max) nototalSummary Statistics : Mean, SD, Min, MaxGroup variable: foreign (Car origin)foreignprice weight mpg.
7 8376663291 1800 12 115906 4840 34 .71713723748 1760 14 312990 3420 41 5 Although the header of the table describes the Statistics running vertically in the cells , the tablemay become hard to read, especially with many variables or Statistics . Thelongstuboption specifiesthat a column be added describing the contents of the cells. Theformatoption can be issued tospecify thattabstatdisplay the Statistics by using the display format of the variables rather thanthe overall default% Compact table of summary Statistics 5. tabstat price weight mpg rep78, by(foreign) stat(mean sd min max) long formatforeign Statsprice weight mpg rep78 Domestic Mean6, 3, , .837666 Min3,291 1,800 12 1 Max15,906 4,840 34 5 Foreign Mean6, 2.
8 717137 Min3,748 1,760 14 3 Max12,990 3,420 41 5 Total Mean6, 3, , .989932 Min3,291 1,760 12 1 Max15,906 4,840 41 5We can specify a layout of the table in which the Statistics run horizontally and the variables runvertically by specifying thecol( Statistics ) tabstat price weight mpg rep78, by(foreign) stat(min mean max) col(stat) longforeign VariableMin Mean MaxDomestic price3291 15906weight1800 4840mpg12 34rep781 5 Foreign price3748 12990weight1760 3420mpg14 41rep783 5 Total price3291 15906weight1760 4840mpg12 41rep781 5 Finally,tabstatcan also be used to enhancesummarizeso we can specify the Statistics tobe displayed.
9 For instance, we can display the number of observations, the mean, the coefficient ofvariation, and the 25%, 50%, and 75% quantiles for a list of tabstat price weight mpg rep78, stat(n mean cv q) col(stat)variableN mean cv p25 p50 p75price74 .478406 4195 6342weight74 .2573949 2240 3190 3600mpg74 .2716543 18 20 25rep7869 .290661 3 3 4 Because we did not specify theby()option, these Statistics were not displayed for the subgroupsof the data formed by the categories of theby() tabstat Compact table of summary statisticsVideo exampleDescriptive Statistics in StataAcknowledgmentsThetabstatcommand was written by Jeroen Weesie and Vincent Buskens both of the Departmentof Sociology at Utrecht University, The , S.
10 2018. baselinetable: A command for creating one- and two-way tables of summary Journal18: 327 see[R]summarize summary Statistics [R]table Table of frequencies, summaries, and command results[R]table summary Table of summary Statistics [R]tabulate, summarize() One- and two-way tables of summary Statistics [D] collapse Make dataset of summary Statistics