Announcement

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

  • Formatting test of means table

    Hello all,

    I would like to recreate as much as possible the following table (wih different variables):


    I have managed to get most of the way using the following code:



    . do "C:\Users\Kris\AppData\Local\Temp\STD5320_000000.t mp"

    . eststo lessthan15: quietly estpost summarize SALES_REV_TURN-SHORT_AND_LONG_TERM_DEBT if ave15 == 0, detail

    . eststo morethan15: quietly estpost summarize SALES_REV_TURN-SHORT_AND_LONG_TERM_DEBT if ave15 == 1, detail

    . eststo diff: quietly estpost ttest SALES_REV_TURN-SHORT_AND_LONG_TERM_DEBT, by(ave15) unequal

    . esttab lessthan15 morethan15 diff, cells("mean(pattern(1 1 0) fmt(3)) sd(pattern(1 1 0)) median(pattern(1 1 0)) b(star pattern(0 0 1) fmt(3)) t(patt
    > ern(0 0 1) par fmt(3))")


    However, as you can see from my results I am missing column names for 1, 2 and 3, as well as a title line, and explanatory line as above. I am also missing the median.




    Any help would be greatly appreciated,

    Kayleigh



  • #2
    estout is from SSC (FAQ Advice #12). If you remove the -quietly- prefix, you can see how estout labels the statistics. The median is the 50th percentile and is stored as "p50".

    Code:
    sysuse auto, clear
    eststo lessthan15: quietly estpost summarize mpg weight turn if !foreign, detail
    eststo morethan15: quietly estpost summarize mpg weight turn if foreign, detail
    eststo diff: quietly estpost ttest mpg weight turn, by(foreign) unequal
    
    esttab lessthan15 morethan15 diff, label collab(, lhs("Variables")) ///
    cells("mean(pattern(1 1 0) fmt(3) label(Mean)) sd(pattern(1 1 0) label(SD)) p50(pattern(1 1 0) label(Median) fmt(a3)) b(star pattern(0 0 1) fmt(3) label(Diff.)) t(pattern(0 0 1) par fmt(3) label(t-stat.))")  ///
    title("T-test of comparisons of means`=char(10)'Some additional information") nonumbers mtitles("Group 1" "Group 2" "Comparison")
    Res.:

    Code:
    T-test of comparisons of means
    Some additional information
    -------------------------------------------------------------------------------------------------------------------------------
                              Group 1                                Group 2                             Comparison                
    Variables                    Mean           SD       Median         Mean           SD       Median        Diff.         t-stat.
    -------------------------------------------------------------------------------------------------------------------------------
    Mileage (mpg)              19.827        4.743           19       24.773        6.611        24.50       -4.946**      (-3.180)
    Weight (lbs.)            3317.115      695.364         3360     2315.909      433.003         2180     1001.206***      (7.500)
    Turn Circle (ft.)          41.442        3.968           42       35.409        1.501           36        6.033***      (9.479)
    -------------------------------------------------------------------------------------------------------------------------------
    Observations                   52                                     22                                     74                
    -------------------------------------------------------------------------------------------------------------------------------
    Last edited by Andrew Musau; 07 Apr 2022, 10:38.

    Comment


    • #3
      Thanks again Andrew! This worked perfectly

      Comment


      • #4
        Hello, I used the command for a similar test that I am doing and it works perfectly; however, the table does not show the p-value
        Can you pls let me know where i can add the pval command

        Comment


        • #5
          Code:
          sysuse auto, clear
          eststo lessthan15: quietly estpost summarize mpg weight turn if !foreign, detail
          eststo morethan15: quietly estpost summarize mpg weight turn if foreign, detail
          eststo diff: quietly estpost ttest mpg weight turn, by(foreign) unequal
          
          esttab lessthan15 morethan15 diff, label collab(, lhs("Variables")) ///
          cells("mean(pattern(1 1 0) fmt(3) label(Mean)) sd(pattern(1 1 0)label(SD)) p50(pattern(1 1 0) label(Median) fmt(a3)) b(pattern(0 0 1) fmt(3) label(Diff.)) t(pattern(0 0 1) par fmt(3) label(t-stat.)) p(pattern(0 0 1)fmt(3) label(p-value))")  ///
          title("T-test of comparisons of means`=char(10)'Some additional information") ///
          nonumbers mtitles("Group 1" "Group 2" "Comparison") substitute(0.000 "<0.001") 
          Res.:

          Code:
          . esttab lessthan15 morethan15 diff, label collab(, lhs("Variables")) ///
          > cells("mean(pattern(1 1 0) fmt(3) label(Mean)) sd(pattern(1 1 0)label(SD)) p50(pattern(1 1 0) label(Median) fmt(a3)) b(pattern(0 0 1) fmt(3) 
          > label(Diff.)) t(pattern(0 0 1) par fmt(3) label(t-stat.)) p(pattern(0 0 1)fmt(3) label(p-value))")  ///
          > title("T-test of comparisons of means`=char(10)'Some additional information") ///
          > nonumbers mtitles("Group 1" "Group 2" "Comparison") substitute(0.000 "<0.001") 
          
          T-test of comparisons of means
          Some additional information
          -----------------------------------------------------------------------------------------------------------------------------------------
                                    Group 1                                Group 2                             Comparison                          
          Variables                    Mean           SD       Median         Mean           SD       Median        Diff.      t-stat.      p-value
          -----------------------------------------------------------------------------------------------------------------------------------------
          Mileage (mpg)              19.827        4.743           19       24.773        6.611        24.50       -4.946     (-3.180)        0.003
          Weight (lbs.)            3317.115      695.364         3360     2315.909      433.003         2180     1001.206      (7.500)        <0.001
          Turn Circle (ft.)          41.442        3.968           42       35.409        1.501           36        6.033      (9.479)        <0.001
          -----------------------------------------------------------------------------------------------------------------------------------------
          Observations                   52                                     22                                     74                          
          -----------------------------------------------------------------------------------------------------------------------------------------

          Comment


          • #6
            thank you so much!

            Comment

            Working...
            X