Announcement

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

  • Testing ratio of means from 2 samples.

    Dear All,
    I have an individual-month level panel with a treatment and a control group.
    Code:
    input float(treated outcome month ID)
    0 1  1  766
    0 2 12  548
    0 1 10 1380
    0 4  5 1248
    0 5  6  773
    0 3  4   66
    1 1  3 1122
    1 3  8  865
    0 5  2 1354
    1 3  2  650
    0 2 11  282
    0 6  8 1030
    0 1  1 1381
    0 3  9  431
    0 1  7  250
    1 6  9  104
    1 2  1  544
    0 5  2 1426
    1 3  6 1035
    0 3 11  938
    0 2 10  368
    0 2 10  442
    0 5  4  718
    0 4  1   39
    0 6  4  709
    0 1  2 1372
    0 5  6  827
    0 2  3  201
    0 7  3 1286
    0 2  3   67
    0 3 10  776
    1 2  6  593
    0 3  6   26
    0 4  1  962
    0 5  4 1215
    0 4  2  586
    0 4  6  290
    0 5  7   83
    0 3  8  416
    0 6  4  166
    0 1  8  410
    0 1  8  483
    0 1  9  329
    1 4 10 1383
    0 1 11  629
    0 1  5 1161
    0 2  6  238
    0 3  5  915
    0 1  5  788
    1 5  6  125
    0 2 10 1330
    0 4  5 1318
    0 6 12 1229
    0 3  5  714
    0 5 11  678
    0 0 12  429
    0 2 10 1258
    0 3 11  503
    0 1  4  900
    0 2  9 1305
    0 3 12  901
    0 4 10  268
    0 2  6  694
    0 1 12    9
    0 2 12  587
    1 4  4  135
    0 2  1  682
    1 2  4  320
    0 1  3  663
    0 2  3  423
    0 4  2  730
    0 1  4  496
    1 3  7  324
    0 5  1 1025
    0 4 11  535
    0 4  9  954
    0 3  5  620
    1 1  9  196
    0 1  3  635
    0 2  7 1300
    0 3 12  762
    0 2  5  729
    0 4  5  252
    1 2  6 1095
    0 5  7  235
    1 2 11  277
    0 4  5  751
    0 0 10  245
    0 0  7  784
    0 3  3  701
    0 2  1 1275
    0 2 10   13
    0 4  9  869
    0 4 12 1174
    0 7 11  241
    1 4 10 1057
    0 4  7 1325
    0 7  1  391
    0 3  1  219
    0 2  9  350
    end
    [/CODE]

    I want to make a monthly plot of the ratio of the mean outcome (mean_outcome_treated/mean_outcome_control) by treatment status. I tried the following:

    Code:
    . mean outcome, over(treated month)
    
    Mean estimation                              Number of obs   =      1,453
    
    -------------------------------------------------------------------------
                            |       Mean   Std. Err.     [95% Conf. Interval]
    ------------------------+------------------------------------------------
    c.outcome@treated#month |
                      0  1  |   2.914063   .1349519      2.649341    3.178784
                      0  2  |   2.913978   .1658389      2.588669    3.239288
                      0  3  |   2.831933   .1534484      2.530929    3.132937
                      0  4  |   2.990654   .1645196      2.667933    3.313376
                      0  5  |   2.738095   .1586365      2.426914    3.049276
                      0  6  |       3.19   .1685919       2.85929     3.52071
                      0  7  |   3.008696   .1770578      2.661379    3.356012
                      0  8  |    3.00885   .1641434      2.686866    3.330833
                      0  9  |   3.012658   .1876534      2.644558    3.380759
                      0 10  |   2.877551   .1736147      2.536988    3.218114
                      0 11  |   2.905263   .1802535      2.551678    3.258848
                      0 12  |    2.77686   .1536909       2.47538    3.078339
                      1  1  |        3.9   .3395043      3.234029    4.565971
                      1  2  |   2.666667   .5270463      1.632813     3.70052
                      1  3  |   2.333333   .4143877      1.520471    3.146196
                      1  4  |   3.555556   .5555556      2.465778    4.645333
                      1  5  |   3.454545   .5454545      2.384582    4.524509
                      1  6  |        2.6   .5206833      1.578628    3.621372
                      1  7  |   3.263158   .3138341      2.647541    3.878775
                      1  8  |   3.076923   .4593967      2.175771    3.978075
                      1  9  |       3.25   .4330127      2.400603    4.099397
                      1 10  |        3.2   .4163332      2.383321    4.016679
                      1 11  |          3    .438529      2.139782    3.860218
                      1 12  |          3   .5773503       1.86747     4.13253
    -------------------------------------------------------------------------
    
    . testnl (1.treated#1.month/0.treated#1.month)=1
    
      (1)  (1.treated#1.month/0.treated#1.month) = 1
           Constraint (1) dropped
    
                   chi2(0) =        0.00
               Prob > chi2 =             .
    I am looking for an estimate, with confidence interval, of the ratio to plot on a graph comparing the mean of the treated and control group in each month of the study period.

    I will be grateful for any help you may be able to offer.
    Many thanks in advance.
    Sumedha.


  • #2
    Code:
    collapse (mean) outcome, by(treated month)
    reshape wide outcome, i(month) j(treated)
    gen ratio = outcome1/outcome0
    graph twoway connected ratio month
    Added: Sorry, that doesn't get you any confidence interval. So, this is better:

    Code:
    mean outcome, over(treated month)
    frame create for_graph int month float(ratio se)
    forvalues i = 1/12 {
        nlcom _b[[email protected]#`i'.month]/_b[[email protected]#`i'.month]
        frame post for_graph (`i') (r(b)[1,1]) (r(V)[1,1])
    }
    
    frame change for_graph
    gen ll = ratio - invnormal(.975)*se
    gen ul = ratio + invnormal(.975)*se
    graph twoway (connect ratio month) (rcap ll ul month)
    Last edited by Clyde Schechter; 15 Nov 2021, 13:39.

    Comment


    • #3
      Thank you for your guidance, Prof. Schechter. Your code helps me get the estimated ratio but unfortunately not the CI's I am seeking. Is there a way I can also get the confidence intervals for the ratio at each month as well? Click image for larger version

Name:	Graph.png
Views:	1
Size:	40.2 KB
ID:	1636676

      Comment


      • #4
        See edits to #1.

        Comment


        • #5
          You're the best! Thank you Prof. Schechter!

          Comment

          Working...
          X