Announcement

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

  • Display Median for Paired t test

    Hello folks

    I have a data set with several observations at different times for companies. However, some values are missing. It is a dependent dataset, so I use a paired t-test.

    The output table gives me (Obs,Mean,Std. Err.,Std. Dev., [95% Conf. Interval]).
    Do any of you know how I can get the median displayed?

    Unfortunately I can't just do tabstat because by paired ttest the n is always in dependency to the two groups.
    Thank you so much in advance!

    Cheers

    ttest Post1 == Pre
    ---> Paired t test
    ------------------------------------------------------------------------------
    Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
    ---------+--------------------------------------------------------------------
    Post1 | 92 1783.223 142.3248 1296.641 1500.093 2066.352
    Pre | 92 1342.873 107.4634 979.0379 1129.095 1556.652
    ---------+--------------------------------------------------------------------
    diff | 92 440.349 82.08607 747.8397 277.0537 603.6444

    ttest Post2 == Pre
    ---> Paired t test
    ------------------------------------------------------------------------------
    Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
    ---------+--------------------------------------------------------------------
    Post2 | 74 1954.532 156.5427 1517.738 1643.669 2265.395
    Pre | 74 1377.931 105.91 1026.835 1167.615 1588.247
    ---------+--------------------------------------------------------------------
    diff | 94 576.6011 104.6164 1014.294 368.8535 784.3486


  • #2
    -summarize, detail- will give you the median in r(p50). E.g.,

    Code:
    . clear
    
    . webuse fuel
    
    . ttest mpg1 = mpg1
    
    Paired t test
    ------------------------------------------------------------------------------
    Variable |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
    ---------+--------------------------------------------------------------------
        mpg1 |      12          21    .7881701    2.730301    19.26525    22.73475
        mpg1 |      12          21    .7881701    2.730301    19.26525    22.73475
    ---------+--------------------------------------------------------------------
        diff |      12           0           0           0           0           0
    ------------------------------------------------------------------------------
         mean(diff) = mean(mpg1 - mpg1)                               t =        .
     Ho: mean(diff) = 0                              degrees of freedom =       11
    
     Ha: mean(diff) < 0           Ha: mean(diff) != 0           Ha: mean(diff) > 0
     Pr(T < t) =      .         Pr(|T| > |t|) =      .          Pr(T > t) =      .
    
    . qui summ mpg1, d
    
    . dis r(p50)
    20.5
    
    . qui summ mpg2, d
    
    . dis r(p50)
    23
    
    .

    Comment


    • #3
      Hey Joro Kolev thanks for the answer.
      But my problem is that the n(Obs) for "pre" is always different, depending on the comparison of the two groups (in your scenario it would bei mpg1 is different).
      I am looking for the median of the values used in the Paired t-test.

      Comment


      • #4
        a paired t-test is the same as a regression with a constant but no covariates/predictors (note that you might have to generate a variable that is the difference of the two if you currently have 2 variables); after estimating the regression, one of the saved items is whether the observation was used in the regression - it is called "e(sample)"; thus, you could estimate the regression and then get the median by including "if e(sample)" in your command (note that you might want to save the results of e(sample) in something more permanent to ensure you don't lose it)

        Comment


        • #5
          One way to go is what Rich proposes, another way is to directly impose the condition that both are not missing in the -summ- command like this:

          Code:
          . webuse fuel
          
          . ttest mpg1 = mpg1
          
          Paired t test
          ------------------------------------------------------------------------------
          Variable |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
          ---------+--------------------------------------------------------------------
              mpg1 |      12          21    .7881701    2.730301    19.26525    22.73475
              mpg1 |      12          21    .7881701    2.730301    19.26525    22.73475
          ---------+--------------------------------------------------------------------
              diff |      12           0           0           0           0           0
          ------------------------------------------------------------------------------
               mean(diff) = mean(mpg1 - mpg1)                               t =        .
           Ho: mean(diff) = 0                              degrees of freedom =       11
          
           Ha: mean(diff) < 0           Ha: mean(diff) != 0           Ha: mean(diff) > 0
           Pr(T < t) =      .         Pr(|T| > |t|) =      .          Pr(T > t) =      .
          
          . qui summ mpg1 if !missing(mpg1,mpg2), d
          
          . dis r(p50)
          20.5
          
          . qui summ mpg2 if !missing(mpg1,mpg2), d
          
          . dis r(p50)
          23
          
          
          
          .

          Comment


          • #6
            There's also a deeper question that can be asked here. Why do you want the median of the difference at all? Performing the paired t-test is to imply that the mean of the difference is meaningful and of interest.

            Comment


            • #7
              Joro Kolev Thanks for the answer! That is exactly what i was looking for! Thank you so much. I really appreciated the help.
              Leonardo Guizzetti I am also doing an signrank test and therefore i need to report the median.

              Comment


              • #8
                Ah okay, that makes sense then.

                Comment

                Working...
                X