Announcement

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

  • setting base level for margins with eydx

    Hello. i'm running a maultivariable panel regression model with xtgee and a number of continuous and categorical indepentent variables. I'm trying to get contrasts of marginal effects of an indicator variable, and can set different base levels using ibX.variable notation.. I can run marginal elasticities with eydx.
    Code:
     . margins i.hour6
    
    Adjusted predictions                            Number of obs     =      7,801
    Model VCE    : Semirobust
    
    Expression   : Exponentiated linear prediction, predict()
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           hour6 |
              0  |    154.271   4.230974    36.46   0.000     145.9785    162.5636
              1  |    147.976   3.380656    43.77   0.000       141.35    154.6019
              2  |   151.9056   3.582315    42.40   0.000     144.8844    158.9268
              3  |   157.2417   3.570002    44.05   0.000     150.2447    164.2388
              4  |   158.6969   3.750886    42.31   0.000     151.3453    166.0485
              5  |   162.7874   4.190865    38.84   0.000     154.5735    171.0014
              6  |   165.2312   5.213272    31.69   0.000     155.0134     175.449
              7  |    168.424   5.232227    32.19   0.000     158.1691     178.679
    ------------------------------------------------------------------------------
    
    . margins rb5.hour6
    
    Contrasts of adjusted predictions
    Model VCE    : Semirobust
    
    Expression   : Exponentiated linear prediction, predict()
    
    ------------------------------------------------
                 |         df        chi2     P>chi2
    -------------+----------------------------------
           hour6 |
       (0 vs 5)  |          1        3.17     0.0748
       (1 vs 5)  |          1       14.53     0.0001
       (2 vs 5)  |          1        8.28     0.0040
       (3 vs 5)  |          1        2.59     0.1075
       (4 vs 5)  |          1        2.63     0.1050
       (6 vs 5)  |          1        0.54     0.4643
       (7 vs 5)  |          1        2.57     0.1089
          Joint  |          7       22.90     0.0018
    ------------------------------------------------
    
    --------------------------------------------------------------
                 |            Delta-method
                 |   Contrast   Std. Err.     [95% Conf. Interval]
    -------------+------------------------------------------------
           hour6 |
       (0 vs 5)  |  -8.516408   4.780009     -17.88505    .8522373
       (1 vs 5)  |  -14.81144   3.886262     -22.42838   -7.194507
       (2 vs 5)  |  -10.88182   3.782032     -18.29446   -3.469169
       (3 vs 5)  |  -5.545677   3.445541     -12.29881     1.20746
       (4 vs 5)  |  -4.090535    2.52343     -9.036367    .8552972
       (6 vs 5)  |   2.443756    3.33936     -4.101269    8.988782
       (7 vs 5)  |   5.636613   3.516349     -1.255304    12.52853
    --------------------------------------------------------------
    , but I cant seem to change the base level:
    Code:
    . margins,eydx(i.hour6)
    
    Conditional marginal effects                    Number of obs     =      7,801
    Model VCE    : Semirobust
    
    Expression   : Exponentiated linear prediction, predict()
    ey/dx w.r.t. : 1.hour6 2.hour6 3.hour6 4.hour6 5.hour6 6.hour6 7.hour6
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      ey/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           hour6 |
              1  |  -.0416609    .018553    -2.25   0.025    -.0780241   -.0052978
              2  |  -.0154516   .0235164    -0.66   0.511    -.0615429    .0306398
              3  |   .0190735    .025897     0.74   0.461    -.0316836    .0698306
              4  |   .0282851   .0274845     1.03   0.303    -.0255835    .0821538
              5  |   .0537343   .0302089     1.78   0.075     -.005474    .1129426
              6  |   .0686347   .0351523     1.95   0.051    -.0002626    .1375319
              7  |   .0877739   .0371598     2.36   0.018      .014942    .1606058
    ------------------------------------------------------------------------------
    Note: ey/dx for factor levels is the discrete change from the base level.
    
    . margins,eydx(ib5.hour6)
    
    Conditional marginal effects                    Number of obs     =      7,801
    Model VCE    : Semirobust
    
    Expression   : Exponentiated linear prediction, predict()
    ey/dx w.r.t. : 1.hour6 2.hour6 3.hour6 4.hour6 5.hour6 6.hour6 7.hour6
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      ey/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           hour6 |
              1  |  -.0416609    .018553    -2.25   0.025    -.0780241   -.0052978
              2  |  -.0154516   .0235164    -0.66   0.511    -.0615429    .0306398
              3  |   .0190735    .025897     0.74   0.461    -.0316836    .0698306
              4  |   .0282851   .0274845     1.03   0.303    -.0255835    .0821538
              5  |   .0537343   .0302089     1.78   0.075     -.005474    .1129426
              6  |   .0686347   .0351523     1.95   0.051    -.0002626    .1375319
              7  |   .0877739   .0371598     2.36   0.018      .014942    .1606058
    ------------------------------------------------------------------------------
    Note: ey/dx for factor levels is the discrete change from the base level.
    note base level is still 0.hour6.

    I could not find the coding syntax in pdf help for margins or contrast - but I'm sure I'm missing somethig obvious.
    thank you

  • #2
    I missed this post 5 years ago, apologies.

    Based on the output from margins it appears you are using an xtgee family that supports (or assumes) option link(log). In this case, your use of margins option eydx() with the default prediction is equivalent to margins option dydx() with option predict(xb). Thus you can either use margins with contrast operators and option predict(xb), or just use the contrast command.

    Here is an example with some data.
    Code:
    webuse airacc
    
    * fitted model
    xtgee i_cnt inprog i.time, family(poisson)
    estimates store fit
    
    * equivalent elasticity specifications
    margins, eydx(time)
    margins, dydx(time) predict(xb)
    contrast rb1.time, nowald
    contrast rb2.time, nowald
    contrast rb3.time, nowald
    contrast rb4.time, nowald
    In a more general setting, where computing eydx() elasticities is not equivalent to contrasts of the fitted coefficients, you can use contrast operators in the marginslist with option expression(log(predict(...))) where ... is the predict option of interest.

    If you have a large dataset or each margins call is taking a non-trivial time to run, I would suggest storing your estimation results and posting the predictive margins with option expression(log(predict(...))), then use contrast to quickly produce your contrasts of interest.

    Here is an example of this.
    Code:
    * equivalent syntax, when the elasticity specifications are not contrasts of
    * the estimated coefficients
    margins time, expression(log(predict(mu))) post
    estimates store margins
    contrast rb1.time, nowald
    contrast rb2.time, nowald
    contrast rb3.time, nowald
    contrast rb4.time, nowald
    Here is a log of the above code
    Code:
    . webuse airacc
    
    . 
    . * fitted model
    . xtgee i_cnt inprog i.time, family(poisson)
    
    Iteration 1:  Tolerance = .0113618
    Iteration 2:  Tolerance = .00011442
    Iteration 3:  Tolerance = 1.731e-06
    Iteration 4:  Tolerance = 1.817e-08
    
    GEE population-averaged model                        Number of obs    =     80
    Group variable: airline                              Number of groups =     20
    Family: Poisson                                      Obs per group:  
    Link:   Log                                                       min =      4
    Correlation: exchangeable                                         avg =    4.0
                                                                      max =      4
                                                         Wald chi2(4)     =   8.22
    Scale parameter = 1                                  Prob > chi2      = 0.0840
    
    ------------------------------------------------------------------------------
           i_cnt | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
          inprog |  -.0552159   .0498207    -1.11   0.268    -.1528627    .0424309
                 |
            time |
              2  |   .0626557   .0573736     1.09   0.275    -.0497944    .1751057
              3  |   -.007464   .0583644    -0.13   0.898     -.121856    .1069281
              4  |   .1223015   .0563842     2.17   0.030     .0117905    .2328124
                 |
           _cons |   3.143932   .0475939    66.06   0.000     3.050649    3.237214
    ------------------------------------------------------------------------------
    
    . estimates store fit
    
    . 
    . * equivalent elasticity specifications
    . margins, eydx(time)
    
    Average marginal effects                                    Number of obs = 80
    Model VCE: Conventional
    
    Expression: Exponentiated linear prediction, predict()
    ey/dx wrt:  2.time 3.time 4.time
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      ey/dx   std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
            time |
              2  |   .0626557   .0573736     1.09   0.275    -.0497944    .1751057
              3  |   -.007464   .0583644    -0.13   0.898     -.121856    .1069281
              4  |   .1223015   .0563842     2.17   0.030     .0117905    .2328124
    ------------------------------------------------------------------------------
    Note: ey/dx for factor levels is the discrete change from the base level.
    
    . margins, dydx(time) predict(xb)
    
    Average marginal effects                                    Number of obs = 80
    Model VCE: Conventional
    
    Expression: Linear prediction, predict(xb)
    dy/dx wrt:  2.time 3.time 4.time
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
            time |
              2  |   .0626557   .0573736     1.09   0.275    -.0497944    .1751057
              3  |   -.007464   .0583644    -0.13   0.898     -.121856    .1069281
              4  |   .1223015   .0563842     2.17   0.030     .0117905    .2328124
    ------------------------------------------------------------------------------
    Note: dy/dx for factor levels is the discrete change from the base level.
    
    . contrast rb1.time, nowald
    
    Contrasts of marginal linear predictions
    
    Margins: asbalanced
    
    --------------------------------------------------------------
                 |   Contrast   Std. err.     [95% conf. interval]
    -------------+------------------------------------------------
            time |
       (2 vs 1)  |   .0626557   .0573736     -.0497944    .1751057
       (3 vs 1)  |   -.007464   .0583644      -.121856    .1069281
       (4 vs 1)  |   .1223015   .0563842      .0117905    .2328124
    --------------------------------------------------------------
    
    . contrast rb2.time, nowald
    
    Contrasts of marginal linear predictions
    
    Margins: asbalanced
    
    --------------------------------------------------------------
                 |   Contrast   Std. err.     [95% conf. interval]
    -------------+------------------------------------------------
            time |
       (1 vs 2)  |  -.0626557   .0573736     -.1751057    .0497944
       (3 vs 2)  |  -.0701196   .0573583     -.1825399    .0423006
       (4 vs 2)  |   .0596458   .0555391     -.0492087    .1685004
    --------------------------------------------------------------
    
    . contrast rb3.time, nowald
    
    Contrasts of marginal linear predictions
    
    Margins: asbalanced
    
    --------------------------------------------------------------
                 |   Contrast   Std. err.     [95% conf. interval]
    -------------+------------------------------------------------
            time |
       (1 vs 3)  |    .007464   .0583644     -.1069281     .121856
       (2 vs 3)  |   .0701196   .0573583     -.0423006    .1825399
       (4 vs 3)  |   .1297654   .0565806      .0188695    .2406614
    --------------------------------------------------------------
    
    . contrast rb4.time, nowald
    
    Contrasts of marginal linear predictions
    
    Margins: asbalanced
    
    --------------------------------------------------------------
                 |   Contrast   Std. err.     [95% conf. interval]
    -------------+------------------------------------------------
            time |
       (1 vs 4)  |  -.1223015   .0563842     -.2328124   -.0117905
       (2 vs 4)  |  -.0596458   .0555391     -.1685004    .0492087
       (3 vs 4)  |  -.1297654   .0565806     -.2406614   -.0188695
    --------------------------------------------------------------
    
    . 
    . * equivalent syntax, when the elasticity specifications are not contrasts of
    . * the estimated coefficients
    . margins time, expression(log(predict(mu))) post
    
    Predictive margins                                          Number of obs = 80
    Model VCE: Conventional
    
    Expression: log(predict(mu))
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
            time |
              1  |   3.129437   .0468333    66.82   0.000     3.037646    3.221229
              2  |   3.192093    .045376    70.35   0.000     3.103158    3.281029
              3  |   3.121973   .0469935    66.43   0.000     3.029868    3.214079
              4  |   3.251739   .0439912    73.92   0.000     3.165518     3.33796
    ------------------------------------------------------------------------------
    
    . estimates store margins
    
    . contrast rb1.time, nowald
    
    Contrasts of predictive margins                             Number of obs = 80
    Model VCE: Conventional
    
    Expression: log(predict(mu))
    
    --------------------------------------------------------------
                 |            Delta-method
                 |   Contrast   std. err.     [95% conf. interval]
    -------------+------------------------------------------------
            time |
       (2 vs 1)  |   .0626557   .0573736     -.0497944    .1751057
       (3 vs 1)  |   -.007464   .0583644      -.121856    .1069281
       (4 vs 1)  |   .1223015   .0563842      .0117905    .2328124
    --------------------------------------------------------------
    
    . contrast rb2.time, nowald
    
    Contrasts of predictive margins                             Number of obs = 80
    Model VCE: Conventional
    
    Expression: log(predict(mu))
    
    --------------------------------------------------------------
                 |            Delta-method
                 |   Contrast   std. err.     [95% conf. interval]
    -------------+------------------------------------------------
            time |
       (1 vs 2)  |  -.0626557   .0573736     -.1751057    .0497944
       (3 vs 2)  |  -.0701196   .0573583     -.1825399    .0423006
       (4 vs 2)  |   .0596458   .0555391     -.0492087    .1685004
    --------------------------------------------------------------
    
    . contrast rb3.time, nowald
    
    Contrasts of predictive margins                             Number of obs = 80
    Model VCE: Conventional
    
    Expression: log(predict(mu))
    
    --------------------------------------------------------------
                 |            Delta-method
                 |   Contrast   std. err.     [95% conf. interval]
    -------------+------------------------------------------------
            time |
       (1 vs 3)  |    .007464   .0583644     -.1069281     .121856
       (2 vs 3)  |   .0701196   .0573583     -.0423006    .1825399
       (4 vs 3)  |   .1297654   .0565806      .0188695    .2406614
    --------------------------------------------------------------
    
    . contrast rb4.time, nowald
    
    Contrasts of predictive margins                             Number of obs = 80
    Model VCE: Conventional
    
    Expression: log(predict(mu))
    
    --------------------------------------------------------------
                 |            Delta-method
                 |   Contrast   std. err.     [95% conf. interval]
    -------------+------------------------------------------------
            time |
       (1 vs 4)  |  -.1223015   .0563842     -.2328124   -.0117905
       (2 vs 4)  |  -.0596458   .0555391     -.1685004    .0492087
       (3 vs 4)  |  -.1297654   .0565806     -.2406614   -.0188695
    --------------------------------------------------------------

    Comment


    • #3
      Jeff - thank you. i think i did a fair bit of homework and got to something like this - but i'm sure not as clearly as you have set out!
      george

      Comment

      Working...
      X