Announcement

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

  • confidence interval for mean difference

    Dear Listers,


    I would like to know how to capture confidence interval for mean difference. I have two groups- intervention and control. After conducting ttest, I want to get the result of confidence interval for mean difference. I know ttest result shows 'differ' but I have more than 10 variables and don't want to copy and past the result from screen.
    Code:
    * Example generated by    -dataex-. To install:    ssc install    dataex
    clear
    input float(cost_strip    cost_monitoring) byte    rand_trt
    0       0 1
    0 128.205 0
    .87       0 1
    .29       0 1
    0 167.055 0
    0  168.35 0
    .58 177.415 0
    0 164.465 0
    0   181.3 0
    .29 185.185 0
    1.45       0 1
    .29 182.595 0
    .29       0 1
    .29       0 1
    .29       0 1
    0  189.07 0
    .29       0 1
    0       0 1
    0 120.435 0
    0 167.055 0
    .58  186.48 0
    .29       0 1
    0       0 1
    .29  170.94 0
    0       0 1
    .29  186.48 0
    0       0 1
    .29       0 1
    .29       0 1
    0       0 1
    end


    Code:
           global X cost_strip    cost_monitoring
    
           foreach x of global X {
         {
    qui sum `x' if rand_trt==0
    
            
             gen int`x'= r(mean)
             qui sum `x' if rand_trt==1
    
             scalar con`x' = r(mean)
             
             
             gen     diff = int`x' - con`x'
         qui ci mean diff
         scalar c = r(lb)
         scalar d = r(ub)
    
    
             }
        *di "`x' " _skip(10) %12.1f c _skip(10) %12.1f d _skip(10) 
             }
    rand_trt is an intervention dummy. But this code doesn't work.

    Many thanks in advance.

    BW

    Kim

  • #2
    Your code doesn't work because you compute the overall means of `x' in each rand_trt group and make a "variable" out of the difference between them. But that "variable" is actually a constant, so it has no variance, and you won't get any kind of standard error or confidence interval out of that.

    The following code will work:
    Code:
    local X cost_strip cost_monitoring
    
    foreach x of local X {
        ttest `x', by(rand_trt)
        scalar `x'_diff = r(mu_1) - r(mu_2)
        scalar `x'_lb = `x'_diff - invt(r(df_t), 0.975)*r(se)
        scalar `x'_ub = `x'_diff + invt(r(df_t), 0.975)*r(se)
    }
    
    scalar dir

    Comment


    • #3
      first, please read the FAQ which explains, among other things, why "doesn't work" is not helpful

      second, I'm not exactly sure what you want but try this:
      Code:
      qui regress cost_strip i.rand_trt
      mat li r(table)
      does that give what you want (in "ll" and "ul" for 1.rand_trt? if not, please clarify what you want

      Comment


      • #4
        Hi Clyde,

        You manually calculated the confidence interval to capture the mean difference. I haven't thought about that approach but seems perfect for this situation.

        Thank you very much for your help and it is really appreciated.

        Kind regards,

        Kim

        Comment

        Working...
        X