Announcement

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

  • Margins after Xtlogit,re

    Dear Stata Forum.

    I have a (very) large panel dataset covering the years 1992-2011 with a total of 4,000,000 observations. The panel dataset is unbalanced. I use a random effect logit model to estimate the following model: d_promoted = constant + network + controls, where the d_promoted either takes the value 0 or 1. This runs. The problem occurs when I want to get the marginal effects.

    I have used margins, dydx(*), however this produces the same results as the coefficients in the xtlogit.
    I have also tried: mfx compute, predict(pu0) however, I get the following error: "predict() expression pu0 unsuitable for marginal-effect calculation.

    Any ideas on how to get the marginal effects for all the variables after running xtlogit, re that are not the same as the coefficients.

    Code:

    xtset pnr aar
    xtlogit d_promoted network_1 $controls1, re i(pnr) nolog
    margins, dydx(*)
    mfx compute, predict(pu0)

    Thanks in advance, and best regards, Daniel.

  • #2
    The default predictor for -margins- after -xtlogit, re- is the predicted probability, so you should not be getting the same results from -margins- as your regression coefficients unless your data support an extraordinary coincidence that these are in fact equal. Your syntax appears correct (although the -i(npr)- option in -xtlogit- is unnecessary). I cannot replicate your problem in my Stata setup using a standard data set:

    Code:
    . webuse nlswork, clear
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . xtlogit union tenure i.south, re
    
    Fitting comparison model:
    
    Iteration 0:   log likelihood = -10366.301  
    Iteration 1:   log likelihood = -9985.0094  
    Iteration 2:   log likelihood = -9977.0989  
    Iteration 3:   log likelihood = -9977.0962  
    Iteration 4:   log likelihood = -9977.0962  
    
    Fitting full model:
    
    tau =  0.0     log likelihood = -9977.0962
    tau =  0.1     log likelihood = -9557.3249
    tau =  0.2     log likelihood = -9201.2045
    tau =  0.3     log likelihood = -8895.9356
    tau =  0.4     log likelihood = -8631.2956
    tau =  0.5     log likelihood = -8400.9051
    tau =  0.6     log likelihood = -8202.7088
    tau =  0.7     log likelihood = -8040.6301
    tau =  0.8     log likelihood = -7932.5701
    
    Iteration 0:   log likelihood = -8040.1112  
    Iteration 1:   log likelihood = -7706.2892  
    Iteration 2:   log likelihood =  -7670.639  
    Iteration 3:   log likelihood = -7668.6628  
    Iteration 4:   log likelihood = -7668.6628  (backed up)
    Iteration 5:   log likelihood = -7668.6437  
    Iteration 6:   log likelihood = -7668.6437  
    
    Random-effects logistic regression              Number of obs     =     19,007
    Group variable: idcode                          Number of groups  =      4,134
    
    Random effects u_i ~ Gaussian                   Obs per group:
                                                                  min =          1
                                                                  avg =        4.6
                                                                  max =         12
    
    Integration method: mvaghermite                 Integration pts.  =         12
    
                                                    Wald chi2(2)      =     257.53
    Log likelihood  = -7668.6437                    Prob > chi2       =     0.0000
    
    ------------------------------------------------------------------------------
           union |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          tenure |   .0929175   .0080217    11.58   0.000     .0771954    .1086397
         1.south |  -1.115711   .0989584   -11.27   0.000    -1.309666   -.9217557
           _cons |  -2.374748   .0793366   -29.93   0.000    -2.530245   -2.219252
    -------------+----------------------------------------------------------------
        /lnsig2u |   1.983892   .0544719                      1.877129    2.090655
    -------------+----------------------------------------------------------------
         sigma_u |   2.696476   .0734412                      2.556309     2.84433
             rho |   .6884846   .0116828                      .6651392    .7109099
    ------------------------------------------------------------------------------
    LR test of rho=0: chibar2(01) = 4616.90                Prob >= chibar2 = 0.000
    
    . margins, dydx(*)
    
    Average marginal effects                        Number of obs     =     19,007
    Model VCE    : OIM
    
    Expression   : Pr(union=1), predict(pr)
    dy/dx w.r.t. : tenure 1.south
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          tenure |   .0084515   .0007451    11.34   0.000      .006991    .0099119
         1.south |  -.0989896   .0085359   -11.60   0.000    -.1157197   -.0822595
    ------------------------------------------------------------------------------
    Note: dy/dx for factor levels is the discrete change from the base level.
    The marginal effects calculated are clearly different from the regression coefficients.

    I think you should show an example of your data (use -dataex-, see FAQ #12 if you are not familiar with it) and the full, exact output you are getting from Stata.

    I'm not responding about -mfx- because I am not familiar with its workings.

    Comment


    • #3
      Dear Clyde,
      I'm wondering if you could help me with this please. It seems that I'm having the same problem and getting the same results using margins after running xtlogit. Please find the attached log file where I'm replicating your example but getting a different set of results. What's wrong with my Stata? I'm using Stata 14 with all things updated. Thank you very much.
      Best wishes,
      Meng Song
      Attached Files

      Comment


      • #4
        In both Stata 14 and 15, I can replicate both your results and Clyde's with the commands

        Code:
        webuse nlswork, clear
        xtlogit union tenure i.south, re
        margins, dydx(*) predict(pr)
        margins, dydx(*) predict(xb)
        Code:
        . margins, dydx(*) predict(pr)
        
        Average marginal effects                        Number of obs     =     19,007
        Model VCE    : OIM
        
        Expression   : Pr(union=1), predict(pr)
        dy/dx w.r.t. : tenure 1.south
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              tenure |   .0084515   .0007451    11.34   0.000      .006991    .0099119
             1.south |  -.0989896   .0085359   -11.60   0.000    -.1157197   -.0822595
        ------------------------------------------------------------------------------
        Note: dy/dx for factor levels is the discrete change from the base level.
        
        . 
        . margins, dydx(*) predict(xb)
        
        Average marginal effects                        Number of obs     =     19,007
        Model VCE    : OIM
        
        Expression   : Linear prediction, predict(xb)
        dy/dx w.r.t. : tenure 1.south
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              tenure |   .0929175   .0080217    11.58   0.000     .0771954    .1086397
             1.south |  -1.115711   .0989584   -11.27   0.000    -1.309666   -.9217557
        ------------------------------------------------------------------------------
        Note: dy/dx for factor levels is the discrete change from the base level.
        Are you really really really sure that you are using a fully up to date version of Stata 14? It seems odd to me that you apparently have a different default option than Clyde and I do. When I dig out my trusty old copy of Stata 13, I get the same results as you. Default options for margins after xtlogit apparently changed between versions 13 and 14.

        In any event, if margins seems to be producing different results for different people, pay attention to the expression lines, which in this case are

        Code:
        Expression  : Pr(union=1), predict(pr)
        Expression   : Linear prediction, predict(xb)
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        Stata Version: 17.0 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          Dear Richard,
          Thank you so much! What you advised was really the problem that I was running into. I updated my Stata 14 and this solved the problem. "margins, dydx(*) predict(pr)" and "margins, dydx(*)" give me the correct answers. Previously I noticed margins gave me linear prediction, but didn't know how to change the expression. So I was using predict(pu(0)) option but wasn't satisfied with the assumption that random effects must be zero. Many thanks indeed for your post.
          Best wishes,
          Meng

          Comment

          Working...
          X