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 ttest , we can use the following options of asdoc to control asdoc behavior.

(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 stats and rowappend are discussed below:

 

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 or few statistics using the stat option. The following table lists the keywords and their details for reporting the desired statistics.

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 a ttest for each of the 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.

 


30 Comments

  1. Jeff D April 23, 2019 at 5:39 am - Reply

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

  2. Attaullah Shah April 24, 2019 at 12:13 am - Reply

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

  3. Andre Moura April 29, 2019 at 10:49 pm - Reply

    Hello 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

  4. Attaullah Shah April 30, 2019 at 12:25 am - Reply

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

  5. pooja July 22, 2019 at 6:53 pm - Reply

    hello sir could i have your email

  6. Felix Quinones September 20, 2019 at 10:49 pm - Reply

    Hello 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:

    asdoc tab q12, missing save(syep_2019.doc) title(Are your grades in school mostly)?)  

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

    asdoc ttest q14_a==1 if poor_zones, ///
    stat(mean se df obs t p sd dif) save(syep_2019.doc) ///
    title(The SYEP helped me)

    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:

  7. Felix Quinones September 20, 2019 at 10:49 pm - Reply

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

  8. David October 1, 2019 at 1:20 am - Reply

    Hello,

    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:

    asdoc ttest panel_data_pre == panel_data_post, replace 

    the error says:

    panel_data_pre - panel_data_post    invalid name
    r(198);

    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, 2019 at 6:14 am - Reply

      David
      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

      set obs 100
      gen Data_Pre  = runiform()
      gen Data_Post = runiform()
      asdoc ttest Data_Pre == Data_Post, replace
  9. George October 8, 2019 at 11:28 am - Reply

    Attaullah 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?

    foreach var in  $vars {
    asdoc quietly ttest `var'==0 if group==0, rowappend stat(obs mean se df p t) dec(3)
    }
    • Attaullah Shah October 8, 2019 at 11:50 am - Reply

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

      sysuse auto, clear
      asdoc ttest rep78==0, stat(obs mean se df t) dec(4)
      asdoc ttest price==0, stat(obs mean se df t) dec(4) rowappend

      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.

  10. George October 10, 2019 at 3:57 am - Reply

    Thanks a lot Shah!

  11. Anna Meier October 11, 2019 at 5:34 pm - Reply

    Hello, the following command

    asdoc ttest var1, by(var2) label append stat(mean sd t p) title (xyz)

    Gives me the following error message

     asdoctable(): 3301 subscript invalid : - function returned error“

    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, 2019 at 10:01 pm - Reply

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

      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.

  12. Anna Meier October 13, 2019 at 6:15 pm - Reply

    Thank 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, 2019 at 6:47 pm - Reply

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

  13. Anna Meier October 17, 2019 at 1:05 pm - Reply

    Thank you for your answer and sorry for not being clearer in my previous response!
    The command

    asdoc ttest var1, by(var2) label stat(mean sad t p) dec(3) append title(„xyz“) 

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

  14. Pedro Coelho December 5, 2019 at 6:04 pm - Reply

    Is there a way to include significance stars in one sample ttest?
    Tahks in advance

  15. Attaullah Shah December 5, 2019 at 6:36 pm - Reply

    Pedro Coelho
    Currently, stars are not available for ttests. I shall add them in the asdocx package. You can see the updates on asdocx here http://fintechprofessor.com/asdocx

  16. Steven December 6, 2019 at 1:57 am - Reply

    Can asdoc accomodate unpaired ttests?

  17. Thomas December 9, 2019 at 7:57 pm - Reply

    Hi there,
    I wanted to apply ttest y, by(x) and report difference across the group x. How would I use asdoc on this occassion?

  18. Attaullah Shah December 10, 2019 at 7:14 pm - Reply

    Thomas, you just simply add asdoc to the ttest command
    example

    sysuse auto, clear
    asdoc ttest price, by(foreign) replace
  19. Thomas December 11, 2019 at 2:11 am - Reply

    Thank you Prof. This is the message I get from STATA
    “matrix accum not found”

  20. Attaullah Shah December 11, 2019 at 7:25 am - Reply

    Thomas
    Please install the latest version of asdoc and if the problem persists, then please send a sample of your dataset and the Stata code that reproduces the error.
    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.

  21. Molly April 8, 2020 at 9:54 pm - Reply

    Hi Prof. Love this tool. Is there a way asdoc can report the two-tailed p-value when computing a one-sample t-test?

  22. Attaullah Shah April 8, 2020 at 10:47 pm - Reply

    Molly
    If you type

    help asdoc

    it opens the asdoc help file. In Section 8, I have listed various options that can be used with the ttest. For reporting p-values, you can use the stat(p) option. See the following examples:

    sysuse auto, clear
    asdoc ttest rep78==0, replace   stat(obs mean se df t p) title(T-test results : mean == 0) 
    asdoc ttest price==0, rowappend stat(obs mean se df t p)
    asdoc ttest mpg==0,   rowappend stat(obs mean se df t p)
    
               
                                T-test results : mean == 0
        +------------------------------------------------------------------------------+
        |                 obs       Mean     St_Err         df    t_value     p_value  |
        +==============================================================================+
        |     rep78         69      3.406       .119         68     28.579      0.000  |
        |     price         74   6165.257    342.872         73     17.981      0.000  |
        |       mpg         74     21.297       .672         73     31.666      0.000  |
        +------------------------------------------------------------------------------+
  23. Molly April 8, 2020 at 11:21 pm - Reply

    Hi Prof. Thanks for the quick reply. I realized my issue was not with reporting p-value but rather that I’m having an issue with setting the first variable equal to something other than 0. For example, I’d like to be able to do this:

    asdoc ttest instruct_avg==1.61 if CBO_n==1

    But the t-value and p-value it reports appear as if instruct_avg had been ==0. Do you have any insight?

    • Attaullah Shah April 9, 2020 at 7:51 pm - Reply

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

      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.

  24. Nick April 22, 2020 at 11:15 pm - Reply

    Hellow
    i’m runnig this foreach loop who works well.

    local Dingreso ingreso_1 ingreso_2 ingreso_3 ingreso_4 /// 
    ingreso_5 ingreso_6 ingreso_7 ingreso_8 ingreso_9 ingreso_10 ingreso_11 ///
    ingreso_12 ingreso_13 ingreso_14 ingreso_15 
    local Dgen_alu gen_alu_1 gen_alu_2
    local Dcod_reg_rbd cod_reg_rbd_1 cod_reg_rbd_2 cod_reg_rbd_3 cod_reg_rbd_4 ///
     cod_reg_rbd_5 cod_reg_rbd_6 cod_reg_rbd_7 cod_reg_rbd_8 cod_reg_rbd_9 ///
    cod_reg_rbd_10 cod_reg_rbd_11 cod_reg_rbd_12 cod_reg_rbd_13 cod_reg_rbd_14 cod_reg_rbd_15
    local Dcod_depe2 cod_depe2_1 cod_depe2_2 cod_depe2_3
    local Dcod_grupo cod_grupo_1 cod_grupo_2 cod_grupo_3 cod_grupo_4 cod_grupo_5
    local Dcod_rural_rbd cod_rural_rbd_1 cod_rural_rbd_2
    local Du `Dingreso' `Dgen_alu' `Dcod_reg_rbd' `Dcod_depe2' `Dcod_grupo Dcod_rural' `Dcod_rural_rbd'
    
    foreach v in `Du' {
      foreach var in `v' { 
        di _n "Variable = `var'"
        ttest `var', by(Tmg), if agno==2016 
    	
        }
    }

    Now i would like to include in the loop the command asdoc to export a ttest table including all the variables in the loop. I tried in this way: ”

     foreach v in `Du' {
       foreach var in `v' { 
        di _n "Variable = `var'"
        ttest `var', by(Tmg), if agno==2016 
    	 foreach e in `var' {
    	   asdoc ttest `e', by(Tmg), if agno==2016, rowappend 
            }
         }
    }


    But the loop stops after the first variable ttest and reports this error: “invalid ‘sep'”

    Do you know how to solve it?
    or another way to export the desired table using a foreach loop?
    Regards.
    Nick.

    • Attaullah Shah April 23, 2020 at 2:42 pm - Reply

      If you can send me your data, I can better pinpoint the problem. Looking at the loop, I can see that you are using three commas. Stata allows only one comma to separate the main command and options. This line should be:

      asdoc ttest `e' if agno==2016, by(Tmg) rowappend 

Leave A Comment