Announcement

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

  • Unpaired t test with adjustments

    Dear all, i'm very new to stata and data management. Have not done data analysis before and is embarking on my first project for my minor. Sincerely seek your help with this.

    I have 2 population A and B that i'm studying. I am looking at the difference in their mean BP and need to adjust for several factors after.

    So i understand that i can use the unpaired t-test function to get the mean BP difference of A and B (with 95% CI and p). However, i need to adjust it for several factors after: age, gender, education in model 1, age gender education BMI in model 2, age gender education BMI and hypertension in model 3 etc.

    How do i go about doing the second portion with the 95% CI and p reflected as well? do i find the difference then perform a regression? if so, how do i get the CI and p?

    Thank you very very much for the help!

    I'm using version 15 btw.
    Last edited by JK Neo; 22 Jan 2022, 00:09.

  • #2
    You want to use linear regression to do this. Below, if I want to replicate the results of a t-test for the price differential between domestic and foreign cars using regress, I would proceed as follows:

    Code:
    sysuse auto, clear
    ttest price, by(foreign)
    regress price i.foreign
    Res.:

    Code:
    . ttest price, by(foreign)
    
    Two-sample t test with equal variances
    ------------------------------------------------------------------------------
       Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
    ---------+--------------------------------------------------------------------
    Domestic |      52    6072.423    429.4911    3097.104    5210.184    6934.662
     Foreign |      22    6384.682    558.9942    2621.915     5222.19    7547.174
    ---------+--------------------------------------------------------------------
    combined |      74    6165.257    342.8719    2949.496    5481.914      6848.6
    ---------+--------------------------------------------------------------------
        diff |           -312.2587    754.4488               -1816.225    1191.708
    ------------------------------------------------------------------------------
        diff = mean(Domestic) - mean(Foreign)                         t =  -0.4139
    Ho: diff = 0                                     degrees of freedom =       72
    
        Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
     Pr(T < t) = 0.3401         Pr(|T| > |t|) = 0.6802          Pr(T > t) = 0.6599
    
    . 
    . regress price i.foreign
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(1, 72)        =      0.17
           Model |  1507382.66         1  1507382.66   Prob > F        =    0.6802
        Residual |   633558013        72  8799416.85   R-squared       =    0.0024
    -------------+----------------------------------   Adj R-squared   =   -0.0115
           Total |   635065396        73  8699525.97   Root MSE        =    2966.4
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
         foreign |
        Foreign  |   312.2587   754.4488     0.41   0.680    -1191.708    1816.225
           _cons |   6072.423    411.363    14.76   0.000     5252.386     6892.46
    ------------------------------------------------------------------------------
    Further, if I wanted to test for this difference controlling for mileage and weight of cars in the sample, I just simply add these two variables as regressors

    Code:
    regress price mpg weight i.foreign
    Res.:

    Code:
     regress price mpg weight i.foreign
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(3, 70)        =     23.29
           Model |   317252881         3   105750960   Prob > F        =    0.0000
        Residual |   317812515        70  4540178.78   R-squared       =    0.4996
    -------------+----------------------------------   Adj R-squared   =    0.4781
           Total |   635065396        73  8699525.97   Root MSE        =    2130.8
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |    21.8536   74.22114     0.29   0.769    -126.1758     169.883
          weight |   3.464706    .630749     5.49   0.000     2.206717    4.722695
                 |
         foreign |
        Foreign  |    3673.06   683.9783     5.37   0.000     2308.909    5037.212
           _cons |  -5853.696   3376.987    -1.73   0.087    -12588.88    881.4934
    ------------------------------------------------------------------------------
    Further detail, always add the -robust- option to the regression command so that it reports robust standard errors.

    Comment


    • #3
      Thank you very much!

      Comment

      Working...
      X