*! version 1.4 19may2021

help for table1Version 1.4, 19 May 2021

Title

table1 -- Create "table 1" of baseline characteristics for a manuscript

Syntax

table1 [if] [in] [weight], vars(var_spec) [options]

var_spec = varname vartype [varformat] [ \ varname vartype [varformat] \ ...]

Supported variable types:

contn - continuous, normally distributed
conts - continuous, skew
cat - categorical, groups compared using Pearson's chi-squared
cate - categorical, groups compared using Fisher's exact test
bin - binary, groups compared using Pearson's chi-squared
bine - binary, groups compared using Fisher's exact test

fweights are allowed; see weight

Group options
by(varname) group observations by varname

test include column describing the significance test used

pdp(#) max number of decimal places in p-value; default is pdp(3)

Contents of rows
onecol report categorical variable levels underneath variable name instead of in
separate column

format(%fmt) default display format for contn and conts variables

cformat(%fmt) default display format for cat and bin variables

plusminus report contn variables as mean +/- sd rather than mean (sd)

percent report categorical values as % rather than N (%)

missing don't exclude missing values from categorical variables

cmissing report number of non-missing continuous variables

Output options
saving(file_spec) save table to Excel file

clear replace the dataset in memory with the table

Description

table1 generates a "table 1" of characteristics for a manuscript. Such a table generally
includes a collection of baseline characteristics which may be either continuous or categorical. The
observations are often grouped, with a "p-value" column on the right comparing the characteristics
between groups.

The vars option is required and contains a list of the variable/s to be included as
rows in the table. Each variable must also have a type specified (contn, conts, cat,
cate, bin or bine - see above). If the observations are grouped using by(), a
significance test is performed to compare each characteristic between groups. contn variables
are compared using ANOVA, conts variables are compared using the Wilcoxon rank-sum (2 groups)
or Kruskal-Wallis (>2 groups) test, cat and bin variables are compared using Pearson's
chi-squared and cate and bine variables are compared using Fisher's exact test. Specifying
the test option adds a column to the table describing the test used.

The display format of each variable in the table depends on the variable type. For continuous
variables the default display format is the same as that variable's current display format. You can
change the table's default display format for continuous variables using the format() option.
For categorical variables (including cat, cate, bin, bine) the default is to
display the proportion using either 0 or 1 decimal place depending on the total frequency. You
can change this default using the cformat() option. After each variable's type you may
optionally specify a display format to override the table's default.

The list of variables is delimited using a backslash (\).

The resulting table may be saved to an Excel file using the saving() option. The
file_spec contains the file path and optionally ", replace" to replace any existing file.
You can also specify the sheet of the Excel file using ", sheet(sheetname)".

The resulting table can be kept in memory, replacing the original dataset, using the
clear option.

Example

. sysuse auto, clear

. table1, by(foreign) vars(price conts \ weight contn %2.1f \ rep78 cat)

. table1, by(foreign) vars(price conts \ weight contn \ rep78 cat) format(%2.1f)

. table1, by(foreign) vars(price conts \ weight contn \ rep78 cat) format(%2.1f) saving(auto.xls, replace)

Author

Phil Clayton, ANZDATA Registry, Australia, phil@anzdata.org.au