Announcement

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

  • Cannot estimate marginal effect after xtlogit

    Dear All,, I am using stata 13 and estimating panel logit model. I am using unbalanced panel data with household id as the grouping observation.


    for the estimation I use the command :


    xtset hh
    xtlogit school_enroll cog_ability age sex, fe


    however after I run the command:

    margins, dydx(*) atmeans post]margins, dydx(*) atmeans post


    Stata reported as following:

    default predict option not appropriate with margins


    but when I tried without fe option, there is no problem with the margins command

    Is there anyway for me to get the marginal effects for fixed effect logit model?


    Thank You


    Dono Iskandar




  • #2
    The Stata 14 documentation is much better on the use of margins with specific commands. See page 4 of

    http://www.stata.com/manuals14/xtxtl...estimation.pdf

    You probably want to use the -pu0- option.
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    Stata Version: 17.0 MP (2 processor)

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

    Comment


    • #3
      Thank You so much Richard, I am really appreciate your help.. You really save my day I've tried to look at the margins section at stata 13 manual, this whole noon,,.

      if you dont mind, I have another question but a bit out of the topic,
      another thing that make me curious, before knowing about that pu0 command, I have trouble when using margins effect for my re model.

      Stata always reported that the expression is : Linear prediction, predict()
      instead of Pr(enroll) after I estimate my model using xtlogit, re and I found all of the marginal effects are exactly the same with the logit coefficients like the following output. I wonder why is that, because I thought the default for stata is to use the Pr() expressions for the margins command.
      Code:
      xtlogit enroll brother07 sister07 sex age par_enroll number_school ///
      Code:
        >  if poor == 0, nolog
        
        Random-effects logistic regression              Number of obs      =      5855
        Group variable: hh                              Number of groups   =      3592
        
        Random effects u_i ~ Gaussian                   Obs per group: min =         1
                                                                       avg =       1.6
                                                                       max =         7
        
        Integration method: mvaghermite                 Integration points =        12
        
                                                        Wald chi2(6)       =   1233.30
        Log likelihood  = -1264.8622                    Prob > chi2        =    0.0000
        
        -------------------------------------------------------------------------------
               enroll |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        --------------+----------------------------------------------------------------
            brother07 |  -.0496489   .0520946    -0.95   0.341    -.1517524    .0524546
             sister07 |  -.0478082   .0529908    -0.90   0.367    -.1516682    .0560518
                  sex |  -.1155652   .1022701    -1.13   0.258    -.3160108    .0848805
                  age |   1.032164    .029475    35.02   0.000     .9743938    1.089934
           par_enroll |   .9677722   .2827846     3.42   0.001     .4135245     1.52202
        number_school |   .0297695     .00967     3.08   0.002     .0108168    .0487223
                _cons |  -7.398123   .3711037   -19.94   0.000    -8.125473   -6.670773
        --------------+----------------------------------------------------------------
             /lnsig2u |  -14.45897   17.67616                      -49.1036    20.18566
        --------------+----------------------------------------------------------------
              sigma_u |   .0007249   .0064067                      2.17e-11    24169.08
                  rho |   1.60e-07   2.82e-06                      1.44e-22           1
        -------------------------------------------------------------------------------
        Likelihood-ratio test of rho=0: chibar2(01) =     0.00 Prob >= chibar2 = 1.000
        
        . 
        end of do-file
        
        . margins, dydx(brother07 sister07 sex )
        
        Average marginal effects                          Number of obs   =       5855
        Model VCE    : OIM
        
        Expression   : Linear prediction, predict()
        dy/dx w.r.t. : brother07 sister07 sex
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
           brother07 |  -.0496489   .0520946    -0.95   0.341    -.1517524    .0524546
            sister07 |  -.0478082   .0529908    -0.90   0.367    -.1516682    .0560518
                 sex |  -.1155652   .1022701    -1.13   0.258    -.3160108    .0848805
        ------------------------------------------------------------------------------
      Thanks

      Comment


      • #4
        That is because the default option for re is -xb-, the linear prediction. Again consider -pu0- instead.
        -------------------------------------------
        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
          Ok.. I understand now.. Thank You Richard..

          Comment


          • #6
            I don't know how the problems I discuss below affect -dydx- margins with -pu0-, so this post might not be relevant to Dono's analysis. They do apply to margins where the target is -pu0- itself, i.e. a predicted probability.

            -pu0- gives the predicted value when the fixed effect is zero. But zero may not be a plausible value in the unconditional logistic model. For example: consider an unconditional model Y= logit(P) = a + ln(2)X, corresponding to OR = 2.0, for a one-unit increase in X. If the likely range of probabilities is 0.01 to 0.30, the corresponding range of Y is about -4.60 to -0.85. If X > -1, then a = 0 is not possible.

            A similar situation: If X=0 is possible (if, for example, X is centered), then a = 0 implies that when X=0, the unconditional probability is P = 0.5. Again, this P might be outside the range of plausible values. Therefore I don't find much use for -pu0-prediction (or -pc1- prediction, for that matter) after xtlogit with the fe or re options.

            To get "real" unconditional predictions from xtlogit, fe or re, (or from clogit), I would go for prediction of -xb-, specify a range of intercepts myself, then convert to unconditional probabilities. I haven't done this, but it might be possible with the Jeff Pitblado's transform_margins command. See Jeff's post at:
            http://stats.stackexchange.com/quest.../164212#164212
            Last edited by Steve Samuels; 04 Aug 2015, 21:42.
            Steve Samuels
            Statistical Consulting
            [email protected]

            Stata 14.2

            Comment


            • #7

              Jeff Pitblado's command transform_margins will operate on xb predictions and CI endpoints, Suppose you want add an intercept "a" to the logit from xtreg, fe or re. Then Jeff's program adds "a" to xb, then takes the inverse-logit. The resulting margins are not averages of probabilities, but are probabilities evaluated the marginal average logits.

              In contrast, Roger Newson's esetran (requires parmest, both at SSC), will operate on -pu0- predictions in the margins statement. In other words, one can add "a" to the logit of pu0. Then transform back to probabilities. The results are averages of synthetic probabilities, analogous to the averages of unconditional probabilities from logistic or logit (in which the intercept is estimated).

              In what follows, I estimate the probability of low birthweight. In many populations, the probabilities are between 10% and 20%. The pu0's are much too high, so I subtract a constant (1.2), found by trial and error. ( In practice, one would try a range of constants and would have to pay attention to other predictors.). I use clogit, which is equivalent to xtlogit, fe. The same approach will work with xtlogit, re.
              Code:
              /* Get programs if necessary */
              which transform_margins
              if _rc {
                  net from http://www.stata.com/users/jpitblado
                  net describe transform_margins
                  net install transform_margins
              }
              which parmest
              if _rc {
                  ssc install parmest
              }
              which esetran
              if _rc{
                  ssc install esetran
              }
              
              webuse lowbirth2
              /* Roger Newson's esetran */
              qui clogit low lwt smoke ptd ht ui i.race, group(pairid)
              margins i.race, predict(pu0)
              preserve // parmest creates a new dataset
              parmest, bmat(r(b)) vmat(r(V)) fast
              esetran estimate stderr, transform(logit)
              parmcip, replace
              foreach Y of varlist estimate min* max* {
               replace `Y'=invlogit(`Y' -1.2)
              }
              list parm estimate min95 max95, abbr(32)
              restore
              /* Jeff Pitblado's transform_margins */
              qui clogit low lwt smoke ptd ht ui i.race, group(pairid)
              qui margins i.race, predict(xb)
              transform_margins invlogit(@ -1.2)
              Results:
              Code:
              /* 1. margins of pu0 */
              . margins i.race, predict(pu0)
              
              Predictive margins                              Number of obs     =        112
              Model VCE    : OIM
              
              Expression   : Pr(low|fixed effect is 0), predict(pu0)
              
              ------------------------------------------------------------------------------
                           |            Delta-method
                           |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
              -------------+----------------------------------------------------------------
                      race |
                    white  |    .336374    .189658     1.77   0.076    -.0353488    .7080968
                    black  |   .4280048   .2323378     1.84   0.065     -.027369    .8833786
                    other  |   .3325409   .2577436     1.29   0.197    -.1726272    .8377091
              ------------------------------------------------------------------------------
              /* 2. Margins after etran */
                +--------------------------------------------+
                   |   parm    estimate       min95       max95 |
                   |--------------------------------------------|
                1. | 1.race   .13244689    .0280662   .44663694 |
                2. | 2.race    .1839223   .03389332   .59147442 |
                3. | 3.race   .13048072   .01517696   .59369302 |
                   +--------------------------------------------+
              /* 3. After transform_margins */
              
              . transform_margins invlogit(@ -1.2)
              ----------------------------------------------
                           |         b         ll         ul
              -------------+--------------------------------
                      race |
                    white  |  .1094062   .0101652   .5950602
                    black  |  .1786594    .013971    .769553
                    other  |  .1069639   .0041033   .7768792
              ----------------------------------------------


              Steve Samuels
              Statistical Consulting
              [email protected]

              Stata 14.2

              Comment


              • #8
                Interesting discussion. It says in the xtlogit postestimation documentation for pu0 that "This may not be similar to the proportion of observed outcomes in the group." The sort of things Steven is discussing would be good for a FAQ or as an addition to the documentation. This sort of question comes up quite often so for now I am going to bookmark this thread.
                -------------------------------------------
                Richard Williams, Notre Dame Dept of Sociology
                Stata Version: 17.0 MP (2 processor)

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

                Comment


                • #9
                  Hi Steve, I was wondering if there is any updated command or technique on marginal effects from clogit? Thanks in advance.

                  Comment


                  • #10
                    Dear Steve Samuels,
                    I appreciate your note. I have couple of questions to make sure that I'm getting the right things. First, in your transform margin example, what is the base category for race? Second, you have only included one factor variable for marginal effect but how about the other variables that you have in logit (clogit)? When I run my model including all the variables I can't get the marginal effects. Am I missing something?

                    Comment


                    • #11
                      Can anybody answer the questions above?

                      Comment


                      • #12
                        Originally posted by Steve Samuels View Post
                        Jeff Pitblado's command transform_margins will operate on xb predictions and CI endpoints, Suppose you want add an intercept "a" to the logit from xtreg, fe or re. Then Jeff's program adds "a" to xb, then takes the inverse-logit. The resulting margins are not averages of probabilities, but are probabilities evaluated the marginal average logits.

                        In contrast, Roger Newson's esetran (requires parmest, both at SSC), will operate on -pu0- predictions in the margins statement. In other words, one can add "a" to the logit of pu0. Then transform back to probabilities. The results are averages of synthetic probabilities, analogous to the averages of unconditional probabilities from logistic or logit (in which the intercept is estimated).

                        In what follows, I estimate the probability of low birthweight. In many populations, the probabilities are between 10% and 20%. The pu0's are much too high, so I subtract a constant (1.2), found by trial and error. ( In practice, one would try a range of constants and would have to pay attention to other predictors.). I use clogit, which is equivalent to xtlogit, fe. The same approach will work with xtlogit, re.
                        Code:
                        /* Get programs if necessary */
                        which transform_margins
                        if _rc {
                        net from http://www.stata.com/users/jpitblado
                        net describe transform_margins
                        net install transform_margins
                        }
                        which parmest
                        if _rc {
                        ssc install parmest
                        }
                        which esetran
                        if _rc{
                        ssc install esetran
                        }
                        
                        webuse lowbirth2
                        /* Roger Newson's esetran */
                        qui clogit low lwt smoke ptd ht ui i.race, group(pairid)
                        margins i.race, predict(pu0)
                        preserve // parmest creates a new dataset
                        parmest, bmat(r(b)) vmat(r(V)) fast
                        esetran estimate stderr, transform(logit)
                        parmcip, replace
                        foreach Y of varlist estimate min* max* {
                        replace `Y'=invlogit(`Y' -1.2)
                        }
                        list parm estimate min95 max95, abbr(32)
                        restore
                        /* Jeff Pitblado's transform_margins */
                        qui clogit low lwt smoke ptd ht ui i.race, group(pairid)
                        qui margins i.race, predict(xb)
                        transform_margins invlogit(@ -1.2)
                        Results:
                        Code:
                        /* 1. margins of pu0 */
                        . margins i.race, predict(pu0)
                        
                        Predictive margins Number of obs = 112
                        Model VCE : OIM
                        
                        Expression : Pr(low|fixed effect is 0), predict(pu0)
                        
                        ------------------------------------------------------------------------------
                        | Delta-method
                        | Margin Std. Err. z P>|z| [95% Conf. Interval]
                        -------------+----------------------------------------------------------------
                        race |
                        white | .336374 .189658 1.77 0.076 -.0353488 .7080968
                        black | .4280048 .2323378 1.84 0.065 -.027369 .8833786
                        other | .3325409 .2577436 1.29 0.197 -.1726272 .8377091
                        ------------------------------------------------------------------------------
                        /* 2. Margins after etran */
                        +--------------------------------------------+
                        | parm estimate min95 max95 |
                        |--------------------------------------------|
                        1. | 1.race .13244689 .0280662 .44663694 |
                        2. | 2.race .1839223 .03389332 .59147442 |
                        3. | 3.race .13048072 .01517696 .59369302 |
                        +--------------------------------------------+
                        /* 3. After transform_margins */
                        
                        . transform_margins invlogit(@ -1.2)
                        ----------------------------------------------
                        | b ll ul
                        -------------+--------------------------------
                        race |
                        white | .1094062 .0101652 .5950602
                        black | .1786594 .013971 .769553
                        other | .1069639 .0041033 .7768792
                        ----------------------------------------------

                        Why is invlogit(@ -1.2) used for transformation in transform_margins? The original author of this module did not mention anything about this in the Stata help documentation. According to this logic, the help documentation is incorrect. Can you clarify this? I really can't understand.

                        Comment


                        • #13
                          Originally posted by Richard Williams View Post
                          Interesting discussion. It says in the xtlogit postestimation documentation for pu0 that "This may not be similar to the proportion of observed outcomes in the group." The sort of things Steven is discussing would be good for a FAQ or as an addition to the documentation. This sort of question comes up quite often so for now I am going to bookmark this thread.
                          Can Professor Richard understand Why invlogit(@ -1.2) is used for transformation in transform_margins?

                          Comment


                          • #14
                            Steve Samuels, who did this way back in 2015 (!) could answer you best. But his stated reason at the time was

                            The pu0's are much too high, so I subtract a constant (1.2), found by trial and error.

                            So, I don't think there is anything magical about the number. He just used it because it seemed to work ok. He also added

                            ( In practice, one would try a range of constants and would have to pay attention to other predictors.)
                            -------------------------------------------
                            Richard Williams, Notre Dame Dept of Sociology
                            Stata Version: 17.0 MP (2 processor)

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

                            Comment


                            • #15
                              Thank you, Professor Richard!

                              Comment

                              Working...
                              X