asdocx : Stata – Export Codebook to Word, Excel or LaTeX


asdocx is a Stata package that can export output from almost all Stata commands with addition of the word asdocx to the beginning of any Stata command. This post discusses how can we export the output from the codebook command. The codebook command examines the variable names, labels, and data to produce a codebook describing the dataset. asdocx can export the output to MS Word, Excel or LaTeX formats. The syntax of the command is:

asdocx codebook [varlist], replace

In the above code, the [varlist] is optional, therefore, if we leave it out, codebook will be generated for all variables. Instead, if we wanted a codebook for some specific variables, then we would provide list of those variables. Consider the following example, where we want to create a codebook table for mpg, price, and trunk.

asdocx codebook mpg price trunk , replace

 

Example of codebook for all variables


Let us create a compact codebook for all variables and send the output to MS Word and then to MS Excel

*Load the working women dataset
sysuse nlsw88, clear

* Send a compact codebook to MS Word
asdocx codebook, replace

And here is the output
asdocx codebook Excel

Since the default output format is MS Word, therefore, we did not use the save() option. If we wanted to send the output to MS Excel, then we must use the save(Myfile.xlsx) option. Myfile can be any valid file name. The extension .xlsx is what asdocx uses to identify the output format.

*Load the working women dataset
sysuse nlsw88, clear

* Send a compact codebook to MS Excel
asdocx codebook, save(Myfile.xlsx) replace

And here is the output
asdocx codebook word