*! version 1.2 3 dec 2019

Title

wordcb -- Create Microsoft Word formatted codebook

Syntax

wordcb
[varlist]
using,
[, options]

using filename specifies the output Microsoft Word file and is required.

Main
varlist any Stata variable list; default is all variables

values(#) number of unique values to display in tables; default is 5. Zero is allowed and omits values from the output

Control sort order
sortfreq(varlist) sort frequency distribution table descending by frequency for specified varlist; must be either the same as the main varlist or a subset of the main varlist

sortvalues(varlist) sort frequency distribution table ascending by values for specified varlist; must be either the same as the main varlist or a subset of the main varlist

Suppress elements in output file
nodta suppress display of file metadata

freqonly(varlist) suppress display of mean, standard deviation, and percentiles
for specified varlist; must be either the same as the main varlist or a subset of the main varlist

Output file save options
replace replaces destination Microsoft Word file

append appends result to destination Microsoft Word file

Description

wordcb Creates a Microsoft Word file similar to output from the the built-in command
codebook. The output file is useful for deposit in data archives or for initial data exploration.

Remarks

This command aids in creating documentation suitable for archiving datates.
wordcb uses putdocx, new in Stata 15, to create a Microsoft Word
formatted codebook of the dataset im memory.

The resulting Word file includes metadata about the data file including
the data file name, data label, and data notes, followed by a pagebreak.

For each variable specified in the varlist, wordcb creates a table containing a header with
the varname, type, label, format, number of unique values, number of observations
with missing values, and variable notes (if present).

A frequency distribution for each variable specified in
the varlist is also displayed. The number of values displayed in the frequency distribution
can be limited by the values(#) option. By default, five random values are shown.
When values(#) is zero, values, mean, standard deviation, and percentiles are omitted.

What is displayed in the frequency distribution is controlled by either the sortfreq(varlist) or the sortvalues(varlist)
option. Variables in the sortfreq(varlist) option are sorted descending by frequency; variables in the
sortvalues(varlist) option are sorted ascending by value.

Limits

Users wanting different numbers of values(#) for different variables should invoke
wordcb multiple times, with the nodta option and append option on the second and
subsequent runs.

wordcb uses putdocx, and is therefore subject to the same limitations as putdocx, most
importantly, the amount of RAM allocated to Java in Stata. Java heap limits and other out of memory
errors will occur when a large number of values, and/or a large number of variables are specified, and/or
a large or complex Microsoft Word file is appended to.

The suggested workaround is to invoke wordcb multiple times, with the nodta option on the second and
subsequent runs, then combine the output in Microsoft Word.

Author

Troy Payne

Alaska Justice Information Center and University of Alaska Anchorage

tpayne9@alaska.edu

Thanks to Andrew Gonzalez & Araceli Valle at the Alaska Justice Information Center and
Winnie Hua at Corrona for testing and early comments.