## Exporting tabs and cross-tabs to MS Word from Stata with asdoc

Category:BlogFor installation and other uses of asdoc, please see this short blog post.

Tabulation and Cross-tabs with asdoc

Exporting tables created by Stata commands such as tab, tabulate1, tabulate12, table, tabsum, tab1, tab2, and others to MS word is super easy with asdoc. As with other commands, we need to just add asdoc as a prefix to the tabulation commands that includes tabulate, tabulate1 tabulate2, tab1, tab2, etc. Since frequency tables in Stata can assume different structures, asdoc writes these tables from log files.

### One-way table

Example: One-way table

sysuse auto, clear asdoc tabulate rep78, replace

Please note that replace is asdoc option to replace the existing file. If we were to write to the existing file, we would then use option append, instead of replace.

### Two-way table of frequencies

webuse citytemp2, clear asdoc tabulate region agecat, replace

Example: Include row percentages

asdoc tabulate region agecat , nokey row replace

Note nokey suppresses the display of a key above two-way tables.

Example: Include column percentages

asdoc tabulate region agecat , nokey column replace

Example: Include row percentages, suppress frequency counts

asdoc tabulate region agecat, nokey row nofreq replace

### One- and two-way tables of summary statistics

Example: One-way tabulation with summary statistics

sysuse auto, clear asdoc tabulate rep78, summarize(mpg) replace

Example: Two variables tabulation with summary statistics

generate wgtcat = autocode(weight, 4, 1760, 4840) asdoc tabulate wgtcat foreign, summarize(mpg) replace

```
Example: Suppress frequencies
asdoc tabulate wgtcat foreign, summarize(mpg) nofreq replace
```

### Multiple-way tabulation (tab1)

tab1 produces a one-way tabulation for each variable specified in varlist.

Example: Multiple-way tabulation

sysuse nlsw88, clear asdoc tab1 race married grade, replace

### Two-way for all possible combinations (tab2)

Example: Two variables tabulation with summary statistics

asdoc tab2 race south, replace

## 8 Comments

## Federico Podesta

December 5, 2018at 7:54 pmDear Attaullah,

I have just downloaded your asdoc program. It is wonderful. MANY MANY THANKS FOR YOUR EFFORT!!

Nevertheless, I have found a problem in Including row percentages in the two-way table of frequencies. If I run the code included in the asdoc help (Example 41), I will not get row percentages

Otherwise, I get row percentages if I simply run

I’m wrong or there is a problem in your program? Thanks a lot in advance for any of your help!

## Anne Marie Schak Jensen

December 7, 2018at 5:47 pmDear Mr Attaullah Shah

Thanks for the program asdoc in Stata it seems to work fine.

http://fintechprofessor.com/2018/06/18/exporting-tabs-and-cross-tabs-to-ms-word-from-stata-with-asdoc/

https://www.statalist.org/forums/forum/general-stata-discussion/general/1435798-asdoc-an-easy-way-of-creating-publication-quality-tables-from-stata-commands

I face a similar issue as reported by Febrico. I don’t get row percentages, see Example 41 in the asdoc help file.

## Attaullah Shah

December 7, 2018at 5:50 pmFedrico and Anne Marie:

You are right. This problem occurs due to a conflict of options of asdoc and tabulation. Option row is an option of asdoc, as well as the tabulate command, but asdoc has a preference and hence the option row is not passed to the tabulate command. As a solution, I have added option

which will pass all such conflicting options to the relevant Stata commands. You can install this new beta version from my website first and then use this option.subopt()I would appreciate if you can comment on asdoc youtube video.

https://www.youtube.com/watch?v=61ks3cMPz3c

Please do cite asdoc in your research.

In-text citationTables were created using asdoc, a Stata program written by Shah (2018).

BibliographyShah, A. (2018). ASDOC: Stata module to create high-quality tables in MS Word from Stata output. Statistical Software Components S458466, Boston College Department of Economics.

## Anne Marie Schak Jensen

December 12, 2018at 7:24 pmI have installed the beta version and now the row option works fine.

## Richard Makurumidze

April 7, 2019at 3:18 amGreetings,

Thank for this wonderful STATA module. I have 2 issues;

1. Trying to use it with tabulate command and giving the following error message “option matrow() not allowed”

2. Its seems not to work with the graph command i.e. it can export graphs to Word

Many thanks

## Attaullah Shah

April 7, 2019at 11:06 amRichard Makurumidze: I have replied to your question in this blog post.

For your second query, yes asdoc is not able to send graphs to MS Word. However, I am trying to add this functionality in the next premium version of asdoc, which I would asdocx. For more updates, keep visiting this page.

## YZ

April 16, 2019at 9:17 pmDear Attaullah, Many thanks for asdoc,

I have a question that if I want to do a 2*2 table with chi-square, how can I have the P value in the export doc. I tried different ways just can not have p-value exported

## Attaullah Shah

April 16, 2019at 9:41 pmYZ

Currently asdoc does not report additional statistics with tabulation commands. However, there is a workaround this issue. If you read the asdoc help file, you shall in Section # that there is a text() option which can be used for reporting text or any additional statistics from the r() and e() macros. Since tabulation command leaves the Chi2 and its P-value in r() macros, therefore, they can be written to the existing document using the text option. See the following examples