Announcement

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

  • Calculting Difference in Proportion between two outcomes across a variable

    Dear All,


    Calculting Difference in Proportion between two outcomes (out1 and out2) across a variable (agegrp:
    Thanks a lot

    . webuse bdesop, clear

    . gen out1 = cases != 0

    . gen out2 = cases > 5

    . tab agegrp out1, row

    +----------------+
    | Key |
    |----------------|
    | frequency |
    | row percentage |
    +----------------+

    | out1
    agegrp | 0 1 | Total
    -----------+----------------------+----------
    25-34 | 28 2 | 30
    | 93.33 6.67 | 100.00
    -----------+----------------------+----------
    35-44 | 20 10 | 30
    | 66.67 33.33 | 100.00
    -----------+----------------------+----------
    45-54 | 6 26 | 32
    | 18.75 81.25 | 100.00
    -----------+----------------------+----------
    55-64 | 0 32 | 32
    | 0.00 100.00 | 100.00
    -----------+----------------------+----------
    65-74 | 2 28 | 30
    | 6.67 93.33 | 100.00
    -----------+----------------------+----------
    75+ | 2 20 | 22
    | 9.09 90.91 | 100.00
    -----------+----------------------+----------
    Total | 58 118 | 176
    | 32.95 67.05 | 100.00

    . tab agegrp out2, row

    +----------------+
    | Key |
    |----------------|
    | frequency |
    | row percentage |
    +----------------+

    | out2
    agegrp | 0 1 | Total
    -----------+----------------------+----------
    25-34 | 30 0 | 30
    | 100.00 0.00 | 100.00
    -----------+----------------------+----------
    35-44 | 30 0 | 30
    | 100.00 0.00 | 100.00
    -----------+----------------------+----------
    45-54 | 28 4 | 32
    | 87.50 12.50 | 100.00
    -----------+----------------------+----------
    55-64 | 22 10 | 32
    | 68.75 31.25 | 100.00
    -----------+----------------------+----------
    65-74 | 26 4 | 30
    | 86.67 13.33 | 100.00
    -----------+----------------------+----------
    75+ | 22 0 | 22
    | 100.00 0.00 | 100.00
    -----------+----------------------+----------
    Total | 158 18 | 176
    | 89.77 10.23 | 100.00

    .



    Frank

  • #2
    Hi Frank. Something like this, perhaps?

    Code:
    * NOTE:  Your out1 and out2 variables are not mutually exclusive!
    tabulate out1 out2
    
    * With 0/1 coding, the mean = proportion of 1s
    bysort agegrp: egen p1 = mean(out1)
    by agegrp: egen p2 = mean(out2)
    generate pdiff = p1-p2
    egen tag = tag(agegrp) // Tag one record per age group for listing
    list agegrp p1 p2 pdiff if tag, clean noobs
    Results from -list- command:

    Code:
    . list agegrp p1 p2 pdiff if tag, clean noobs
    
        agegrp         p1         p2      pdiff  
         25-34   .0666667          0   .0666667  
         35-44   .3333333          0   .3333333  
         45-54      .8125       .125      .6875  
         55-64          1      .3125      .6875  
         65-74   .9333333   .1333333         .8  
           75+   .9090909          0   .9090909

    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 18.5 (Windows)

    Comment


    • #3
      Hi Bruce,

      Thanks a lot. That is what I want. Please is it possible to calculate the 95% CI for the difference (Oliver Twist).


      Frank

      Comment

      Working...
      X