Announcement

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

  • comparing difference in average marginal effects (AME) between stratified samples

    Hi Statalists,

    I was wondering how to conduct a significance test to compare the difference in average marginal effects (AME) between two stratified samples. An example is as follows:


    logit y i.x1 i.x2 if gender==1

    margins,dydx(x1) asobserved vsquish

    Average marginal effects Number of obs = 3,112
    ------------------------------------------------------------------------------
    | Delta-method
    | dy/dx Std. Err. z P>|z| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    x1 |
    1 yes | .0743023 .0155001 4.79 0.000 .0439226 .1046819
    ------------------------------------------------------------------------------




    logit y i.x1 i.x2 if gender==2

    margins,dydx(x1) asobserved vsquish

    Average marginal effects Number of obs = 4,347
    ------------------------------------------------------------------------------
    | Delta-method
    | dy/dx Std. Err. z P>|z| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    x1 |
    1 yes | .0860667 .0147079 5.85 0.000 .0572398 .1148937
    ------------------------------------------------------------------------------



    I wanted to test whether the AME of X1 for men (.0743023) and women (.0860667) are significantly different. How can I do this in STATA?

    Thank you.
    Last edited by Weidi Qin; 03 Feb 2023, 19:15.

  • #2
    You can use an interaction and margins with post. Here's an example

    Code:
    .
    . clear all
    
    . webuse nhanes2
    
    .
    . qui logit highbp age weight if sex == 1
    
    . margins, dydx(age) asobserved vsquish
    
    Average marginal effects                        Number of obs     =      4,915
    Model VCE    : OIM
    
    Expression   : Pr(highbp), predict()
    dy/dx w.r.t. : age
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |   .0081688   .0003371    24.23   0.000     .0075081    .0088295
    ------------------------------------------------------------------------------
    
    . local x = r(table)[1,1]
    
    .
    . qui logit highbp age weight if sex == 2
    
    . margins, dydx(age) asobserved vsquish
    
    Average marginal effects                        Number of obs     =      5,436
    Model VCE    : OIM
    
    Expression   : Pr(highbp), predict()
    dy/dx w.r.t. : age
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |    .011241   .0002496    45.04   0.000     .0107517    .0117302
    ------------------------------------------------------------------------------
    
    . local y = r(table)[1,1]
    
    .
    . di `x'-`y'
    -.00307217
    
    .
    . qui logit highbp i.sex##(c.age c.weight)
    
    . margins , dydx(age) over(sex) post
    
    Average marginal effects                        Number of obs     =     10,351
    Model VCE    : OIM
    
    Expression   : Pr(highbp), predict()
    dy/dx w.r.t. : age
    over         : sex
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    age          |
             sex |
           Male  |   .0081688   .0003371    24.23   0.000     .0075081    .0088295
         Female  |    .011241   .0002496    45.04   0.000     .0107517    .0117302
    ------------------------------------------------------------------------------
    
    .
    . di   _b[age:1bn.sex] -  _b[age:2.sex]
    -.00307217
    
    .
    . test  _b[age:1bn.sex] =  _b[age:2.sex]
    
     ( 1)  [age]1bn.sex - [age]2.sex = 0
    
               chi2(  1) =   53.65
             Prob > chi2 =    0.0000
    Last edited by Justin Niakamal; 03 Feb 2023, 20:18.

    Comment


    • #3
      Yes, it worked! Thank you so much, Justin.

      Comment

      Working...
      X