Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages

asdoc : Creating high quality tables of summary statistics in Stata

Ever wanted to create high-quality summary statistics with one click in Stata. asdoc creates excellent tables of summary statistics such as mean, standard deviation, minimum, maximum, etc. asdoc offers four different methods of creating tables of summary statistics. These are discussed below with examples and relevant options. To know about installation of the program and other feature, you can visit this blog post. 

Simple tables of summary statistics:
To create a simple table of summary statistics, we normally type summarize or sum command in Stata. To send output from sum command to a Word document, we shall type the following. A picture of the output file is also shown below.

sysuse auto
asdoc sum

Summary / descriptive statistics for selected variables 

asdoc sum price mpg rep78 headroom trunk

 

Summary / descriptive statistics with [if] [in] conditions

asdoc sum price mpg rep78 headroom trunk if price>4000

 

Reporting customized decimal points

asdoc sum, dec(2)

46 Comments

Nicola Deghaye MSc (Health Econ)

November 20, 2018at 12:34 pm

Hi
I am using Stata 14 and am battling with “asdoc” with tabstat.
Here is my code:

tabstat TotalLWD_2013, by (quintile) stat(N mean median sem) format

which produces:

quintile |         N      mean       p50  se(mean)
---------+----------------------------------------
       1 |   8018.00      1.44      0.00      0.13
       2 |   6467.00      1.85      0.00      0.16
       3 |   5324.00      3.45      0.00      0.25
       4 |   1807.00      6.08      0.00      0.65
       5 |   2103.00     11.61      0.00      0.71
---------+----------------------------------------
   Total |  23719.00      3.26      0.00      0.12
--------------------------------------------------

asdoc tabstat TotalLWD_2013, by (quintile) stat(N mean median semean) ///
save(prevalence by category raw data 2013.doc) replace  
 
or

asdoc tabstat TotalLWD_2013, by (quintile) stat(N mean median semean) format ///
save(prevalence by category raw data 2013.doc) replace  

produce:

Summary statistics 
  	 N	 Mean	 Median	 se(Mean)
TotalLW~2013	25180	3.203	0	.111

In other words, it is not picking up my “by” option – it is giving me a one-way tab instead of a table of statistics of disability prevalence by school category (quintile)
I have tried various combinations of spacing with the by(quintile), but it isn’t solving the problem.

Please help.

Best regards,

    Attaullah Shah

    November 20, 2018at 12:40 pm

    Seems that asdoc is working perfectly with both the commands. However, in your command, there is a space between by and the term (quintile)

    So, you can correct it by

    asdoc tabstat TotalLWD_2013, by(quintile) stat(N mean median semean) ///
    save(prevalence by category raw data 2013.doc) replace  

Faisal Khan

December 15, 2018at 1:57 pm

Dear Sir,
I appreciate your effort and supportive attitude towards the community. I am interested in finding out descriptive statistics of mutual fund category wise.
When I use asdoc command for multiple category and variables it works but the format of the table is not consistent. The format of a table for 1st category is fine but not for the second, similarly 3rd category fine but not 4th and so on.
The Command is
asdoc by category , sort : summarize CH LNTNA EXP FL DL b1 TURNs TURNp RU12 FFV FF1 FF6 FF12 NoFMs DY Beta LnRed, replace

category: I have encode fund category

    Attaullah Shah

    December 15, 2018at 2:01 pm

    Faisal Khan:
    Due to the specific command structure of asdoc, it accepts the by option in two flavors.
    The first is to use bys as a prefix. So the following command should work for you

    bys category :  asdoc  summarize CH LNTNA EXP FL DL b1 TURNs TURNp RU12 FFV FF1 FF6 FF12 NoFMs DY Beta LnRed, replace

    The second method is to use by as an option after using the comma. So the following should also work.

    asdoc  summarize CH LNTNA EXP FL DL b1 TURNs TURNp RU12 FFV FF1 FF6 FF12 NoFMs DY Beta LnRed, replace by(category)

    .
    Let me know if there is any problem with any of these commands.

Anum Ellahi Mazhar

January 10, 2019at 10:55 am

hi… i want to make specialised table to have frequency and percentage with label identification…for example for gender i want to show the female and male percentage and frequency

    Attaullah Shah

    January 10, 2019at 4:35 pm

    Anum Ellahi Mazhar
    Can you please email me the format in which you are asking for the results?

Arantza Ugidos

February 9, 2019at 8:24 am

Hello, my name is Arantza Ugidos and I have just seen your video about the use of asdoc. I have a question. I want to make a table of summary statistics using weights. I have realized that when I use “asdoc sum” the reported summary statistics are not taken into account the weights. I get the same results when I use the weight option as when I do not use it. I write:

asdoc sum $xlist [weight=pesoper],  replace label dec(2) ///
save(TablaSumStat.doc) title (Descriptive Statistics) 

Have you had the same problem or I am doing something wrong?

Thank you.

Best wishes,

    Attaullah Shah

    February 9, 2019at 8:28 am

    Arantza Ugidos
    Thanks for your email. asdoc does not support weights at the moment, but adding it to asdoc is on my card for the next update.

Farah Zamir

February 20, 2019at 1:55 pm

Dear Dr Shah

I would appreciate your efforts regarding asdoc. I am also trying to use this feature. However, when I use
asdoc tab N_Comb_code COUNTRY

to tabulate SIC codes with 9 countries, the table gets out of margins even in word. I tried changing the font to Courier new and 9….but nothing works. Can you please help me with this. Additionally how to add column headings?

    Attaullah Shah

    February 22, 2019at 8:09 am

    Farah Zamir
    When there are many categories of the given variables, the output will naturally be larger. Normally, it is a good practice to put the variable with many categories in rows. Therefore, if the output goes out of margins, you can swap the places of the two variables. So instead of

    asdoc tab N_Comb_code COUNTRY

    Try the followin

    gasdoc tab COUNTRY N_Comb_code 

    Further, I am going to release the new version of asdoc in the coming week, so do download the new version from ssc by typing

    ssc install asdoc, replace

    . This new version creates elegant tables from the tab and table commands.

Andrew (Public Health)

March 4, 2019at 7:19 pm

Dear Dr Shah,

Thank you very much for asdoc. It works great for me. Tables for conditional (fixed-effects) logistic regression look fantastic and are ready to be published. However, the table for mixed logit models is slightly different (I use the user-written mixlogit.ado). It creates coeff, se, z, p, and conf intervals just fine but doesn’t use labels instead of varnames (option label doesn’t seem to work for mixed logit models) and summary statistics such as AIC or BIC. Is there any workaround to get full statistics for mixed logit models?

Kind regards,
Andrew

Andrew (Public Health)

March 4, 2019at 7:25 pm

In Addition to my former message:

This works great with all statistics:
asdoc clogit choice v1-v12, gr(csets) save(clogit.doc) replace label

Here I get coefficients for mean and SD, but labels and fit criteria such as AIC, BIC are missing:

asdoc mixlogit choice, rand(v1-v12) gr(csets) id(individ)  save(mix.doc) replace label

    Attaullah Shah

    March 4, 2019at 7:37 pm

    Andrew
    asdoc tries to make the regression table from the matrix r(table), which is left behind by standard Stata regressions. The user-written package you have referred to "mixlogi.ado" does not mention in its help file that it stores results in r() or e() macros. Given that, asdoc tries to use its generic routine to make the table, therefore the standard asdoc’s options available with the regression commands do not work with the mentioned package.

Andrew

March 4, 2019at 7:45 pm

Dr. Shah,

thank you very much for the fast reply. I appreciate it. Then I will just add the missing statistics in this specific model manually. I can live with that. Anyway, asdoc is a great help in preparing my papers.

Kind regards,
Andrew

    Attaullah Shah

    March 5, 2019at 7:13 am

    Andrew
    Please do 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.

Frankline Onchiri

April 11, 2019at 5:11 am

Hello Prof. Shah,
Is it possible to include variable and value labels in the detailed Regression Table? This will improve on readability of the outputs.
Thank you and so you know, we really appreciate your responses and collegiality.

    Attaullah Shah

    April 11, 2019at 6:53 am

    Frankline Onchiri
    asdoc can report variable labels. For example,

    sysuse auto, clear
    asdoc reg price mpg trunk weight, label replace

    If you are referring to something different, then please guide me to an example and I shall try to explore the possibility of adding it to asdoc.

Frankline.

April 21, 2019at 7:27 am

Thank you so much for your response. I have been running conditional logistic regression model but the variable and value labels don’t print on the word document that asdoc creates.
Again, I appreciate your time.

Attaullah Shah

April 21, 2019at 8:56 am

Frankline
Can you please send me y our example data and the Stata code that you are using on the following email attaullah.shah@imsciences.edu.pk

Asim Jahangir

May 23, 2019at 9:06 pm

Dear Dr. Shah,

Appreciate your efforts for the research community and making asdoc available for us.
I need to create summary stats between groups and report t-test of significance if the values differ. Currently, I am using the following codes:

sysuse auto
orth_out price mpg, by(foreign) pcompare stars

which gives the following output in a excel file

   Domestic:      Foreign:  (1) vs. (~e:
                               _             _             _
        Price:mean      6072.423      6384.682         0.680
Mileage (mpg):mean        19.827        24.773         0.001

The command is great but it doesn’t give the flexibility to format the table or to introduce * (stars) of significance.

Another possibility is to use estpost and estout combination, like this:

sysuse auto
estpost ttest price mpg, by(foreign)
esttab ., wide

with the following output:
-----------------------------------------
                      (1)                
                                         
-----------------------------------------
price              -312.3         (-0.41)
mpg                -4.946***      (-3.63)
-----------------------------------------
N                      74                
-----------------------------------------

This command gives the output in a text or excel file, with stars. But, I am finding it hard to introduce the mean values of each variable by foreign (category) and format the headers of the table.

The question is, is there a way to use asdoc to make tables with means, mean difference and stars of significance?

Thanks and appreciate your support.

    Attaullah Shah

    May 23, 2019at 10:40 pm

    Asim Jahangir
    A similar question was asked on the Statalist. And Liu Qiang presented an excellent example using the asdoc’s row option. This option is used for making highly customized tables. See the Statalist discussion here.

Asim

May 23, 2019at 9:24 pm

Thanks

Asim Jahangir

May 24, 2019at 6:44 am

Thanks Dr. Shah, this helps a great deal.

I have to produce multiple sets of tables for different categories (using the same dependent variable) where some are binary categories and others have multiple categories. How would one go about it running multiple t-tests like this and append the results in a single or collated tables.

Consider the following code for instance, where one variable has multiple categories (it gives an error):

gen transmission = round(runiform())
label var transmission "Transmission: 0=manual 1=auto"
gen type = floor(runiform()*4)
label var type "Type: 0=sedan 1=mini-van 2=SUV 3=sports"
foreach var in foreign transmission type {
	foreach i in price mpg {	
		ttest `i', by (`var')
	}
}

Attaullah Shah

May 24, 2019at 10:20 pm

The error message you are getting belongs to Stata’s own limitation of allowing only two categories in ttest while using option by(). Therefore, asdoc cannot go beyond Stata’s capabilities. Specifically, the code chokes when it runs the ttest with the option by(type) variable which has three categories.

I am not sure what hypotheses are you testing, but you can estimate ttests using if qualifier with the type variable, adding the relevant categories in the command in turns, so for the first two categories of type, the command would be:

ttest price if inlist(type, 0,1), by(type )

and for the next two, it will be:

ttest price if inlist(type, 0,2), by(type )

and then:

ttest price if inlist(type, 1,2), by(type )

Maria

May 28, 2019at 12:46 am

Dear Prof. Shah,

thanks for your helpful asdoc command.

I have one question: I would like to do the following: asdoc tab2 state urban, cell

While I do have the percentages in the state output, they are not displayed in the Word file.
I saw the “nokey column/row replace” option, which works, but I would still prefer to have the equivalent to the “cell” option, meaning that only in the right corner of the graph I have 100%, to which the total-columns and total-rows sum up. Is this possible with asdoc?

Also, I was wondering whether options like putting the percentages in brackets were possible?

Thank you for any advice or comment!

Best
Maria

    Attaullah Shah

    May 28, 2019at 2:39 am

    Maria:
    It would be easier for me to reply if you provide an example dataset with the codes that you have used. You can send the data and codes to

    attaullah.shah@imsciences.edu.pk

Alhousseynou BALL,

June 29, 2019at 1:04 pm

Good afternoon professor,

I am Alhousseynou BALL, a statistician

I have some questions concerning the asdoc program in Stata. The results obtained by asdoc (see below) correspond to the unweighted results. However, I wish to have weighted results with asdoc.

table age_classe travaille [iweight  = poids_fem], c(mean Hdomestique_corr)

asdoc table age_classe travaille [iweight =  poids_fem], c(mean Hdomestique_corr)

table age_classe travaille, c(mean Hdomestique_corr)

Thank you in advance.

________________________________________________________________
Alhousseynou BALL,

    Attaullah Shah

    June 29, 2019at 1:07 pm

    Thanks for reporting this. I have revised asdoc to remove this bug.

    The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.

    net install asdoc, from(http://fintechprofessor.com) replace

    Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

    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.

Valery

July 26, 2019at 7:35 pm

Dear Prof. Shah,

I am trying to create a table that shows pairwise correlation with asdoc.
The summary statistics table worked perfect fine by typing in the following code:

asdoc summarize atleast1_2 pwomen2 Blau2 fagedummy bsizelog2 emplog talog west_east mvaluelog levdebta ROA ROS TobQ Year industry, replace label tzok dec(2) save(Desc)

However, afterwards I tried to produce a table with pairwise correlation using the following command:

asdoc pwcorr atleast1_2 pwomen2 Blau2 fagedummy bsizelog2 emplog talog west_east mvaluelog levdebta ROA ROS TobQ Year industry, replace label tzok save(Correl)

But here I get the following error:
either the name is not valid; or when I tried to save it with: save(Desc) it also said the file is not found. Then I tried to not save it to as specific file at all:

asdoc pwcorr atleast1_2 pwomen2 Blau2 fagedummy bsizelog2 emplog talog west_east mvaluelog levdebta ROA ROS TobQ, replace label tzok

And then I got:

(note: file Myfile.doc not found)
>=1 invalid name
r(198);

Do you know what’s the problem?

Further, I wanted to ask whether there is any possibility to add the results of the Hausman test or the Breusch-Pagan Test into the regression tables? (i.e., a line where it says: Hausman and then it shows stars if the Hausman test was significant or not).

Thank you very much in advance.

Best wishes,
Valery

    Attaullah Shah

    July 26, 2019at 10:57 pm

    Valery
    Thanks for your comments. The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.

    net install asdoc, from(http://fintechprofessor.com) replace

    Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

    For the second query, results of Hausman test can be appended to the same document. 
    
    * Use the grunfeld dataset in the example
    webuse grunfeld
    
    * Estimate the fixed effect model
    xtreg invest mvalue kstock, fe
    
    * Store the estimates of the fixed effect model. 
    estimates store fixed
    
    * Estimate the random effects model
    xtreg invest mvalue kstock, re
    
    * Store the estimates of the random effects model
    estimates store random
    
    * Apply the Hausman test and write its results to Word file using asdoc
    asdoc hausman fixed random

Sonya Song

August 1, 2019at 10:54 pm

Dear Dr Shah
I just saw your great answers about the code asdoc on web https://fintechprofessor.com/asdoc-creating-high-quality-tables-summary-statistics-st/

I have a question about asdoc with bysort. I want bysort two categories, like “

bysort bz year: asdoc sum age gender

(bz=0 or 1; year from 2014 to 2019),then stata reported

“year is not allowed ”.

But it can work when I only input the code

bysort bz year:sum age gender

How do I write this command?

Thanks for your patience of reading this question. Looking forward to you reply.

Sincerely

    Attaullah Shah

    August 1, 2019at 10:55 pm

    Currently, asdoc allows bysort prefix with only one variable. If you need to use two variables with bysort, then there is a workaround. Convert both the variables to a single with using the group function of egen, and then use the new variable with asdoc. see this example

    egen bz_year = group(bz year)
    
    bysort bz_year: asdoc sum age gender

    Please 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.

Mahmoud

August 4, 2019at 12:08 pm

Hi,
I am using asdoc command for the exporting the output and I have a question. I wonder how can we insert significant star on t-value in the exported output?

below are the code and example:

code:

. asdoc tabstat price mpg rep78 headroom, by(foreign) stat(N mean sd max min tstat)
foreign

example:

. dataex price mpg rep78 headroom

———————– copy starting from the next line ———————–
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int(price mpg rep78) float headroom
4099 22 3 2.5
4749 17 3 3
3799 22 . 3
4816 20 3 4.5
7827 15 4 4
5788 18 3 4
4453 26 . 3
5189 20 3 2
10372 16 3 3.5
4082 19 3 3.5
11385 14 3 4
14500 14 2 3.5
15906 21 3 3
3299 29 3 2.5
5705 16 4 4
4504 22 3 3.5
5104 22 2 2
3667 24 2 2
3955 19 3 3.5
3984 30 5 2
4010 18 2 4
5886 16 2 4
6342 17 2 4.5
4389 28 4 1.5
4187 21 3 2
11497 12 3 3.5
13594 12 3 2.5
13466 14 3 3.5
3829 22 4 3
5379 14 4 3.5
6165 15 3 3.5
4516 18 3 3
6303 14 4 3
3291 20 3 3.5
8814 21 4 4
5172 19 3 2
4733 19 3 4.5
4890 18 4 4
4181 19 3 4.5
4195 24 1 2
10371 16 3 3.5
4647 28 3 2
4425 34 5 2.5
4482 25 3 4
6486 26 . 1.5
4060 18 2 5
5798 18 4 4
4934 18 1 1.5
5222 19 3 2
4723 19 3 3.5
4424 19 . 3.5
4172 24 2 2
9690 17 5 3
6295 23 3 2.5
9735 25 4 2.5
6229 23 4 1.5
4589 35 5 2
5079 24 4 2.5
8129 21 4 2.5
4296 21 3 2.5
5799 25 5 3
4499 28 4 2.5
3995 30 4 3.5
12990 14 . 3.5
3895 26 3 3
3798 35 5 2.5
5899 18 5 2.5
3748 31 5 3
5719 18 5 2
7140 23 4 2.5
5397 41 5 3
4697 25 4 3
6850 25 4 2
11995 17 5 2.5
end
—————— copy up to and including the previous line ——————

Listed 74 out of 74 observations

.

Thanks in advance!
Mahmoud

    Attaullah Shah

    August 9, 2019at 12:49 pm

    Mahmoud
    There is no option to attached stars with tabstat command. You can use the row() option of asdoc to create a customized table. There is a blog entry on how to use the row() option of asdoc.

Deepali Sharma

September 10, 2019at 2:58 pm

Dear Prof

I need some help

I am trying to run asdoc command with if option but its not working

I want sum for only middle income countries

I am writing:
asdoc sum (varlist) if Income_Gourp_wb_ne==”Middle Income”

it says type mismatch. am using stata 14

    Attaullah Shah

    September 10, 2019at 3:49 pm

    Deepali Sharma
    This problem was solved in the new version.

    The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.
    net install asdoc, from(http://fintechprofessor.com) replace

    Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

    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.

Jay Chol Choi (jaychoi@jejunu.ac.kr)

September 10, 2019at 4:10 pm

Dear Dr.Shah
How can I produce a following table using asdoc?
My table is a comparison of multiple variables between group.
Continuous variables with normal distribution should be presented with mean with SD and the variables without normal distributions need to be presented with median with interquartile range.
Categorical variables should be presented with number(percent).

group 1 group2 p-value
——————————————————————————————————-
continuous variable mean (SD) mean (SD) 0.001
continuous variable median (IQR) median (IQR) 0.78
categorical variable 0.34
A number (%) number (%)
B number (%) number (%)
C number (%) number (%)
———————————————————————————————————-

    Attaullah Shah

    September 10, 2019at 6:27 pm

    Jay Chol
    You can use option row() of asdoc to make such customized tables. This blog post gives a simple introduction to option row(). And this blog post provides an advanced example of creating a customized table with asdoc in Stata.

Tina

September 11, 2019at 12:43 pm

Dear Attaullah, first and foremost thanks for finally coming up with asdoc, you have made a huge favor to all Stata users.
I am trying to produce a table reporting the proportion of respondents’ reporting a low health status (a dummy variable) by year of birth (in 5-year intervals) and age group (in 5 year age intervals). I am using the tabulate, summarize option but I keep the receiving “option summarize() not allowed” error message.
I did go through the examples using the Stata example data sets for asdoc and encounter the same issue every time I try to combine the asdoc and tab, summarize command.
I used this example and received the same error message:

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

Here is the code I am using for my dataset

asdoc tabulate cob age_cat, summarize (low_SAH) nofreq replace

where cob and age_cat are categorical variables for the year of birth and age grouping respectively.

Do you have any idea why I am having this issue? Thanks

    Attaullah Shah

    September 13, 2019at 12:50 am

    Tina
    Perhaps I had mentioned this somewhere in the comments section that asdoc currently does not support the sum option with tab commands. The reason is that when I wrote the tab commands, that took me a lot of time and I was out of motivation to work further on the tab command. I would like if someone comes along and become a patron to finance the development of this missing feature.

Elisabeth Mueller

October 16, 2019at 5:20 pm

Hi, thank you so much for the great program and helpful explanation. Is there any way to add a note at the bottom of the table?

    Attaullah Shah

    October 16, 2019at 11:58 pm

    The new beta version accepts notes.
    The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.

    net install asdoc, from(http://fintechprofessor.com) replace
    sysuse auto, clear
    asdoc sum, notes(My notes are here) replace

    Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

    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.

Elisabeth Mueller

October 18, 2019at 6:01 pm

Dear Mr. Shah, thanks a lot, this works like a charm, and is very helpful when creating many tables and updating them! Also, thank you for the reminder of how to cite asdoc.

Anand

November 2, 2019at 12:05 pm

Dear Professor Shah,

First of all, I would like to thank you for developing this wonderful asdoc programme. Asdoc is very helpful in creating high quality tables of regression and descriptive statistics. Many thanks for sharing this with the entire research community.

I am trying to create a table of descriptive statistics for a research paper. I have seen the ‘YouTube video’ where you have nicely explained the steps involved. I am able to create that table as shown above and in the video. However, I want to add a column of ‘variable definition’ (next to the ‘variable’ column) in that table.

Is there a way to do that? Thanks

Anand

November 2, 2019at 12:47 pm

Thanks for the prompt response! I’ll wait for asdocx version.

Leave a Reply

one × 5 =