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