*! version 1.0 18 Nov 2021

Title

report -- A command to produce tables for XML

Syntax

report
[if]
[iweight/]
[,
options]

Required

rows(string) specifies the variable(s) used for the rows of the table.

Optional
cols(string) specifies the variables used for the columns of the table.

file(string) specifies the filename of the file to contain the new table.

title(string asis) specifies the text used as the title of the table.

toptions(string asis) specifies the additional text options used for the table.

adjacentcolumns indicates that columns are placed next to each other and not nested.

adjacentrows indicates that rows are placed next to each other and not nested.

tableoptions(string asis) specifies the additional options used for the table.

usecollabels uses the value label to determine the values tabulated as opposed to which values are observed.

userowlabels uses the value label to determine the values tabulated as opposed to which values are observed.

font(string) specifies the font to be used in the table.

landscape specifies whether the table is created in landscape mode.

pagesize(string) specifies the page size.

row specifies to produce row percentages for a frequency table.

column specifies to produce column percentages for a frequency table.

totals specifies to produce total columns and rows for a frequency table.

note(string) specifies the text to place in the table note.

nofreq indicates that frequency values are not included in the table.

replace specifies that a new file be created.

missing specifies that missing values will be reported separately for frequency tables and NOT summary tables.

dropfirstrows(#) specifies that the first # lines are dropped.

droplastrows(#) specifies that the last # lines are dropped.

dropfirstcols(#) specify the number of columns to drop at the left side of the table to drop

droplastcols(#) specify the number of rows at the bottom of the table to drop

rowtotals specifies that additional totals are added to the inner row variable.

coltotals specifies to produce column totals for a frequency table.

rowsby(string) indicates that the summary statistics table has a subdivision on the rows, this can be used in conjuntion with cols() but not adjacentcolumns().

overall specifies that overall summary statistics are included in the summary statistics tables.

oldstyle specifies that the tables use the pre-May2021 table formats.

cellfmt(string) specifies additional formatting statements be added to the table.

* extras

Description

report produces a single table that can be added to an existing docx file or
used to create a new docx file.

Options

Main

rows(string) specifies the variable(s) used for the rows of the table.

cols(string) specifies the variables used for the columns of the table.

file(string) report specifies the filename of the file to contain the new table.

title(string asis) specifies the text used as the title of the table.

toptions(string asis) specifies the additional text options used for the table.

adjacentcolumns indicates that columns are placed next to each other and not nested.

adjacentrows indicates that rows are placed next to each other and not nested.

tableoptions(string asis) specifies the additional options used for the table.

usecollabels uses the value label to determine the values tabulated as opposed to which values are observed.

userowlabels uses the value label to determine the values tabulated as opposed to which values are observed.

font(string) specifies the font to be used in the table.

landscape specifies whether the table is created in landscape mode.

pagesize(string) specifies the page size.

row specifies to produce row percentages for a frequency table.

column specifies to produce column percentages for a frequency table.

totals specifies to produce total columns and rows for a frequency table.

note(string) specifies the text to place in the table note.

nofreq indicates that frequency values are not included in the table.

replace replace specifies that a new file be created.

missing specifies that missing values will be reported separately for frequency tables and NOT summary tables.

dropfirstrows(#) specifies that the first # lines are dropped.

droplastrows(#) specifies that the last # lines are dropped.

dropfirstcols(#) specify the number of columns to drop at the left side of the table to drop

droplastcols(#) specify the number of rows at the bottom of the table to drop

rowtotals specifies that additional totals are added to the inner row variable.

coltotals specifies to produce column totals for a frequency table.

rowsby(string) indicates that the summary statistics table has a subdivision on the rows, this can be used in conjuntion with cols() but not adjacentcolumns().

overall specifies that overall summary statistics are included in the summary statistics tables.

oldstyle specifies that the tables use the pre-May2021 table formats.

cellfmt(string) specifies additional formatting statements be added to the table.

* extras

Examples

First read in some data

webuse citytemp2, clear <--- this will delete your data!

The simplest table is to create a list of unique levels of a variable and places it
in a file called test.docx (replacing it if it already exists).

report, rows(region) nofreq file(test) replace

Then freqencies of each category and percentages can be added to the same filename test.docx (by not specifying replace)

report, rows(region) title(Frequency and row percentages) file(test) row

Often the same sort of report can be desired for two variables, this can be done by adding in an additional variable
into the rows() option.

report, rows(region agecat) title(2-way Freq table) file(test) row

However, this is not the usual way of producing a frequency table and the useful one is having
region as the row variable and agecat as the column variable. To give the more familiar table.

report, rows(region) cols(agecat) column totals file(test)

Higher dimensions are allowable

report, rows(region division) cols(agecat) column totals file(test)

which does not seem correct because region is derived from division and there are plenty of zero cells
in the table. However you could do separate tables with rows either region or division but to
combine into one table you can use the adjacentrows option

report, rows(region division) cols(agecat) column totals file(test) adjacentrows

A table containing summary statistics can also be created with the following command. Note that you can put formating statements for each of
the summary statistics. Also the statistics are the words used in the collapse command and any of the collapse
statistics can be used.

report, rows(tempjan, mean %5.2f | tempjan, sd %5.2f| tempjan, count | tempjuly, mean %5.2f| tempjuly, median %5.2f) cols(region agecat) font(,8) file(test)

Rather than nesting age within region, it might be preferred to have the columns alongside each other and here we add the adjacentcolumns option

report, rows(tempjan, mean %5.2f | tempjan, sd %5.2f| tempjan, count | tempjuly, mean %5.2f| tempjuly, median %5.2f) cols(region agecat) font(,8) file(test) adjacentcolumns

Also it is possible to add the overall category alongside the column variables.

report, rows(tempjan, mean %5.2f | tempjan, sd %5.2f| tempjan, count | tempjuly, mean %5.2f| tempjuly, median %5.2f) cols(region agecat) font(,8) file(test) adjacentcolumns overall

Or perhaps you want to subdivide the rows by region and have age categories as columns, this is handled by adding a rowsby() option.

report, rows(tempjan, mean %5.2f | tempjan, sd %5.2f| tempjan, count | tempjuly, mean %5.2f| tempjuly, median %5.2f) cols(agecat) rowsby(region) font(,8) file(test)

Then to produce the table in landscape because it doesn't fit well in portrait (which is the default)

report, rows(heatdd, mean %5.2f | heatdd, count | heatdd, sd %5.3f | tempjan, mean %5.2f | tempjan, sd %5.2f| tempjan, count | tempjuly, mean %5.2f| tempjuly, median %5.2f) cols(region agecat) font(,8) landscape file(test2) replace

A recent addition to the report command is the ability to alter the formatting of any cells of the table. Many formatting statements can be
added with a | symbol in between. The first number is for specifying the rows, the second number is for specifying the columns and the third part is the text
used in the format option.

report, rows(heatdd, mean %5.2f | heatdd, count | heatdd, sd %5.3f | tempjan, mean %5.2f | tempjan, sd %5.2f| tempjan, count) cols(region agecat) font(,8) landscape cellfmt(6,6,font(palatino, 12, red) | 5,., shading(lime))

The next example does some frequency tables but sometimes the first row and first column are not needed to make sense
of the results. Using the dropfirstcols() and dropfirstrows() options the variable label columns can be removed. Note that these commands are not guaranteed to work because you might be dropping a column when perhaps two cells have been merged (no idea how to drop half a merged cell)

.use "http://www.stata-press.com/data/r16/nhanes2b.dta", clear
.report, rows(race agegrp region) cols(sex) totals column file(example_tables) adjacentrows title(Table 10: Frequency table - another example.) font(,10) landscape dropfirstrows(1) dropfirstcols(1)

Author

Prof Adrian Mander, Cardiff University.

Email mandera@cardiff.ac.uk