## Exporting ttest results from Stata to Word using asdoc

Category:asdoc,Blog,Stata Programs,Uncategorized### asdoc installation

If you have not already studied the features of asdoc, you can visit this page that lists the table of contents of what asdoc can do. You can also read this one paragraph introduction to asdoc. The following line of code will install asdoc from SSC

ssc install asdoc

help asdoc

## Reporting t-tests with asdoc

Before we make the t-test results table for our example data, let us breifly explore the options available in asdoc for making a t-test results table.

Whether it is one-sample t-test or two-sample or other forms, asdoc manages to report the results line by line for each test. asdoc also allows accumulating results from different runs of t-tests. For this purpose, the option **rowappend **of asdoc really comes handy. With the sub-command

(1) replace / append

(2) save(filename)

(3) title(text)

(4) fs(#)

(5) hide.

(6) stats()

(7) rowappend.

These options are discussed in detail in Section 1 of asdoc help file

### Option stat()

Without stat() option, asdoc reports the number of observations (obs), mean, standard error, t-value, and p-value with t-tests. However, we can select all

keyword | details |

n | Number of observations |

mean | Arithmetic mean |

se | Standard error |

df | degrees of freedom |

obs | Number of observations |

t | t-value |

p | p-value |

sd | standard deviation |

dif | difference in means if two-sample t-test |

### Option rowappned

ttest tables can be constructed in steps by adding results of different t-tests to an existing table one by one using option **rowappend**. There is only one limitation that the t-tests are performed and asdoc command applied without writing any other results to the file in-between.

## An example

Suppose we have the following data set with variables r0, r1, r2, r3, and y. The data can be downloaded into Stata by

use http://fintechprofessor.com/ttests.dta, clear

The variables * ro-r3* are the numeric variables for which we would like to conduct one-sample ttest whereas variable

*y*is a numeric date variable that tracks years. We wish to conduct

*r0-r3*variables and in each year and make one table from all such tests.

### Without using a loop

asdoc ttest R0==0 if Y==2009, replace title(One Sample t-test Results)

asdoc ttest R1==0 if Y==2009, rowappend

asdoc ttest R2==0 if Y==2009, rowappend

asdoc ttest R3==0 if Y==2009, rowappend

asdoc ttest R0==0 if Y==2010, rowappend

asdoc ttest R1==0 if Y==2010, rowappend

asdoc ttest R2==0 if Y==2010, rowappend

asdoc ttest R3==0 if Y==2010, rowappend

asdoc ttest R0==0 if Y==2011, rowappend

asdoc ttest R1==0 if Y==2011, rowappend

asdoc ttest R2==0 if Y==2011, rowappend

asdoc ttest R3==0 if Y==2011, rowappend

asdoc ttest R0==0 if Y==2012, rowappend

asdoc ttest R1==0 if Y==2012, rowappend

asdoc ttest R2==0 if Y==2012, rowappend

asdoc ttest R3==0 if Y==2012, rowappend

And appreciate the results

## Explanation

1.In the first line of code, we wrote asdoc ttest in the beggining of the line. This is how we use asdoc with Stata commands. We just add asdoc to the beggining of any Stata command and that’s all.

2. We used two options of asdoc in the first line of code: the replace and **title()**. Replace will replace any existing file with the name **Myfile.doc** and title will add the specific test as a title to the output file.

3. In the second line of code, we added option **rowappend()** that will append the results to the existing table in the file **Myfile.doc**

4. And the process continues untill all ttests are estimated.

## 17 Comments

## Jeff D

April 23, 2019at 5:39 amHello Dr. Shah, thank you so much for creating this program. This is such an amazing contribution. I am using asdoc to perform t-tests and I was wondering if there was any way to further customize the stats that are being reported. Namely, I was wondering if I could get obs, means, SDs for each of my two groups, as well as confidence intervals for the mean diff.

## Attaullah Shah

April 24, 2019at 12:13 amJeff D

Thanks for your comments. For customized statistics, you can use the option stat() as shown above in the post. However, confidence intervals are not yet available in asdoc with ttest commands.

## Andre Moura

April 29, 2019at 10:49 pmHello There,

Thank you for this program. Is there a way a could report one-tailed t tests statistics? Currently the program reports are two-tailed.

Thanks

## Attaullah Shah

April 30, 2019at 12:25 amAndre Moura

I did not think of it before, thanks for the suggestion. I shall consider your suggestion in future updates.

## pooja

July 22, 2019at 6:53 pmhello sir could i have your email

## Felix Quinones

September 20, 2019at 10:49 pmHello Dr. Shah,

Hope you are doing fine. First, I want to thank you for the creation of ASDOC.

My question is related to a simple the tabulate command and the ttest command.

For the tabulate, I will like to see a table with the total and the end. I’m using the following code:

For the ttest, I’m trying to use the following command:

With the tabulate, the table in the word document is not showing the total at the button of the table. The t test is giving me the error:

## Felix Quinones

September 20, 2019at 10:49 pmI discovered my mistake.

I was needing to install the last version of asdoc to see the totals. In addition, I was coding incorrectly the Ttest.

ASDOC is awesome!

Thanks,

Felix.

## David

October 1, 2019at 1:20 amHello,

I was trying to use asdoc command with paired t-test but I am getting an error that I could not fix.

Here is my line of code:

the error says:

When I put abb(4) in the code as an option, still I am getting the same error. I read the help file but haven’t found any solution.

Thanks for any help.

## Attaullah Shah

October 1, 2019at 6:14 amDavid

The problem is caused by the lengthy names of your variables. Stata matrices do not allow lengthy names. When I shorten the names by a few letters, the command works fine. See this example

## George

October 8, 2019at 11:28 amAttaullah you are a genius. Thanks for this handy code. I have a question. How can we control the decimal places for the t-statistics? What if I want to see 4 decimals for the statistics. The code below tests whether a variable is significantly different from zero for a specific group. How can I show more decimal places for the t-statistics and the p-values?

## Attaullah Shah

October 8, 2019at 11:50 amGeorge

Thanks for your kind words. I have revised asdoc to report customized decimal points with the t-values in ttests. For example,

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.

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.

## George

October 10, 2019at 3:57 amThanks a lot Shah!

## Anna Meier

October 11, 2019at 5:34 pmHello, the following command

Gives me the following error message

If I use the same command with the option stat(mean t p), no error message occurs. I am using asdoc on mac, could that be an issue?

## Attaullah Shah

October 11, 2019at 10:01 pmAnna Meier

I have fixed the error. 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.

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.

## Anna Meier

October 13, 2019at 6:15 pmThank you or your quick response and fixing the problem! Unfortunately, after having updated the version, my command from the earlier post does not retrieve the results for the scalar r(t) anymore for a two-sample t test but for a one-sample t test. Has that something to do with the update of the command asdoc?

## Attaullah Shah

October 13, 2019at 6:47 pmAnna Meier

asdoc runs several programs internally to get various statistics, and there are chances that the r() and e() macros left behind by some Stata commands are over-written in this process. Therefore, if you need to get these stats, then you can run the Stata commands without asdoc prefix. So, this way you need to run the commands twice, i.e. once with asdoc and then without asdoc.

## Anna Meier

October 17, 2019at 1:05 pmThank you for your answer and sorry for not being clearer in my previous response!

The command

runs a one-sample t test instead of a two-sample ttest since the last update of asdoc.