Announcement

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

  • The p-value of a two-sided t-test.

    Dear all
    I have two group based on dummy variable. I have the mean, standard deviation, minimum and maximum. Please, how can I get the average value for each group for each variable as well as the p-value of a two-sided t-test. Thanks a lot.

  • #2
    Run -help tttest- and then look specifically at the instructions for -ttesti-, which is the command that will do this.

    Comment


    • #3
      Thanks Clyde.
      I did it as you have mentioned. Please , I have two following questions :
      1-) I got this table, but I do not know the interpretations for the values below the tables - I mean the p-value and other things.
      2-) because I have too many variables , and when i run the code stata give me this message -too many variables specified
      r(103);-.

      Two-sample t test with equal variances
      ------------------------------------------------------------------------------
      Group | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
      ---------+--------------------------------------------------------------------
      0 | 468 .0426858 .0023686 .051241 .0380313 .0473403
      1 | 51 .0705214 .0122765 .0876716 .0458633 .0951794
      ---------+--------------------------------------------------------------------
      combined | 519 .0454211 .0024745 .0563724 .0405599 .0502823
      ---------+--------------------------------------------------------------------
      diff | -.0278356 .0082302 -.0440043 -.0116668
      ------------------------------------------------------------------------------
      diff = mean(0) - mean(1) t = -3.3821
      Ho: diff = 0 degrees of freedom = 517

      Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
      Pr(T < t) = 0.0004 Pr(|T| > |t|) = 0.0008 Pr(T > t) = 0.9996

      Comment


      • #4
        Hello Marco. I'm a bit confused. You say you have "the mean, standard deviation, minimum and maximum". Do you mean you have the mean and SD for each of two groups? Or do you just have the overall mean & SD?

        In order to use the -ttesti- command Clyde directed you to, you need n, mean and SD for each group separately.

        Code:
            Immediate form of two-sample t test
        
                ttesti #obs1 #mean1 #sd1 #obs2 #mean2 #sd2 [, options2]
        HTH.
        Last edited by Bruce Weaver; 18 Aug 2021, 15:36. Reason: Crossed with Marco's response to Clyde in #3. Apparently, he did have n, mean and SD for each of two samples!
        --
        Bruce Weaver
        Email: [email protected]
        Version: Stata/MP 18.5 (Windows)

        Comment


        • #5
          Originally posted by Marco Stefano View Post
          2-) because I have too many variables , and when i run the code stata give me this message -too many variables specified
          r(103);-.
          Marco, please review the FAQ, and pay attention especially to item 12.
          --
          Bruce Weaver
          Email: [email protected]
          Version: Stata/MP 18.5 (Windows)

          Comment


          • #6
            Hello Bruce. Thank you.
            Please, I am not professional in stata, so please let me explain to you and Clyde What I mean and What I did.
            Well,I have dummy variable equal 1 Financial firms and 0 Non financial firms. I have the "the mean, standard deviation, minimum and maximum" on the whole sample by using sim Varlist.
            I need to have the "the mean, standard deviation, minimum and maximum" for each variable for each group and my advisor said the most important thing is to get the p-value of a two-sided t-test. So, I do not know how to do that in stata. Thanks a lot.

            Comment


            • #7
              Hi Marco. Unfortunately, I am still confused. See item 12.2 in the FAQ, and then use -dataex- to share part of your data file so that we can see what you are working with. And use code delimiters (described in item 12.3) to show us the code that you used to generate the output shown in post #3. Thanks.
              --
              Bruce Weaver
              Email: [email protected]
              Version: Stata/MP 18.5 (Windows)

              Comment


              • #8
                Hi Bruce. Much appreciated. Thanks. I am attaching an example of my dateset and the Code that I have used in post #3.
                input long FirmID int Year float GroupDum double(X1 X2 X3 X4)
                16834 2019 1 .00187057616284 .03227519259037 . .
                28881 2019 1 .01879157025818 .24420714913271 .08256095890757001 .
                47718 2019 1 .004117736957 .07457386438763 .00152085132479 .06587418795537
                44868 2019 1 .00206467586212 .0371636441709 . .00024022278439
                19945 2019 1 .00543650574791 .3632171757673 .00152085132479 .00157275263716
                43997 2019 1 .01133497425939 .1485511346097 .00861740721532 .
                95684 2019 0 .00531338568905 .08329652934095 .01076756420894 .013895406372050001
                30185 2019 0 .00760396995359 .12694083462574 .0048863140689 .009659249274450001
                43311 2019 0 .00460111177885 .06538564184681 .004 .01273170731707
                93365 2019 0 .0038733683775299997 .06452755556867 .00637488439329 .0124602662646
                95327 2019 0 .00620271379122 .09930199086515 .00567095530305 .010790814636199998
                43411 2019 0 .008620147571359999 .12674961884621 .00464114012391 .01930897129284
                95358 2019 0 .00880273120363 .12493727683278999 .0062048617691 .008545996252080001
                44316 2019 0 .00959606102855 .07505896135285 .01204197047347 .02151867987044
                43887 2019 0 .010479624700479999 .07478326311673 .012166751430210001 .01999058994054
                45107 2019 0 .01074533090408 .07396482914934001 .01422433450121 .02687423173089
                95392 2019 0 .020411725999439998 .15811246997683 .05822342464209 .05878705895615
                32560 2019 0 .00791720482413 .05360590573538 .03614740172242 .037201945046580004
                19556 2019 1 .00971518215784 .03911845750316 .07802252250294 .14384789124989
                95435 2019 1 .00496310616646 .052071462090229996 .05374644056271 .15551872157763
                23598 2019 1 .00719372453085 .07868924918168001 .03617625275387 .05098395209962
                95264 2019 1 -.01678346515395 -.15704737966964 .08062779760892999 .21120665232572
                31687 2019 0 .023223787167449998 .14720761829183998 .03812014582343 .07592328419718
                ------------------.
                ttest X1, by(GroupDum)

                Comment


                • #9
                  OK, so the output of that command applied to the example data is:

                  Code:
                  . ttest X1, by(GroupDum)
                  
                  Two-sample t test with equal variances
                  ------------------------------------------------------------------------------
                     Group |     Obs        Mean    Std. err.   Std. dev.   [95% conf. interval]
                  ---------+--------------------------------------------------------------------
                         0 |      13    .0097993    .0016016    .0057748    .0063096     .013289
                         1 |      10    .0048705    .0028889    .0091355   -.0016647    .0114056
                  ---------+--------------------------------------------------------------------
                  Combined |      23    .0076563    .0015958    .0076533    .0043468    .0109659
                  ---------+--------------------------------------------------------------------
                      diff |            .0049289    .0031144               -.0015479    .0114056
                  ------------------------------------------------------------------------------
                      diff = mean(0) - mean(1)                                      t =   1.5826
                  H0: diff = 0                                     Degrees of freedom =       21
                  
                      Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
                   Pr(T < t) = 0.9358         Pr(|T| > |t|) = 0.1285          Pr(T > t) = 0.0642
                  The output is actually pretty self explanatory. But for guidance, I have put the two group means in red, and the two-tailed t-test of group mean equality in blue. The standard errors in each group are to the right of the group means, and the standard deviations to the right of those.

                  To get the minimum and maximum of the outcome in each group, which are not part of the -ttest- output, you can do this:
                  Code:
                  by GroupDum, sort: summ X1

                  Comment


                  • #10
                    Thanks a lot Clyde. I have got it. Thanks

                    Comment

                    Working...
                    X