Announcement

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

  • Understanding difference between contrast and margins command

    I need help understanding why the -margins- and -contrast- commands produce identical results in a regression model without an interaction term and different results in a regression model with an interaction term. To illustrate my question, I use the nlsw88 dataset that allows us to analyze how race (‘White’, ‘Black’, ‘Other’) affects the wages of individuals:
    Code:
    sysuse nlsw88
    reg wage i.race married tenure hours
    contrast r.race
    
    -------------------------------------------------------------------
                      |   Contrast   Std. err.     [95% conf. interval]
    ------------------+------------------------------------------------
                 race |
    (Black vs White)  |  -1.554238   .2776981     -2.098813   -1.009663
    (Other vs White)  |    .586882   1.105017     -1.580092    2.753856
    -------------------------------------------------------------------
    
    margins, dydx(2.race 3.race)
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
            race |
          Black  |  -1.554238   .2776981    -5.60   0.000    -2.098813   -1.009663
          Other  |    .586882   1.105017     0.53   0.595    -1.580092    2.753856
    ------------------------------------------------------------------------------
    When race is not interacted with any other variable, the contrast measures and discrete effects are identical. Furthermore, I know that the discrete effects can be interpreted as the effect of being 'Black' (relative to being 'White') on wages or the effect of belonging to an ‘Other’ race (relative to being 'White') on wages.

    Different results occur when an interaction term is introduced within the regression model:
    Code:
    reg wage race##married tenure hours
    contrast r.race
    
    -------------------------------------------------------------------
                      |   Contrast   Std. err.     [95% conf. interval]
    ------------------+------------------------------------------------
                 race |
    (Black vs White)  |  -1.591575   .2785111     -2.137745   -1.045405
    (Other vs White)  |   .4358627   1.197187     -1.911862    2.783588
    -------------------------------------------------------------------
    
    margins, dydx(2.race 3.race)
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
            race |
          Black  |  -1.455648   .2837977    -5.13   0.000    -2.012185   -.8991107
          Other  |   .5447258   1.111263     0.49   0.624    -1.634498    2.723949
    ------------------------------------------------------------------------------
    Now, the contrast measures and discrete effects are no longer identical. Assuming that it is still correct to interpret the discrete effects as the effect of being ‘Black’/’Other’ (relative to ‘White’) on wages, how do I interpret the contrast measures?
    Last edited by Weston Ley; 03 Jul 2025, 12:29.

  • #2
    contrast treats factors as balanced while margins treats them as observed. Results will match with
    Code:
    contrast r.race , asobserved
    or, vice versa
    Code:
    margins , dydx(2.race 3.race) asbalanced

    Comment

    Working...
    X