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

## 4 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.