Announcement

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

  • marginal effect of firthlogit

    Dear Statalists,
    I tried to calculate the marginal effect of firthlogit. I use "margins , expression(invlogit(predict(xb)))" following advice from #4 of this thread. (I may have understood it wrong.)

    Among the independent variables, soe fie tradecom are binary, others are continuous. But when I tried to calculate the marginal effect. An error occurred and said: factor variables may not contain noninteger values. However, limpint is continous.
    Does it mean that this way of calculation only suits factor variables? How can I calculate the marginal effect for all variables?
    Below is the code and error. Any comments would be appreciated.
    Many thanks,
    K



    Code:
     firthlogit odistarter     limpint soe fie tradecom process_share lexpint  
      
      initial:       penalized log likelihood = -49394.935
      rescale:       penalized log likelihood = -49394.935
      Iteration 0:   penalized log likelihood = -49394.935  
      Iteration 1:   penalized log likelihood = -47937.173  
      Iteration 2:   penalized log likelihood = -47677.303  
      Iteration 3:   penalized log likelihood = -47676.333  
      Iteration 4:   penalized log likelihood = -47676.333  
      
                                                      Number of obs     =  2,188,615
                                                      Wald chi2(6)      =    3255.91
      Penalized log likelihood = -47676.333           Prob > chi2       =     0.0000
      
      ------------------------------------------------------------------------------
        odistarter |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
           limpint |   5.879801   .1970857    29.83   0.000      5.49352    6.266082
               soe |   .1002127   .0401549     2.50   0.013     .0215107    .1789148
               fie |  -1.241626   .0339263   -36.60   0.000    -1.308121   -1.175132
          tradecom |   -.560522   .0309983   -18.08   0.000    -.6212775   -.4997664
      process_sh~e |  -.2379967   .0389793    -6.11   0.000    -.3143946   -.1615987
           lexpint |   6.334411   .2019787    31.36   0.000      5.93854    6.730282
             _cons |  -6.197648    .027174  -228.07   0.000    -6.250908   -6.144388
      ------------------------------------------------------------------------------
      
      . margins limpint soe fie tradecom process_share lexpint, expression(invlogit(
      > predict(xb)))
      limpint:  factor variables may not contain noninteger values
      r(452);
    Last edited by Kailin Gao; 04 Apr 2020, 22:36.

  • #2
    1. For the syntax margins <varlist>, all of the variables that you specify in the variable list must have been specified in the preceding estimation command using Stata's factor variables notation. You haven't done that.

    2. For continuous variables, you need to specify them in an option, typically dydx(), not in the variable list immediately following the margins command.

    3. I didn't think that margins works after the user-written firthlogit estimation command. I thought that you must do a little dipsy-doodle first, where you feed the coefficient vector from firthlogit to logit as initial values and then fit the model with zero iterations. I think that the help file has an auxiliary do-file that shows how to do that. (There, it's illustrated in the context of matching the standard errors that R and SAS give with the Firth method, but the technique is the same for a prelude to margins.)

    4. You have over two million observations. Why are you using firthlogit?

    Comment


    • #3
      Thank you very much Joseph! It is a great help.
      On the last point, even though I have two million observations, but dependent variable=1 is only around 7000. Even though I find notes tell me that I should not be worried about it if I have thousands of positive outcomes, I see papers concerned about rare event bias when they have this scale of positive outcomes. So I thought I should try it and see what happened.
      Thanks again.
      Best,
      K
      Last edited by Kailin Gao; 05 Apr 2020, 01:51.

      Comment


      • #4
        I am trying to do the same, however I do not exactly understand point 3 in #2 how can I feed the coefficient vector from firthlogit to logit as initial values and then fit the model with zero iterations? can you please explain the method.

        Comment


        • #5
          Originally posted by Zahid Khan View Post
          . . . how can I feed the coefficient vector from firthlogit to logit as initial values and then fit the model with zero iterations? can you please explain the method.
          ". . . the help file has an auxiliary do-file that shows how to do that."
          Code:
          type http://fmwww.bc.edu/RePEc/bocode/s/SEMatch.do
          To see it in action:
          Code:
          version 18.0
          
          local programs firthlogit.ado firthlogit_ll.ado
          foreach program of local programs {
              copy http://fmwww.bc.edu/RePEc/bocode/f/`program' `program'
          }
          
          do http://fmwww.bc.edu/RePEc/bocode/s/SEMatch.do
          margins pred
          
          foreach program of local programs {
              erase `program'
          }
          
          exit
          This assumes that you have read-write privileges in your present working directory.

          The most common use case, though, is separation, and there you would ignore standard errors altogether and you would not consider using margins. See the Remarks section of the help file.

          Comment

          Working...
          X