Announcement

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

  • T-Test for group means comparison when there are 3 groups

    Hi all, I have microdata and respondents have been divided between 3 groups- A, B and C. I want to compare group means of A and C as well as A and B.
    Here's some more info:
    A question was asked in the survey "Are you employed in XYZ company". Those who said yes are Group A, Those who said No are Group B, Those who didn't answer this question at all and those who answered No are combined in group C. Essentially, Groups A and B are mutually exclusive and So are groups A and C. But Group B is contained in group C.
    I want to compare group means of A and B and also A and C. I was able to do it for A and C with a simple T test:
    t test outcome, by (group_a)
    How do I do this for group A and B?

  • #2
    Welcome to the Stata Forum / Statalist,

    Please read the FAQ. There you'll find advice about sharing data/command/output.

    You didn't provide an example to work with. Therefore, I decided to share a toy example:

    Code:
    . sysuse auto
    (1978 Automobile Data)
     
    . tab rep78, missing
    
         Repair |
    Record 1978 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |          2        2.70        2.70
              2 |          8       10.81       13.51
              3 |         30       40.54       54.05
              4 |         18       24.32       78.38
              5 |         11       14.86       93.24
              . |          5        6.76      100.00
    ------------+-----------------------------------
          Total |         74      100.00
    
    . gen myrep = rep78 >=3 & !missing(rep78)
    
    . replace myrep = 2 if rep78 ==.
    (5 real changes made)
    
    . tab myrep
    
          myrep |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |         10       13.51       13.51
              1 |         59       79.73       93.24
              2 |          5        6.76      100.00
    ------------+-----------------------------------
          Total |         74      100.00
    
     
    . ttest mpg if myrep <2, by(myrep)
    
    Two-sample t test with equal variances
    ------------------------------------------------------------------------------
       Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
    ---------+--------------------------------------------------------------------
           0 |      10        19.5    1.166667    3.689324    16.86082    22.13918
           1 |      59    21.59322    .7982003    6.131093    19.99545    23.19099
    ---------+--------------------------------------------------------------------
    combined |      69    21.28986    .7062326    5.866408    19.88059    22.69912
    ---------+--------------------------------------------------------------------
        diff |            -2.09322    2.004857               -6.094931     1.90849
    ------------------------------------------------------------------------------
        diff = mean(0) - mean(1)                                      t =  -1.0441
    Ho: diff = 0                                     degrees of freedom =       67
    
        Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
     Pr(T < t) = 0.1501         Pr(|T| > |t|) = 0.3002          Pr(T > t) = 0.8499
    
    . ttest mpg if myrep >=1, by(myrep)
    
    Two-sample t test with equal variances
    ------------------------------------------------------------------------------
       Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
    ---------+--------------------------------------------------------------------
           1 |      59    21.59322    .7982003    6.131093    19.99545    23.19099
           2 |       5        21.4    2.271563     5.07937    15.09313    27.70687
    ---------+--------------------------------------------------------------------
    combined |      64    21.57812    .7525765    6.020612    20.07422    23.08203
    ---------+--------------------------------------------------------------------
        diff |            .1932203    2.826687               -5.457246    5.843687
    ------------------------------------------------------------------------------
        diff = mean(1) - mean(2)                                      t =   0.0684
    Ho: diff = 0                                     degrees of freedom =       62
    
        Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
     Pr(T < t) = 0.5271         Pr(|T| > |t|) = 0.9457          Pr(T > t) = 0.4729

    Hopefully that helps.
    Best regards,

    Marcos

    Comment


    • #3
      Hello, thank you this was perfect!!

      Comment

      Working...
      X