help table dialog: table
-------------------------------------------------------------------------------
Title
[R] table -- Tables of summary statistics
Syntax
table rowvar [colvar [supercolvar]] [if] [in] [weight] [, options]
options description
-------------------------------------------------------------------------
Main
contents(clist) contents of table cells; select up to five
statistics; default is contents(freq)
by(superrowvarlist) superrow variables
Options
cellwidth(#) cell width
csepwidth(#) column-separation width
stubwidth(#) stub width
scsepwidth(#) supercolumn-separation width
center center-align table cells; default is right-align
left left-align table cells; default is right-align
cw perform casewise deletion
row add row totals
col add column totals
scol add supercolumn totals
concise suppress rows with all missing entries
missing show missing statistics with period
replace replace current data with table statistics
name(string) name new variables with prefix string
format(%fmt) display format for numbers in cells; default is
format(%9.0g)
-------------------------------------------------------------------------
by is allowed; see [D] by.
fweights, aweights, iweights, and pweights are allowed; see weight.
pweights may not be used with sd, semean, sebinomial, or sepoisson.
iweights may not be used with semean, sebinomial, or sepoisson.
aweights may not be used with sebinomial or sepoisson.
where elements of clist may be
freq frequency
mean varname mean of varname
sd varname standard deviation
semean varname standard error of the mean (sd/sqrt(n))
sebinomial varname standard error of the mean, binomial distribution
(sqrt(p(1-p)/n))
sepoisson varname standard error of the mean, Poisson distribution
(sqrt(mean))
sum varname sum
rawsum varname sums ignoring optionally specified weight
count varname count of nonmissing observations
n varname same as count
max varname maximum
min varname minimum
median varname median
p1 varname 1st percentile
p2 varname 2nd percentile
... 3rd-49th percentile
p50 varname 50th percentile (median)
... 51st-97th percentile
p98 varname 98th percentile
p99 varname 99th percentile
iqr varname interquartile range
Menu
Statistics > Summaries, tables, and tests > Tables > Table of summary
statistics (table)
Description
table calculates and displays tables of statistics.
Options
+------+
----+ Main +-------------------------------------------------------------
contents(clist) specifies the contents of the table's cells; if not
specified, contents(freq) is used by default. contents(freq)
produces a table of frequencies. contents(mean mpg) produces a table
of the means of the variable mpg. contents(freq mean mpg sd mpg)
produces a table of frequencies together with the mean and standard
deviation of variable mpg. Up to five statistics may be specified.
by(superrowvarlist) specifies that numeric or string variables be treated
as superrows. Up to four variables may be specified in
superrowvarlist. The by() option may be specified with the by
prefix.
+---------+
----+ Options +----------------------------------------------------------
cellwidth(#) specifies the width of the cell in units of digit widths; 10
means the space occupied by 10 digits, which is 0123456789. The
default cellwidth() is not a fixed number, but a number chosen by
table to spread the table out while presenting a reasonable number of
columns across the page.
csepwidth(#) specifies the separation between columns in units of digit
widths. The default is not a fixed number, but a number chosen by
table according to what it thinks looks best.
stubwidth(#) specifies the width, in units of digit widths, to be
allocated to the left stub of the table. The default is not a fixed
number, but a number chosen by table according to what it thinks
looks best.
scsepwidth(#) specifies the separation between supercolumns in units of
digit widths. The default is not a fixed number, but a number chosen
by table to present the results best.
center specifies that results be centered in the table's cells. The
default is to right-align results. For centering to work well, you
typically need to specify a display format as well. center
format(%9.2f) is popular.
left specifies that column labels be left-aligned. The default is to
right-align column labels to distinguish them from supercolumn
labels, which are left-aligned.
cw specifies casewise deletion. If cw is not specified, all observations
possible are used to calculate each of the specified statistics. cw
is relevant only when you request a table containing statistics on
multiple variables. For instance, contents(mean mpg mean weight)
would produce a table reporting the means of the variables mpg and
weight. Consider an observation in which mpg is known but weight is
missing. By default, that observation will be used in the
calculation of the mean of mpg. If you specify cw, the observation
will be excluded in the calculation of the means of both mpg and
weight.
row specifies that a row be added to the table reflecting the total
across the rows.
col specifies that a column be added to the table reflecting the total
across columns.
scol specifies that a supercolumn be added to the table reflecting the
total across supercolumns.
concise specifies that rows with all missing entries not be displayed.
missing specifies that missing statistics be shown in the table as
periods (Stata's missing-value indicator). The default is that
missing entries be left blank.
replace specifies the data in memory be replaced with data containing 1
observation per cell (row, column, supercolumn, and superrow) and
with variables containing the statistics designated in contents().
This option is rarely specified. If you do not specify this option,
the data in memory remain unchanged.
If you do specify this option, the first statistic will be named
table1, the second table2, and so on. For instance, if contents(mean
mpg sd mpg) was specified, the means of mpg would be in variable
table1 and the standard deviations in table2.
name(string) is relevant only if you specify replace. name() allows
changing the default stub name that replace uses to name the new
variables associated with the statistics. If you specify name(stat),
the first statistic will be placed in variable stat1, the second in
stat2, and so on.
format(%fmt) specifies the display format for presenting numbers in the
table's cells. format(%9.0g) is the default; format(%9.2f) and
format(%9.2fc) are popular alternatives. The width of the format you
specify does not matter, except that %fmt must be valid. The width
of the cells is chosen by table to present the results best. The
cellwidth() option allows you to override table's choice.
Limits
Up to four variables may be specified in the by(), so with the three row,
column, and supercolumn variables, seven-way tables may be displayed.
Up to five statistics may be displayed in each cell of the table.
The sum of the number of rows, columns, supercolumns, and superrows is
called the number of margins. A table may contain up to 3,000 margins.
Examples
---------------------------------------------------------------------------
Setup
. sysuse auto
One-way table; frequencies shown by default
. table rep78
One-way table; show count of nonmissing observations for mpg
. table rep78, contents(n mpg)
One-way table; multiple statistics on mpg requested
. table rep78, c(n mpg mean mpg sd mpg median mpg)
Add formatting
. table rep78, c(n mpg mean mpg sd mpg median mpg) format(%9.2f)
Two-way table; frequencies shown by default
. table rep78 foreign
Two-way table; show means of mpg for each cell
. table rep78 foreign, c(mean mpg)
Add formatting
. table rep78 foreign, c(mean mpg) format(%9.2f) center
. table foreign rep78, c(mean mpg) format(%9.2f) center
Add row and column totals
. table foreign rep78, c(mean mpg) format(%9.2f) center row col
---------------------------------------------------------------------------
Setup
. webuse byssin
Three-way table
. table workplace smokes race [fw=pop], c(mean prob)
Add formatting
. table workplace smokes race [fw=pop], c(mean prob) format(%9.3f)
Request supercolumn totals
. table workplace smokes race [fw=pop], c(mean prob) format(%9.3f) sc
---------------------------------------------------------------------------
Setup
. webuse byssin1
Four-way table
. table workplace smokes race [fw=pop], by(sex) c(mean prob)
format(%9.3f)
Four-way table with supercolumn, row, and column totals
. table workplace smokes race [fw=pop], by(sex) c(mean prob)
format(%9.3f) sc col row
---------------------------------------------------------------------------
Also see
Manual: [R] table
Help: [D] collapse, [R] summarize, [P] tabdisp, [R] tabstat, [R]
tabulate oneway, [R] tabulate twoway