Introduction
asdoc sends Stata output to Word / RTF format. asdoc creates high-quality, publication-ready tables from various Stata commands such as summarize, correlate, pwcorr, tab1, tab2, tabulate1, tabulate2, tabstat, ttest, regress, table, amean, proportions, means, and many more.
Using asdoc is pretty easy. We need to just add asdoc as a prefix to Stata commands. asdoc has several built-in routines for dedicated calculations and making nicely formatted tables.
asdoc Options
How to enter asdoc options and Stata_command options?
Both the asdoc options and Stata_command specific options should be entered after comma. asdoc will parse both the option itself. For example,the following command has both types of options.
asdoc sum, detail replace dec(3)
option detail belongs to sum command of Stata, whereas options replace and dec(3) are asdoc options.
Following options are used for controlling the behavior of asdoc:
1.1 Replace / append:
We shall use option replace when an existing output file needs to be replaced. On the other hand, we shall use option append if we want to
append results to the existing file. Both the options are optional. Therefore, if none of these options are used, asdoc will first determine
whether a file with a similar name exists in the current directory. If it exists, asdoc will assume an append option. If the file does not
exist, it will create a new file with the default name “Myfile.doc”
Example 1 : running asdoc without replace or append (first time) sysuse auto asdoc sum
The above lines of code will generate a new file with the name Myfile.doc. Next, if we estimate a table of correlation, we can replace the
existing file Myfile.doc or append to it. Again, if we do not use any of these options, option append will be assumed. So;
Example 2 : running asdoc without replace or append (second time) asdoc cor OR asdoc cor, append
Both of the above commands serve the same purpose. The file Myfile.doc will now contain a table of summary statistics, followed by a table ofcorrelations. However, had we typed the following, then the file would contain only table of correlations. asdoc cor, replace
1.2 rowappend:
To develop a table row by row from different runs of the asdoc, we need to use option rowappend. This option can be used with ttest, customized summary statistics, or in other instances where the table headers and structure do not change
and appendable statistics have a similar structure as those already in the table.
1.3 save (file_name):
Option save(file_name) is an optional option. This option is used to specify the name of the output file. If left blank, the default name will
be used, that is Myfile.doc. If .doc extension is not preferred, then option save will have to be used with the desired extension, such as
.rtf
Example 3 : Naming the output file asdoc sum, save(summary.doc) OR asdoc sum, save(summary.rtf)
1.4 title(table_title)
Option title(table_title) is an optional option. This option is used to specify table title. If left blank, a default table title will be
used.
asdoc sum, save(summary.doc) title(Descriptive statistics)
1.5 Font size i.e. fs(#)
The default font size of asdoc is 10 pt. Option fs(#) can be used to change it. For example, fs(12) or fs(8), etc.
1.6 Decimal points i.e. dec(#)
The default decimal points in many commands are 3. In some commands, the decimal points are borrowed from the Stata output and hence they cannot be changed. In several commands, it is possible to change decimal points with option dec(#). For example, dec(2) or dec(4), etc.
1.7 Adding text lines to the output file i.e. text(text lines)
We can write text to our output file with option text(text lines). This is useful when we want to add details or comments with the Stata
output. In fact, this option makes asdoc really flexible in terms of adding tables and paragraph at the same time. We never have to leave the
Stata interface to add comments or interpretation with the results. One trick that we can play is to use option fs() to change font size and
mark headings and sub-headings in the document. Consider the following examples [I have copied some text from www.wikipedia.org for this example]
1. Write a heading "Details on Cars" in our document asdoc, text(Details on Cars) fs(16) replace
2. Now add some text
asdoc, text(A car is a wheeled motor vehicle used for transportation) append fs(10) asdoc, text(Most definitions of car say they run primarily on roads, seat one ) append fs(10) asdoc, text(to eight people, have four tires, and mainly transport people.) append fs(10)
3. Now add some statistics
sysuse auto, clear asdoc sum, append fs(10)
1.8 Hide Stata output with option hide
We can suppress Stata output with option hide. It is important to mention that option hide might not work with some of the Stata commands (asdoc creates output from log files in some cases).
1.9 Getting Stata commands in output files (cmd)
If we need to report the Stata command in the output file, we can use the option cmd.
1.10 Abbreviate variable names with option (abb(#))
In case variable names are lengthy, they can be abbreviated in the output file with option abb(#). For example, abb(8). In many cases, the
default value is 10. However, when option label is used, this value is set to = abb + 22
1.11 Report variable labels with option (label)
Several commands allow reporting variable labels instead of variable names. For example, the most commonly used commands for reporting statistics are correlate and summarize. Both of these commands allow option label. For example :
asdoc cor, label asdoc sum, label
1.12 Always report equal decimal points (tzok)
The default for report decimal points is to drop trailing zeros and report only valid decimal points. However, we can use the option tzok
i.e. trailing zeros OK, to report equal decimal points for all values even if the trailing values are zero. Therefore, using option
dec(4) for reporting 4 decimal points, the value 2.1 will be reported as follows with and without option tzok.
Default style 2.1
with tzok option 2.1000
[addthis tool=”addthis_relatedposts_inline”]
I have tried to specify the number of decimal points to be used with the command “mean”, using asdoc. It doesn’t work. Is “mean” one of the commands where one cannot specify the number of decimal points to be used with asdoc? Or do you think I have made a mistake in my coding?
Here is my code:
Hi,
I really appreciate you for your hard work. I am just wondering if you have a sample for mean and median test for two groups in a sample. I want to create a summary table, including obs, mean and median with test stats and significance level for two groups.
Thank you.
H. Panta
Hi H Panta
You can use the stat option with the sub command sum and report customized statistics. For example, from the auto dataset, let us create the statistics you have specified for a list of variables
In the above code, the term p50 is used for reporting the median.
It would be nice to be able to suppress the title when producing many one-way freq. tables. Also, would be cool if ‘rowappend’ worked with tab1.
Giovanni : The title can be suppressed by entering an empty title. You can also see this thread on the Statalist, post 35 where I showed how to do it. Here is a short example:
The title(\) is a way of entering an empty title. And thanks for the rowappend option, I shall explore this possibility in the next update.
Hi,
Is there a way to put stars for significance ttest by group?
how to put stars for the difference?
Can we find the median difference between mpg by a group like foreign using asdoc?
Thank you for your support in advance.
HP
HP: Adding significance stars to t-test results is not currently supported by asdoc. I was waiting for someone to ask for it, you are the first one. I shall try to add it to asdoc in the next update. Thanks for stopping by and your comments.
Thank you for the prompt response. Would you be able to add a median test by the group so that that we can find the median difference of a given variable in two groups? Thanks.
HP: Please provide some example or refer me to some material on what you are asking for
Thanks for asdoc! It is a great tool! However, could you add the option to put the number of observations at the end of the correlation table? I usually put it when using estpost correlate / esttab, but I could not find out how to do it with asdoc.
Fabio Motoki Can you please suggest a layout in which the number of observations would be appended to the correlation table?
Hi,
Just like finding the mean difference between two groups as
can we test median difference as
Thanks for the suggestion, I shall work on it.
Just wanna input on a couple of comments. This site layout is perfect, the articles are quite superb:
Thanks so much for your hard working on this! It’s a great way to output tables from Stata. Is there a way to change the font size for a table title? The fs() option seems to only change the size of the text in the table, not the title.
Lauren
Thanks for your feedback. Yes, it is possible. In fact, we can pass any RTF control word for formatting the title text. For changing the font size, relevant control word is
fs
. See the following example where I set the font size 40 for the title text.Hi,
asdoc was very helpful during the last day, but currently I am having some trouble.
If I try to use asdoc to export a correlation diagram I get the following error: “: 3499 asdoccor() not found”
Do you have any idea how I could solve this or is anybody else have the same problem?
William: This is rather an unusual error message, please re-install your package by typing
And restart your stata. If that does not solve the problem, then please send me the following:
1, Type the following and send me the output
2. Also, please indicate which version of Stata and operating system do you use
3. Please if you can share your data set or a sample of it
Email: attaullah.shah@imsciences.edu.pk
Hello, how do I create a table of summary statistics using asdoc of selected variables, for example my data has 12 variables but I just want the statistics of 6 variables only. Thank you for your help
Muvanhu
You have to write the names of those variables. For example, in the following code, I am specifying three variables, ie. price, mgp, and rep78
sysuse auto, clear
asdoc sum price mgp rep78, replace
Hi Dr. Shah,
Can I report both p value and SE in the nested table?? Also how do I show the both R2 and adjusted R2 using asdoc?
It’s a lifesaving command. Thanks !!
Sadek,
Currently you can only report either se or p-values, not both at the same time in the nested tables. For reporting adjusted r-squared, you can use the option stat(r2_a). For example
Hallo, thanks for asdoc, great command! I am having issues saving my output results in a log file when my dofile has more than one asdoc command. If there is more that one asdoc command in the dofile, it does not save all the output results – the logfile breaks down somewhere and I get an error indicating there is no log file to close. However when I remove all the asdoc commands, the logfile saves everything in the output window and closes properly,… Is this something you have encountered or been asked.
Hope the narrative I am giving is clear… .
Thanks
I am having the same problem as Pricilla. Asdoc seems to be interacting with the log command somehow. For now I am going to try to close the log file before every asdoc and then reopen it after. I would love a better solution.
Good morning professor Shah, I’m trying to combine the outputs of a t-test plus a summarize.
using a piece of your code found on a Statalist post, I tried to replicate something like the following:
unfortunately, the output is an empty table. could you point me the mistakes I’m making?
thanks a lot in advance
Edorado
I have moved your comment to the Forum page, please access my reply here.
I want to drop coefficients of i.year i.indnu from my asdoc table. But drop does not work. I get the message that “drop is not allowed”. Can you help! Thanks
Can you please post the full command?
In response to your mail:
My year variable contains 2014 to 2019. Industry variable includes names of industries (string variable) and is coded as follows;
drop command does not work.
Thanks
IM
You may use the keep() option as dummy variable names and factor variables are usually difficult to type and get their correct name. You may try this:
Please remember to cite asdoc in your research
In-text citation
Tables were created using asdoc, a Stata program written by Shah (2018).
Bibliography
Shah, 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.
Thanks a lot Prof Shah.
For generating i.indnu, I use code:
tabulate industry, gen(indnu)
When I run code
asdoc xtreg l q r s g nta i.year i.indnu, fe robust save(myresults) fs(8) keep(l q r s g nta)
I ge message indnu ambiguous.
When I generate indnu using: encode industry, gen(indnu) , I get results but coefficients of both year and industry do appear in in Table.
I will appreciate your help.
Thanks a lot
Please send your dataset and your code at my email.
Dear Professor Shah,
your asdoc command is helping so, so much. Thank you!
I have a question. I am running a probit regression, hence I am not interested in the coefficients but rather in the marginal effects. Is there a way to include those instead for each variable and for each model?
As of now I am running the following command:
asdoc probit results players games goals, replace nest cnames(Model 1) dec(3) save(Regression_Table_Base_Model) title(Probit Regression Table) fs(8) stat(chi2)
I would like to add the results of
margins, dydx(*) atmeans
to my table and drop the coefficients instead. The significants stars I want to keep, same as the standard errors.
Thanks already
Charlotte
I am running multilevel logit model. can we use asdoc to get the results in one table? If so how to proceed?
Dear Professor Ramakrishna
Multi-level models are currently not supported by asdoc. The next version of asdoc (I call it asdocx) will have this missing functionality. I shall send an email to all asdoc users once the next version is read.
Dear Dr. Shah,
I must commend you for the good job with asdoc.
My inquiry is about the cor output table that i had previously ran to establish which variables are highly correlated before going on for further analysis. When I proceeded with the analysis using the logit command after which I applied asdoc with the replace option, I still get the earlier collation matrix table. To further clarify, i ran a line of code with a logit model with at option to replace, i still got that previous cor output (matrix of correlation table). Is there anything I am not getting right
Dear Dr. Shan,
How can I get the table figure in below format:
Variable 2013
N = 200
Sex
Male 100 (50)
Female 100 (50)
Pragya
I have not understood your query. Can you please post or email me your data and the asdoc code that you have used. Also, please elaborate what you mean by Male 100 (50), etc.
Dear Dr. Shah,
First of all, thank you so much for all your effort!
I have been able to use asdoc consistently and without problems. However, until recently, i am no longer able to create a new correlation table using asdoc.
Everytime i run a correlation using asdoc pwcorr var1 var2 etc, i am not getting the correct output in the word document. Instead, it keeps exporting a table with variables i defined earlier in another correlation.
What can i do to fix this issue? i am using stata version 14.0.
It would help me a lot if you would get back to me
Thanks in advance!
Jorian
The current version of asdoc is
The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.
Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.
If this version also givens the same error, then please send your data and asdoc code so that I can fix it.
asdocx is now available
A more powerful and flexible version of asdoc is now available. I call it asdocx. You may like to check the details here
https://fintechprofessor.com/asdocx
Please do remember to cite asdoc. To cite:
In-text citation
Tables were created using asdoc, a Stata program written by Shah (2018).
Bibliography
Shah, 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.
Respected Prof. Shah
How to get more than 7 digit figures in the using asdoc? Presently more than 7 digits are expressed in exponent form. For example 1.97e+07. How to solve this problem?
Please post your asdoc code so that I can identify the Stata command that you are using with asdoc.
I am having the same problem, can you please help? The code I used is given below:
Hi professor,
How to use asdoc for ARDL model, as the “replace” option is already there in ARDL code
Mehmood
This is one situation where we have a real contradiction in asdoc and Stata options. You might use a new file new instead of the replace options. New file name can be specified in the option save()
Hello, does the label option with asdoc work with stcox command?
Hi! I am wondering how to compare between groups when I want to limit to certain observations. For example, I’m running a diff-in-diff analysis, so I’m looking to print differences in the dependent variables for both impacted and non-impacted companies and for the pre/post periods. Thanks!
Hello Linda
I can do this using asdocx. asdocx is a premium version of asdoc and is more powerful and flexible than asdoc. It is currently available for a discounted price of $9.99.
I see, thanks. I just sent! What is the syntax for this this type of descriptive analysis?
Hello! I think the format option in asdoc does not work. I am using this command but the table in the word file does not get this format:
asdoc table gender, c(mean unemployed) format(%12.0fc) title(unemployed) save(myfile.doc) replace
I want to use asdoc for a summary of some selected variables, not every variable I have. please how can I do this?
Hello Mike
If you want to find summary statistics for selected variables, then you need to specify the variable names after asdoc sum. See the following example:
You might also like asdocx, that is more powerful and flexible. See details here https://fintechprofessor.com/asdocx/
Hello sir,
I am trying to use your command to get a simple OLS regression nested table but I also want it to show AIC. The normal table shows AIC but when I use AIC in stat option it just “.z” in the nested table. My code below:
asdoc reg total_score dist if endline_dummy==1, rep(t) title(OLS Regressions) nest tzok replace stat(r2_a, AIC) cnames(Model_1) t(below)
Hi, is there a way to align all estimates by the decimal points in all rows of an asdoc table?