Announcement

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

  • #16
    Ankit:
    as an aside to Andrew's excellent reply, you may want to consider -lincom- after -regress- (standard errors will differ from the one calculated via -ttest-, though. This very old Stata thread explains why):
    Code:
    use "C:\Program Files\Stata18\ado\base\a\auto.dta"
    . ttest mpg if inlist(rep78, 1, 2), by(rep78) unequal
    
    Two-sample t test with unequal variances
    ------------------------------------------------------------------------------
       Group |     Obs        Mean    Std. err.   Std. dev.   [95% conf. interval]
    ---------+--------------------------------------------------------------------
           1 |       2          21           3    4.242641   -17.11861    59.11861
           2 |       8      19.125    1.328768    3.758324    15.98296    22.26704
    ---------+--------------------------------------------------------------------
    Combined |      10        19.5    1.166667    3.689324    16.86082    22.13918
    ---------+--------------------------------------------------------------------
        diff |               1.875    3.281101               -19.43346    23.18346
    ------------------------------------------------------------------------------
        diff = mean(1) - mean(2)                                      t =   0.5715
    H0: diff = 0                     Satterthwaite's degrees of freedom =  1.42302
    
        Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
     Pr(T < t) = 0.6776         Pr(|T| > |t|) = 0.6447          Pr(T > t) = 0.3224
    
    . lincom _b[1b.rep78]-_b[2.rep78]
    
     ( 1)  1b.rep78 - 2.rep78 = 0
    
    ------------------------------------------------------------------------------
             mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             (1) |      1.875   4.181884     0.45   0.655    -6.479274    10.22927
    ------------------------------------------------------------------------------
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #17
      Originally posted by Carlo Lazzaro View Post
      Ankit:
      Code:
       use "C:\Program Files\Stata18\ado\base\a\auto.dta"
      (1978 automobile data)
      
      . gen butler=0 if rep78==3
      
      
      . replace butler=1 if rep78==4
      
      . ttest price, by(butler) unequal
      
      Two-sample t test with unequal variances
      ------------------------------------------------------------------------------
      Group | Obs Mean Std. err. Std. dev. [95% conf. interval]
      ---------+--------------------------------------------------------------------
      0 | 30 6429.233 643.5995 3525.14 5112.924 7745.542
      1 | 18 6071.5 402.9585 1709.608 5221.332 6921.668
      ---------+--------------------------------------------------------------------
      Combined | 48 6295.083 427.0852 2958.933 5435.899 7154.268
      ---------+--------------------------------------------------------------------
      diff | 357.7333 759.3392 -1172.108 1887.574
      ------------------------------------------------------------------------------
      diff = mean(0) - mean(1) t = 0.4711
      H0: diff = 0 Satterthwaite's degrees of freedom = 44.5217
      
      Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
      Pr(T < t) = 0.6801 Pr(|T| > |t|) = 0.6399 Pr(T > t) = 0.3199
      
      .
      Thanks sir

      Comment


      • #18
        Originally posted by Andrew Musau View Post

        To add to Carlo's illustration, note that the t-test is a pairwise test, so you cannot have a larger sample than that implied by two groups. In a situation with more than two groups, you need to use the -if- qualifier, as the following example illustrates.

        Code:
        sysuse auto, clear
        *1 vs. 2
        ttest mpg if inlist(rep78, 1, 2), by(rep78)
        
        *1 vs. 4
        ttest mpg if inlist(rep78, 1, 4), by(rep78)
        Res.:

        Code:
        . *1 vs. 2
        
        .
        . ttest mpg if inlist(rep78, 1, 2), by(rep78)
        
        Two-sample t test with equal variances
        ------------------------------------------------------------------------------
        Group | Obs Mean Std. err. Std. dev. [95% conf. interval]
        ---------+--------------------------------------------------------------------
        1 | 2 21 3 4.242641 -17.11861 59.11861
        2 | 8 19.125 1.328768 3.758324 15.98296 22.26704
        ---------+--------------------------------------------------------------------
        Combined | 10 19.5 1.166667 3.689324 16.86082 22.13918
        ---------+--------------------------------------------------------------------
        diff | 1.875 3.021731 -5.093125 8.843125
        ------------------------------------------------------------------------------
        diff = mean(1) - mean(2) t = 0.6205
        H0: diff = 0 Degrees of freedom = 8
        
        Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
        Pr(T < t) = 0.7239 Pr(|T| > |t|) = 0.5522 Pr(T > t) = 0.2761
        
        .
        .
        .
        . *1 vs. 4
        
        .
        . ttest mpg if inlist(rep78, 1, 4), by(rep78)
        
        Two-sample t test with equal variances
        ------------------------------------------------------------------------------
        Group | Obs Mean Std. err. Std. dev. [95% conf. interval]
        ---------+--------------------------------------------------------------------
        1 | 2 21 3 4.242641 -17.11861 59.11861
        4 | 18 21.66667 1.16316 4.93487 19.21261 24.12072
        ---------+--------------------------------------------------------------------
        Combined | 20 21.6 1.067215 4.77273 19.36629 23.83371
        ---------+--------------------------------------------------------------------
        diff | -.6666667 3.651484 -8.338149 7.004816
        ------------------------------------------------------------------------------
        diff = mean(1) - mean(4) t = -0.1826
        H0: diff = 0 Degrees of freedom = 18
        
        Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
        Pr(T < t) = 0.4286 Pr(|T| > |t|) = 0.8572 Pr(T > t) = 0.5714
        Thanks

        Comment

        Working...
        X