Announcement

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

  • Accessing values returned by -margins-

    Hi everyone

    I'm interested whether a variable (foreign) modifies the effect of X (trunk) on Y (mpg). Here's an example:

    Code:
    sysuse auto, clear
    
    regress mpg c.trunk##foreign
    To do so, I test the difference in slopes for domestic and foreign cars with -margins-:

    Code:
    margins, dydx(trunk) over(foreign) pwcompare(effects)
    Super easy, yields the following output:

    Code:
    Pairwise comparisons of average marginal effects
    
    Model VCE: OLS                                              Number of obs = 74
    
    Expression: Linear prediction, predict()
    dy/dx wrt:  trunk
    Over:       foreign
    
    --------------------------------------------------------------------------------------
                         |   Contrast Delta-method    Unadjusted           Unadjusted
                         |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
    ---------------------+----------------------------------------------------------------
    trunk                |
                 foreign |
    Foreign vs Domestic  |   .2638674   .3493065     0.76   0.453    -.4328025    .9605373
    --------------------------------------------------------------------------------------
    My question, as I have to do this one billion times: What is the best practice to access the contrast (0.2638674) and its p-value (0.453) to write it into the notes of figures? E.g. _b[trunk:1vs0.foreign]] doesn't work

    Thanks so much
    Go


  • #2
    See

    Code:
    return list

    Code:
    sysuse auto, clear
    regress mpg c.trunk##foreign
    margins, dydx(trunk) over(foreign) pwcompare(effects)
    mat l r(table_vs)
    display r(table_vs)["b", 1]
    display %4.3f r(table_vs)["pvalue", 1]
    Res.:

    Code:
    . margins, dydx(trunk) over(foreign) pwcompare(effects)
    
    Pairwise comparisons of average marginal effects
    
    Model VCE: OLS                                              Number of obs = 74
    
    Expression: Linear prediction, predict()
    dy/dx wrt:  trunk
    Over:       foreign
    
    --------------------------------------------------------------------------------------
                         |   Contrast Delta-method    Unadjusted           Unadjusted
                         |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
    ---------------------+----------------------------------------------------------------
    trunk                |
                 foreign |
    Foreign vs Domestic  |   .2638674   .3493065     0.76   0.453    -.4328025    .9605373
    --------------------------------------------------------------------------------------
    
    . 
    . mat l r(table_vs)
    
    r(table_vs)[9,1]
                 trunk:
                  1vs0.
               foreign
         b   .26386741
        se   .34930651
         t   .75540364
    pvalue   .45254119
        ll  -.43280246
        ul   .96053728
        df          70
      crit   1.9944371
     eform           0
    
    . 
    . display r(table_vs)["b", 1]
    .26386741
    
    . 
    . display %4.3f r(table_vs)["pvalue", 1]
    0.453
    
    .

    Comment

    Working...
    X