Announcement

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

  • Publication table for two-sample t-tests

    Hi,

    Is there a way to produce publication style tables for two-sample t-test results (similar to outreg or estout/esttab for regression estimates)? I would want the table to include the means for each gruop, difference in means, p-value for two-tailed and both one-tailed tests.

    Thanks,

    Sumayyah

  • #2
    You could write a simple program like this example.
    Code:
    sysuse nlsw88
    
    tempname fh
    
    file open `fh' using results.csv, write text replace
    
    file write `fh' "Variable ,Mean for nonunion , Mean for union ,Diff. ,p (lower 1-tailed) ,p (2-tailed)" _newline
    
    foreach v of varlist wage hours tenure {
    
        ttest `v', by(union) unequal
    
        file write `fh' "`: var lab `v'', `r(mu_1)', `r(mu_2)' , `=r(mu_1)-r(mu_2)' , `r(p_l)' , `r(p)'" _newline
    
        }
    
    file close `fh'
    This example creates a comma-separated text file, which I prefer because I can just double-click the file to open in Excel, but you have to watch out for commas in your variable labels.

    With a little additional programming, you can add rounding and formatting, calculate the absolute value of the difference, add asterisks to indicate statistical significance levels, and more.
    David Radwin
    Senior Researcher, California Competes
    californiacompetes.org
    Pronouns: He/Him

    Comment


    • #3
      I should add that as a statistical matter, you probably don't want to use or report the results of a 2-tailed t-test and either or both 1-tailed t-tests for the same comparison.

      I suggest that if you want to provide evidence that one mean is greater than the other mean, use the appropriate 1-tailed t-test (but not both 1-tailed t-tests). If you want to provide evidence that the two means are different, use a 2-tailed test. Your hypothesis will guide your selection of test statistic before you conduct the statistical test.
      David Radwin
      Senior Researcher, California Competes
      californiacompetes.org
      Pronouns: He/Him

      Comment


      • #4
        Thank you David.

        My research hypothesis assumes a direction (based on existing literature and empirical studies) and so I have formulated the statistical hypothesis as follows:
        Null - no difference in means
        Alternative - mean in group X > mean in group Y

        Where the two-tailed test comes back significant (say at the 5%) and I can reject the null of no difference, is it not okay to then look at the one-tailed test for both sides to see which direction is evident in the data?

        Comment


        • #5
          Yes, but before you do a statistical test you can tell from the data whether the mean of X is larger or smaller than the mean of Y. As a practical matter, if you use ttest to both calculate the difference and perform the statistical test at the same time, you can see the difference in the results in row labelled "diff."
          Code:
          . sysuse nlsw88
          (NLSW, 1988 extract)
          
          . ttest wage, by(union)
          
          Two-sample t test with equal variances
          ------------------------------------------------------------------------------
             Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
          ---------+--------------------------------------------------------------------
          nonunion |   1,417    7.204669    .1090159    4.103694    6.990819    7.418519
             union |     461    8.674294    .1944277    4.174539    8.292218    9.056371
          ---------+--------------------------------------------------------------------
          combined |   1,878    7.565423    .0961874    4.168369    7.376778    7.754069
          ---------+--------------------------------------------------------------------
              diff |           -1.469625    .2209702               -1.902999   -1.036252
          ------------------------------------------------------------------------------
              diff = mean(nonunion) - mean(union)                           t =  -6.6508
          Ho: diff = 0                                     degrees of freedom =     1876
          
              Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
           Pr(T < t) = 0.0000         Pr(|T| > |t|) = 0.0000          Pr(T > t) = 1.0000
          David Radwin
          Senior Researcher, California Competes
          californiacompetes.org
          Pronouns: He/Him

          Comment

          Working...
          X