Home > Data Management > Export tabulation results to Excel—Update

Export tabulation results to Excel—Update

It’s summer time, which means we have interns working at StataCorp again. Our newest intern, Chris Hassell, was tasked with updating my community-contributed command tab2xl with most of the suggestions that blog readers left in the comments. Chris updated tab2xl and wrote tab2docx, which writes a tabulation table to a Word file using the putdocx command.

To install or update your tab2xl command, type

. net install http://www.stata.com/users/kcrow/tab2xl, replace

To install the new tab2docx command, type

. net install http://www.stata.com/users/kcrow/tab2docx

tab2xl now allows weights, if, in, formatting of the cells, and two-way tabulations. Once installed, you can type

. sysuse auto, clear
(1978 Automobile Data)

. tab2xl rep78 foreign in 1/50 [fweight=mpg] using testfile, col(1) row(1)
file testfile.xlsx saved

to produce

To write the table to a Word document, you must first open a .docx file using the command putdocx begin, type your tab2docx command to append the table to your file, and then save the document using putdocx save filename. For example, typing

. sysuse auto, clear
(1978 Automobile Data)

. putdocx begin

. tab2docx rep78 in 1/50 [fweight=mpg]

. putdocx save testfile.docx

will produce

Chris did an excellent job updating tab2xl and coding tab2docx, making it easier for you to create tables for inclusion in a Word file.