The putdocx command allows you to create a word document entirely from within Stata. The command includes options for adding a table to the word document. There are four methods for adding a table, either using the data currently loaded in memory, a matrix, an estimation result, or a table created using the collect command suite. For more information on how to add tables using these methods check out this Tech Tip.
To add a summary table that mimics the summarize command, we use the table command along with Stata’s collect command suite. The table can then be added with Stata’s putdocx collect command.
collect clear
putdocx clear
putdocx begin
ds
local v = "`r(varlist)'"
table (var) (result), statistic(count `v') statistic(mean `v') statistic(sd `v') statistic(min `v') statistic(max `v')
collect style header, level(value)
putdocx collect
putdocx save filename
In this example I create a putdocx table using the Stata auto example dataset. The table should look the same as a table generated with summarize, however the “Obs” column will be titled “count”. In the command pane, I type the following:
sysuse auto, clear
collect clear
putdocx clear
putdocx begin
ds
local v = "`r(varlist)'"
table (var) (result), statistic(count `v') statistic(mean `v') statistic(sd `v') statistic(min `v') statistic(max `v')
collect style header, level(value)
putdocx collect
putdocx save summarize.docx, replace
This generates the following table, saved in summarize.docx:

Which is a perfect representation of summarize, as shown below:
