Announcement

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

  • margins, pwcompare

    I have written a program that exports tables from margins. I was hoping to replicate the results from pwcompare with the margins, pwcompar command. In most cases the results are similar, however, when using the option pveffects, the results differ. Am I missing something. Here is an example:
    Code:
    webuse nhanes2
    logistic highbp sex##agegrp##c.bmi
    
    . margins agegrp, pwcompare(pv)
    
    Pairwise comparisons of predictive margins              Number of obs = 10,351
    Model VCE: OIM
    
    Expression: Pr(highbp), predict()
    
    --------------------------------------------------------
                    |            Delta-method    Unadjusted
                    |   Contrast   std. err.      z    P>|z|
    ----------------+---------------------------------------
             agegrp |
    30-39 vs 20-29  |   .0798159    .013507     5.91   0.000
    40-49 vs 20-29  |   .1738605   .0155477    11.18   0.000
    50-59 vs 20-29  |   .3122507   .0161705    19.31   0.000
    60-69 vs 20-29  |   .3610133   .0126272    28.59   0.000
      70+ vs 20-29  |   .4504747   .0174674    25.79   0.000
    40-49 vs 30-39  |   .0940445   .0164988     5.70   0.000
    50-59 vs 30-39  |   .2324348    .017087    13.60   0.000
    60-69 vs 30-39  |   .2811974   .0137814    20.40   0.000
      70+ vs 30-39  |   .3706588   .0183192    20.23   0.000
    50-59 vs 40-49  |   .1383903   .0187419     7.38   0.000
    60-69 vs 40-49  |   .1871529   .0157866    11.86   0.000
      70+ vs 40-49  |   .2766143   .0198717    13.92   0.000
    60-69 vs 50-59  |   .0487626   .0164004     2.97   0.003
      70+ vs 50-59  |    .138224   .0203626     6.79   0.000
      70+ vs 60-69  |   .0894614   .0176804     5.06   0.000
    --------------------------------------------------------
    
    . pwcompare agegrp, pv
    
    Pairwise comparisons of marginal linear predictions
    
    Margins: asbalanced
    
    --------------------------------------------------------
                    |                            Unadjusted
                    |   Contrast   Std. err.      z    P>|z|
    ----------------+---------------------------------------
    highbp          |
             agegrp |
    30-39 vs 20-29  |  -.0248978   .5020654    -0.05   0.960
    40-49 vs 20-29  |   1.217738    .522244     2.33   0.020
    50-59 vs 20-29  |   2.427516    .506242     4.80   0.000
    60-69 vs 20-29  |   3.083275    .419672     7.35   0.000
      70+ vs 20-29  |   4.267813   .5528408     7.72   0.000
    40-49 vs 30-39  |   1.242636   .5468977     2.27   0.023
    50-59 vs 30-39  |   2.452414   .5316383     4.61   0.000
    60-69 vs 30-39  |   3.108173    .449981     6.91   0.000
      70+ vs 30-39  |   4.292711   .5761868     7.45   0.000
    50-59 vs 40-49  |   1.209778   .5507345     2.20   0.028
    60-69 vs 40-49  |   1.865538   .4723898     3.95   0.000
      70+ vs 40-49  |   3.050076   .5938522     5.14   0.000
    60-69 vs 50-59  |   .6557598   .4546364     1.44   0.149
      70+ vs 50-59  |   1.840298   .5798298     3.17   0.002
      70+ vs 60-69  |   1.184538   .5060101     2.34   0.019
    --------------------------------------------------------

  • #2
    As stated in the output, pwcompare calculates marginal linear predictions, which are conventional linear predictions (predicted values of the outcome holding all other variables in the model constant). You can certainly compute linear predictions using margins.

    Code:
    clear all
    webuse nhanes2
    logit highbp sex##agegrp##c.bmi
    pwcompare agegrp, pv
    margins, over(agegrp) expression(predict(xb)) at(bmi=0) asbalanced pwcompare(pv)
    Res.:

    Code:
    . pwcompare agegrp, pv
    
    Pairwise comparisons of marginal linear predictions
    
    Margins: asbalanced
    
    --------------------------------------------------------
                    |                            Unadjusted
                    |   Contrast   Std. err.      z    P>|z|
    ----------------+---------------------------------------
    highbp          |
             agegrp |
    30–39 vs 20–29  |  -.0248978   .5020654    -0.05   0.960
    40–49 vs 20–29  |   1.217738    .522244     2.33   0.020
    50–59 vs 20–29  |   2.427516    .506242     4.80   0.000
    60–69 vs 20–29  |   3.083275    .419672     7.35   0.000
      70+ vs 20–29  |   4.267813   .5528408     7.72   0.000
    40–49 vs 30–39  |   1.242636   .5468977     2.27   0.023
    50–59 vs 30–39  |   2.452414   .5316383     4.61   0.000
    60–69 vs 30–39  |   3.108173    .449981     6.91   0.000
      70+ vs 30–39  |   4.292711   .5761868     7.45   0.000
    50–59 vs 40–49  |   1.209778   .5507345     2.20   0.028
    60–69 vs 40–49  |   1.865538   .4723898     3.95   0.000
      70+ vs 40–49  |   3.050076   .5938522     5.14   0.000
    60–69 vs 50–59  |   .6557598   .4546364     1.44   0.149
      70+ vs 50–59  |   1.840298   .5798298     3.17   0.002
      70+ vs 60–69  |   1.184538   .5060101     2.34   0.019
    --------------------------------------------------------
    
    . 
    . margins, over(agegrp) expression(predict(xb)) at(bmi=0) asbalanced pwcompare(pv)
    
    Pairwise comparisons of adjusted predictions            Number of obs = 10,351
    Model VCE: OIM
    
    Expression: Linear prediction (log odds), predict(xb)
    Over:       agegrp
    At: 1.agegrp
            sex      (asbalanced)
            agegrp   (asbalanced)
            bmi    = 0
        2.agegrp
            sex      (asbalanced)
            agegrp   (asbalanced)
            bmi    = 0
        3.agegrp
            sex      (asbalanced)
            agegrp   (asbalanced)
            bmi    = 0
        4.agegrp
            sex      (asbalanced)
            agegrp   (asbalanced)
            bmi    = 0
        5.agegrp
            sex      (asbalanced)
            agegrp   (asbalanced)
            bmi    = 0
        6.agegrp
            sex      (asbalanced)
            agegrp   (asbalanced)
            bmi    = 0
    
    --------------------------------------------------------
                    |            Delta-method    Unadjusted
                    |   Contrast   std. err.      z    P>|z|
    ----------------+---------------------------------------
             agegrp |
    30–39 vs 20–29  |  -.0248978   .5020654    -0.05   0.960
    40–49 vs 20–29  |   1.217738    .522244     2.33   0.020
    50–59 vs 20–29  |   2.427516    .506242     4.80   0.000
    60–69 vs 20–29  |   3.083275    .419672     7.35   0.000
      70+ vs 20–29  |   4.267813   .5528408     7.72   0.000
    40–49 vs 30–39  |   1.242636   .5468977     2.27   0.023
    50–59 vs 30–39  |   2.452414   .5316383     4.61   0.000
    60–69 vs 30–39  |   3.108173    .449981     6.91   0.000
      70+ vs 30–39  |   4.292711   .5761868     7.45   0.000
    50–59 vs 40–49  |   1.209778   .5507345     2.20   0.028
    60–69 vs 40–49  |   1.865538   .4723898     3.95   0.000
      70+ vs 40–49  |   3.050076   .5938522     5.14   0.000
    60–69 vs 50–59  |   .6557598   .4546364     1.44   0.149
      70+ vs 50–59  |   1.840298   .5798298     3.17   0.002
      70+ vs 60–69  |   1.184538   .5060101     2.34   0.019
    --------------------------------------------------------
    
    .
    Last edited by Andrew Musau; 27 Apr 2024, 16:29.

    Comment

    Working...
    X