Announcement

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

  • Stata question: how to use -margins- with -xtnbreg-

    I'm now doing my final project, in which I like to study the interaction effect between level of urbanization (percentage of urban population) and level of democracy (polity2 score: -10 to 10) on strike incidence (country-year count). I run state like this after sorting panel data:

    xtnbreg strike c.urban##c.polity2 (other control variables), fe

    then I want the marginal effect of urban at different level of polity2, so I run:

    margins, dydx(urban) \\Actually I tried all kinds of things here but nothing works.

    But the state just keep saying "default prediction is a function of possibly stochastic quantities other than e(b)". I've been tortured for two days by this, searching lots of solutions but still no clue. I'm now posting my question here for suggestions and advice. Thank you all!

  • #2
    There is nothing obviously wrong with your code, and I cannot replicate your difficulty in my own Stata setup using similar commands on a different data set:

    Code:
    . webuse airacc, clear
    
    . xtset
           panel variable:  airline (strongly balanced)
            time variable:  time, 1 to 4
                    delta:  1 unit
    
    . xtnbreg i_cnt c.ait##c.relsize, exposure(pmiles) fe
    
    Iteration 0:   log likelihood = -176.26768  
    Iteration 1:   log likelihood = -174.06367  
    Iteration 2:   log likelihood = -173.86394  
    Iteration 3:   log likelihood = -173.86266  
    Iteration 4:   log likelihood = -173.86266  
    
    Conditional FE negative binomial regression     Number of obs     =         80
    Group variable: airline                         Number of groups  =         20
    
                                                    Obs per group:
                                                                  min =          4
                                                                  avg =        4.0
                                                                  max =          4
    
                                                    Wald chi2(3)      =       2.86
    Log likelihood  = -173.86266                    Prob > chi2       =     0.4133
    
    ---------------------------------------------------------------------------------
              i_cnt |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    ----------------+----------------------------------------------------------------
                ait |   .9909921   .9405635     1.05   0.292    -.8524786    2.834463
            relsize |   .0546052   .1442965     0.38   0.705    -.2282108    .3374213
                    |
    c.ait#c.relsize |  -.0704317   .2304945    -0.31   0.760    -.5221926    .3813292
                    |
              _cons |  -4.244062    1.06006    -4.00   0.000    -6.321741   -2.166384
         ln(pmiles) |          1  (exposure)
    ---------------------------------------------------------------------------------
    
    . margins, dydx(ait) at(relsize = (2.25(0.25)3.75))
    
    Average marginal effects                        Number of obs     =         80
    Model VCE    : OIM
    
    Expression   : Linear prediction, predict()
    dy/dx w.r.t. : ait
    
    1._at        : relsize         =        2.25
    
    2._at        : relsize         =         2.5
    
    3._at        : relsize         =        2.75
    
    4._at        : relsize         =           3
    
    5._at        : relsize         =        3.25
    
    6._at        : relsize         =         3.5
    
    7._at        : relsize         =        3.75
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    ait          |
             _at |
              1  |   .8325207   .5419272     1.54   0.124    -.2296371    1.894679
              2  |   .8149128   .5111028     1.59   0.111    -.1868303    1.816656
              3  |   .7973049   .4851886     1.64   0.100    -.1536474    1.748257
              4  |    .779697   .4650064     1.68   0.094    -.1316988    1.691093
              5  |    .762089   .4513256     1.69   0.091    -.1224929    1.646671
              6  |   .7444811   .4447467     1.67   0.094    -.1272064    1.616169
              7  |   .7268732   .4455844     1.63   0.103    -.1464561    1.600202
    ------------------------------------------------------------------------------
    
    .
    Moreover, with -xtnbreg, fe-, I can't imagine what kind of stochastic quantities other than e(b) might be involved. I know that there are several Stata commands that produced this kind of error message incorrectly that have been fixed in recent updates. So I think the first step would be to make sure your Stata is completely up to date. Run -update all, force- and try it again. If that doesn't work*, please post back showing an example of data that produces the problem and the exact commands and complete output you got from Stata (within code delimiters as I have done above--see FAQ #12 if you don't know about code delimiters.)

    *If you are working on a network that you don't control, it is possible you will be unable to do the update either due to firewall issues, or because your local IT has cached an out of date version of Stata that it redirects you to when you try to run -update-. So if you are working on a network, if the -update- doesn't obviously fail, after the -update- run -about- and check that the second line of Stata's output says "Revision 16 Nov 2016." If it gives an earlier date, then the update has failed. In that case contact your IT department and ask them to enable you to do a real update. Then try your code again.

    Comment


    • #3
      Thank you so much! It does work after I updated Stata!!

      Comment


      • #4
        Just for those who are nonetheless struggling with this issue. I just discovered that controlling for the lag of the dependent variable with xtnbreg in stata leads to the described error as well. It can be overcome by manually creating a lagged dependent variable without the prescript L. Just for those for whom the previous solution did not solve the problem.

        Comment

        Working...
        X