Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Combining results from separate t-tests into one table

    Dear Sirs,

    I am wondering if you can help me with the following problem; I have panel data grouped into 5 different groups and I want to combine the results (mean, p-values) from several one sample t-tests (ttest variablename == 0) into the same table. For regressions I have used the command "estimates store" after each regression and then the command "estout" in order to get all the results into one table, however I cannot use the command "estimates store" for t-tests. Does anyone have an idea how I can do this?

    Thank you in advance!

    Best regards,

    Anna

  • #2
    You can use asdoc for doing this.

    Code:
    ssc install asdoc
    sysuse auto, clear
    asdoc ttest rep78==0, replace title(T-test results : mean == 0) stat(mean p) tzok
    asdoc ttest price==0, rowappend stat(mean p) tzok
    asdoc ttest mpg==0, rowappend stat(mean p) tzok
    asdoc ttest turn==0, rowappend stat(mean p) tzok
    asdoc ttest weight==0, rowappend stat(mean p) tzok
    asdoc ttest length==0, rowappend stat(mean p) tzok
    Click image for larger version

Name:	asdoc with ttest.png
Views:	1
Size:	18.6 KB
ID:	1439221




    Notes:

    The default for reporting decimal points is to drop trailing zeros and report only valid decimal points. However, we can use the option tzok i.e. trailing zeros OK, to report equal decimal points for all values even if the trailing values are zero.

    To develop a table row by row from different runs of the asdoc, we need to use option rowappend.

    Option stat is used to get customized statistics.

    I shall encourage you to read more about asdoc. It can be used for the following tasks. More details are given in the help file, i.e. type help asdoc

    1. asdoc options

    2. Summary statistics
    2.1 Basic summary statistics
    2.2 Detailed Summary statistics
    2.3 Customized summary statistics
    2.4 By-groups summary statistics

    3. Correlations
    3.1 Simple correlations
    3.2 Pairwise / correlations with a significance level
    3.3 Partial correlations
    3.4 Interclass correlation
    3.5 Tetrachoric correlation

    4. Regressions
    4.1 Full regression tables
    4.2 Compact / nested tables (publication quality)

    5. Frequency tables
    5.1 One-way tabulation (tabulate1)
    5.2 Two-way tabulation (tabulate2)
    5.3 One- and two-way tables of summary statistics (tabsum)
    5.4 Multiple-way tables (tab1)
    5.5 All-possible two-way tables (tab2)

    6. Compact tables (tabstat)
    6.1 Without groups
    6.1 With groups

    7. Flexible table of statistics (table)
    7.1 One-way table
    7.2 Two-way table
    7.3 Three-way table
    7.4 Four-way table

    8. T-tests
    8.1 one-sample t-test
    8.2 two-sample using groups
    8.3 two-sample using variables
    8.4 paired t-test

    9. Table of means, std., and frequencies (tabsum)

    10. Means
    10.1 Arithmetic / harmonic / geometric means
    10.2 Proportions
    10.3 Ratio
    10.4 Total

    11. List command

    12. Writing matrix to a Word / RTF file

    13. The survey prefix command

    14. aslist - Create a list of unique values

    15. Describe - Export variable names and their labels

    16. Other Stata Commands



    Last edited by Attaullah Shah; 13 Apr 2018, 08:04.
    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

    Comment


    • #3
      Dear Mr. Shah,

      Thank you for your quick response!
      However, when running the commands I don't get all the t-tests in the same table in STATA or in the Word document. I have also tried to run the commands with your data file. Do you have any suggestion on how to get the results in the same table?

      Best regards,
      Anna

      Comment


      • #4
        I have posted the codes and the result files in the above post. Once all the commands are executed, you should get a table like given above. Do you need a different table? or your problem is different than this. To be more specific, please post a sample of your data using dataexfrom ssc and tell us what you typed and what Stata reported?
        Regards
        --------------------------------------------------
        Attaullah Shah, PhD.
        Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
        FinTechProfessor.com
        https://asdocx.com
        Check out my asdoc program, which sends outputs to MS Word.
        For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

        Comment


        • #5
          Dear Mr. Shah,

          I ran the regression both on my own and on your data set – all commands according to your instructions above – and I got tables like the ones below. The tables are based on your data set, so you know what the data looks like.

          Sorry if it was unclear before.

          Best regards,

          Anna

          Click image for larger version

Name:	Skärmavbild 2018-04-13 kl. 18.53.18.png
Views:	1
Size:	83.3 KB
ID:	1439255
          Click image for larger version

Name:	Skärmavbild 2018-04-13 kl. 18.53.41.png
Views:	1
Size:	70.0 KB
ID:	1439256
          Click image for larger version

Name:	Skärmavbild 2018-04-13 kl. 18.54.00.png
Views:	1
Size:	75.3 KB
ID:	1439257

          Comment


          • #6
            And when the final command for length == 0 completes, it generates the link Myfile.doc, you click on this link, does it not create a table that I showed in my post #2 above. If it generates the said table, then is it not something that you had asked for?
            Regards
            --------------------------------------------------
            Attaullah Shah, PhD.
            Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
            FinTechProfessor.com
            https://asdocx.com
            Check out my asdoc program, which sends outputs to MS Word.
            For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

            Comment


            • #7
              Attaullah Shah I am trying to create a nested table for t-test. My command is as under:

              ttest var1 if var2>=1 & var3==1 , by(var4)

              I used asdoc *, stat( ) but it gives all the estimates in one row. I need a table in the following format. Is it possible using asdoc?

              Model 1
              Panel A.
              group 1 0.406
              (0.006)
              group 2 0.373
              (0.006)
              Difference (1) – (2) 0.031***
              (0.008)
              Observations 11965

              Alternatively, i have used ttab and estout. This generates the above table but i can't export it to word. The 'tofile' command specified in the options of ttab isn't working for me. can anyone help?

              ttab var1 if var2>=1 & var3==1 , by(var4) estout(c(b(fmt(3) star) se(fmt(3) par))

              Comment


              • #8
                If you need a more customized table, you can use the row() option of asdoc. Here is one example. You can also find this discussion useful

                Code:
                ttest price if turn>=1 & rep78>2 , by(foreign )
                
                * Get the relevant statistics
                loc mean1 = `r(mu_1)'
                loc mean2 = `r(mu_2)'
                loc sd1 = `r(sd_1)'
                loc sd2 = `r(sd_2)'
                loc dif = `mean1' - `mean2'
                loc obs = `r(N_1)' + `r(N_2)' 
                dis `dif'
                * Write these with asdoc using the row option
                asdoc, row(\i, Model 1) replace
                asdoc, row(Panel A, \i)
                
                asdoc, row(Group 1, `mean1')
                asdoc, row(\i, `sd1')
                asdoc, row(Group 2, `mean2')
                asdoc, row(\i, `sd2')
                asdoc, row(Difference [1] - [2] , `dif' )
                asdoc, row(Observations, `obs')
                Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	12.5 KB
ID:	1508697
                Regards
                --------------------------------------------------
                Attaullah Shah, PhD.
                Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                FinTechProfessor.com
                https://asdocx.com
                Check out my asdoc program, which sends outputs to MS Word.
                For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                Comment


                • #9
                  Attaullah Shah
                  Is there a way to set a variable equal to something other than 0, like the sample mean, when doing a one-sample t-test?
                  Last edited by Molly Hyde; 08 Apr 2020, 12:04.

                  Comment


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


                    Example from the updated version

                    Code:
                    . ttest mpg == 21
                    
                    One-sample t test
                    ------------------------------------------------------------------------------
                    Variable |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
                    ---------+--------------------------------------------------------------------
                         mpg |      74     21.2973    .6725511    5.785503     19.9569    22.63769
                    ------------------------------------------------------------------------------
                        mean = mean(mpg)                                              t =   0.4420
                    Ho: mean = 21                                    degrees of freedom =       73
                    
                        Ha: mean < 21               Ha: mean != 21                 Ha: mean > 21
                     Pr(T < t) = 0.6701         Pr(|T| > |t|) = 0.6598          Pr(T > t) = 0.3299
                    
                    
                    asdoc ttest mpg == 21
                    
                                        One-sample t test for mpg
                    
                    -------------------------------------------------------------------------
                                     |       obs       Mean     St_Err    t_value    p_value
                    -----------------+-------------------------------------------------------
                                 mpg |        74    21.2975      .6725       .442        .66
                    -------------------------------------------------------------------------
                    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.
                    Regards
                    --------------------------------------------------
                    Attaullah Shah, PhD.
                    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                    FinTechProfessor.com
                    https://asdocx.com
                    Check out my asdoc program, which sends outputs to MS Word.
                    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                    Comment


                    • #11
                      Attaullah Shah Works like a charm -- thank you so much!

                      Comment

                      Working...
                      X