Announcement

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

  • Logit for panel data

    Hello,

    I have a very straightforward question for which I can't seem to find an answer: can I use - logit - (instead of - xtlogit -) for panel data if I specify - xtset - before?

    Specifying a bit more what my situation is, I want to know the effect of gender (and other 9 binary and non-binary variables) on the probability of filing for bankruptcy in the previous period, with N=13006 and T=40. I tried both - logit - and - xtlogit -, and both seem to give nice results, but I am inclined to use - logit - since 1) it presents a pseudo-R2, 2) I get significant results for the variable gender and 3) honestly, the table just generally looks simpler. I don't know, however, if using - logit - is totally wrong or not.

    I would be very grateful if one of you could help me with this. Thank you!

    Sofia

  • #2
    I have a straightforward answer: no, if you have panel data then you need to take that into account, and that is what -xtlogit- is for.

    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you!

      And one more question: how could I then obtain a pseudo-R2 using -xtlogit-?

      Comment


      • #4
        Sofi:
        you can get pseudo-R2 after -xtlogit- in this way:
        Code:
        . use http://www.stata-press.com/data/r14/union
        (NLS Women 14-24 in 1968)
        
        . xtlogit union age grade not_smsa south##c.year, fe nolog
        note: multiple positive outcomes within groups encountered.
        note: 2,744 groups (14,165 obs) dropped because of all positive or
              all negative outcomes.
        
        Conditional fixed-effects logistic regression   Number of obs     =     12,035
        Group variable: idcode                          Number of groups  =      1,690
        
                                                        Obs per group:
                                                                      min =          2
                                                                      avg =        7.1
                                                                      max =         12
        
                                                        LR chi2(6)        =      78.60
        Log likelihood  =  -4510.888                    Prob > chi2       =     0.0000
        
        ------------------------------------------------------------------------------
               union |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                 age |   .0710973   .0960536     0.74   0.459    -.1171643    .2593589
               grade |   .0816111   .0419074     1.95   0.051    -.0005259     .163748
            not_smsa |   .0224809   .1131786     0.20   0.843     -.199345    .2443069
             1.south |  -2.856488   .6765694    -4.22   0.000    -4.182539   -1.530436
                year |  -.0636853   .0967747    -0.66   0.510    -.2533602    .1259896
                     |
        south#c.year |
                  1  |   .0264136   .0083216     3.17   0.002     .0101036    .0427235
        ------------------------------------------------------------------------------
        
        . di e(r2_p)
        .00863656
        .
        Kind regards,
        Carlo
        (Stata 18.0 SE)

        Comment


        • #5
          Carlo:

          Thank you! I tried what you suggested but I got no results. I was wondering if that only works for fixed-effects, since this is what I tried:

          Code:
          . xtlogit bnkr1 gndr nimta1lag tlta exret rsize cntr ind seven eight nine ten eleven twelve thirteen fourteen fifteen, nolog
          
          Random-effects logistic regression              Number of obs      =    257644
          Group variable: id                              Number of groups   =     11210
          
          Random effects u_i ~ Gaussian                   Obs per group: min =         1
                                                                         avg =      23.0
                                                                         max =        39
          
          Integration method: mvaghermite                 Integration points =        12
          
                                                          Wald chi2(16)      =    380.89
          Log likelihood  = -1505.3156                    Prob > chi2        =    0.0000
          
          ------------------------------------------------------------------------------
                 bnkr1 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                  gndr |   .5300032   .3614087     1.47   0.143    -.1783448    1.238351
             nimta1lag |  -4.957597    .904459    -5.48   0.000    -6.730304    -3.18489
                  tlta |   3.359389   .3443373     9.76   0.000       2.6845    4.034278
                 exret |  -1.144998   .2405046    -4.76   0.000    -1.616379   -.6736178
                 rsize |  -1.041825   .1568063    -6.64   0.000    -1.349159   -.7344897
                  cntr |   3.072285   .5702914     5.39   0.000     1.954535    4.190036
                   ind |   -.032804   .0566942    -0.58   0.563    -.1439226    .0783147
                 seven |  -1.120693   .6126774    -1.83   0.067    -2.321519    .0801327
                 eight |   .6814726   .4231408     1.61   0.107    -.1478681    1.510813
                  nine |   1.156817    .404621     2.86   0.004     .3637743    1.949859
                   ten |    .705944   .4381467     1.61   0.107    -.1528077    1.564696
                eleven |   .5850139    .448255     1.31   0.192    -.2935497    1.463578
                twelve |   .4054139   .4472038     0.91   0.365    -.4710895    1.281917
              thirteen |  -.0071434   .4763082    -0.01   0.988    -.9406903    .9264034
              fourteen |   .5392361    .432546     1.25   0.213    -.3085385    1.387011
               fifteen |   .8644068   .3963188     2.18   0.029     .0876362    1.641177
                 _cons |  -25.92258   1.863321   -13.91   0.000    -29.57462   -22.27053
          -------------+----------------------------------------------------------------
              /lnsig2u |   2.435172   .1721748                      2.097716    2.772629
          -------------+----------------------------------------------------------------
               sigma_u |   3.379022   .2908912                       2.85439     4.00008
                   rho |   .7763159   .0298981                      .7123589    .8294567
          ------------------------------------------------------------------------------
          Likelihood-ratio test of rho=0: chibar2(01) =   112.25 Prob >= chibar2 = 0.000
          
          . 
          end of do-file
          
          . di e(r2_p)
          .
          Kind regards,
          Sofi

          Comment


          • #6
            Sofi:
            - Stata returns -e(r2_p)- for the conditional fixed-effects logistic specification;
            - Stata return -e(chi2)- for the random-effect specification.
            Hence, if you're going for the latter specification, you simply cannot get -e(r2_p).
            Kind regards,
            Carlo
            (Stata 18.0 SE)

            Comment


            • #7
              That makes sense. Thank you so much for your help.

              Kind regards,
              Sofi

              Comment


              • #8
                If you are going to use fe, you can also use the clogit command. The one advantage would be that pseudo r2 is automatically displayed in the output. You may also like the appearance slightly better.

                Code:
                . use http://www.stata-press.com/data/r14/union
                (NLS Women 14-24 in 1968)
                
                . clogit union age grade not_smsa south##c.year, group(idcode) nolog
                note: multiple positive outcomes within groups encountered.
                note: 2,744 groups (14,165 obs) dropped because of all positive or
                      all negative outcomes.
                
                Conditional (fixed-effects) logistic regression
                
                                                                Number of obs     =     12,035
                                                                LR chi2(6)        =      78.60
                                                                Prob > chi2       =     0.0000
                Log likelihood =  -4510.888                     Pseudo R2         =     0.0086
                
                ------------------------------------------------------------------------------
                       union |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                         age |   .0710973   .0960536     0.74   0.459    -.1171643    .2593589
                       grade |   .0816111   .0419074     1.95   0.051    -.0005259     .163748
                    not_smsa |   .0224809   .1131786     0.20   0.843     -.199345    .2443069
                     1.south |  -2.856488   .6765694    -4.22   0.000    -4.182539   -1.530436
                        year |  -.0636853   .0967747    -0.66   0.510    -.2533602    .1259896
                             |
                south#c.year |
                          1  |   .0264136   .0083216     3.17   0.002     .0101036    .0427235
                ------------------------------------------------------------------------------
                Last edited by Richard Williams; 28 Nov 2017, 14:37.
                -------------------------------------------
                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
                  Is there any way to get pseudo R2 for random-effect specification?

                  Comment


                  • #10
                    Taher:
                    welcome to this forum.
                    I'm not aware of any methods to get pseudo R2 for -xtlogit, re-, as Stata return -e(chi2)- for the random-effect specification
                    Kind regards,
                    Carlo
                    (Stata 18.0 SE)

                    Comment


                    • #11
                      Hello,

                      What the different between logit and xtlogit? and what are the steps that must be done for xtlogit?

                      thank you.
                      ---
                      Kind regards,
                      Aldi

                      Comment


                      • #12
                        Aldi:
                        welcome to this forum.
                        In brief: -logit- (and -logistic-) is ok when you have one wave of data only; -xtlogit- works for panel data (ie, when you have more waves of data for the same sample).
                        That said, you can get more details from the -xt- prefixed command entries in Stata .pdf manual andfrom any decent textbook on panel data econometrics.
                        Kind regards,
                        Carlo
                        (Stata 18.0 SE)

                        Comment


                        • #13
                          Originally posted by Taher Jamil View Post
                          Is there any way to get pseudo R2 for random-effect specification?
                          The Pseudo-R2 formula is 1 - llfit/ ll0, where llfit is the log likelihood of the fitted model, and ll0 is the log likelihood of the constant only model. Since you are doing random effects, you can do something like

                          Code:
                          clear all
                          set more off
                          
                          webuse union
                          xtset idcode year
                          
                          xtlogit union
                          scalar ll0 = e(ll)
                          
                          xtlogit union age grade i.not_smsa south##c.year
                          
                          di "Pseudo-R2: " 1 - e(ll)/ll0
                          Alfonso Sanchez-Penalver

                          Comment


                          • #14
                            Originally posted by Alfonso Sánchez-Peñalver View Post

                            The Pseudo-R2 formula is 1 - llfit/ ll0, where llfit is the log likelihood of the fitted model, and ll0 is the log likelihood of the constant only model. Since you are doing random effects, you can do something like

                            Code:
                            clear all
                            set more off
                            
                            webuse union
                            xtset idcode year
                            
                            xtlogit union
                            scalar ll0 = e(ll)
                            
                            xtlogit union age grade i.not_smsa south##c.year
                            
                            di "Pseudo-R2: " 1 - e(ll)/ll0
                            Dear Alfonso,

                            I have tried to get pseudo-R2 following your instructions. Could you please check if the steps are right?

                            Code:
                            . xtlogit GRI, re vce(robust)
                            
                            Fitting comparison model:
                            
                            Iteration 0:   log pseudolikelihood = -609.07376  
                            Iteration 1:   log pseudolikelihood = -609.07376  
                            
                            Fitting full model:
                            
                            tau =  0.0     log pseudolikelihood = -609.07376
                            tau =  0.1     log pseudolikelihood = -580.68084
                            tau =  0.2     log pseudolikelihood = -551.64685
                            tau =  0.3     log pseudolikelihood = -524.79147
                            tau =  0.4     log pseudolikelihood = -502.10019
                            tau =  0.5     log pseudolikelihood = -484.37493
                            tau =  0.6     log pseudolikelihood =  -472.0918
                            tau =  0.7     log pseudolikelihood = -465.45804
                            tau =  0.8     log pseudolikelihood = -465.87373
                            
                            Iteration 0:   log pseudolikelihood = -465.53053  
                            Iteration 1:   log pseudolikelihood = -360.45909  (not concave)
                            Iteration 2:   log pseudolikelihood = -360.14749  (not concave)
                            Iteration 3:   log pseudolikelihood = -360.14749  (not concave)
                            Iteration 4:   log pseudolikelihood = -358.86241  
                            Iteration 5:   log pseudolikelihood = -358.45335  
                            Iteration 6:   log pseudolikelihood = -358.45254  
                            Iteration 7:   log pseudolikelihood = -358.45254  
                            
                            Calculating robust standard errors:
                            
                            Random-effects logistic regression              Number of obs     =      3,276
                            Group variable: ID                              Number of groups  =        441
                            
                            Random effects u_i ~ Gaussian                   Obs per group:
                                                                                          min =          1
                                                                                          avg =        7.4
                                                                                          max =          9
                            
                            Integration method: mvaghermite                 Integration pts.  =         12
                            
                                                                            Wald chi2(0)      =          .
                            Log pseudolikelihood  = -358.45254              Prob > chi2       =          .
                            
                                                               (Std. Err. adjusted for 441 clusters in ID)
                            ------------------------------------------------------------------------------
                                         |               Robust
                                     GRI |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                            -------------+----------------------------------------------------------------
                                   _cons |  -7.686735     .34362   -22.37   0.000    -8.360218   -7.013252
                            -------------+----------------------------------------------------------------
                                /lnsig2u |   2.764629   .2367763                      2.300556    3.228702
                            -------------+----------------------------------------------------------------
                                 sigma_u |   3.984111   .4716715                       3.15907    5.024625
                                     rho |    .828322   .0336707                      .7520747    .8847146
                            ------------------------------------------------------------------------------
                            
                            . scalar ll0 = e(ll)
                            
                            . xtlogit GRI SIZE_w LEV_w ROA_w CAPEXSALES_w CALFCF_w i.ICBIC i.YEAR, re vce(robust)
                            note: 10.ICBIC != 0 predicts failure perfectly
                                  10.ICBIC dropped and 94 obs not used
                            
                            note: 20.ICBIC != 0 predicts failure perfectly
                                  20.ICBIC dropped and 60 obs not used
                            
                            note: 35.ICBIC != 0 predicts failure perfectly
                                  35.ICBIC dropped and 257 obs not used
                            
                            note: 65.ICBIC omitted because of collinearity
                            
                            Fitting comparison model:
                            
                            Iteration 0:   log pseudolikelihood = -588.45617  
                            Iteration 1:   log pseudolikelihood = -500.36955  
                            Iteration 2:   log pseudolikelihood = -372.23454  
                            Iteration 3:   log pseudolikelihood = -352.57462  
                            Iteration 4:   log pseudolikelihood = -351.68556  
                            Iteration 5:   log pseudolikelihood = -351.68393  
                            Iteration 6:   log pseudolikelihood = -351.68393  
                            
                            Fitting full model:
                            
                            tau =  0.0     log pseudolikelihood = -351.68393
                            tau =  0.1     log pseudolikelihood = -337.33459
                            tau =  0.2     log pseudolikelihood = -324.02502
                            tau =  0.3     log pseudolikelihood = -312.03672
                            tau =  0.4     log pseudolikelihood = -301.52068
                            tau =  0.5     log pseudolikelihood = -292.58033
                            tau =  0.6     log pseudolikelihood = -285.55344
                            tau =  0.7     log pseudolikelihood = -281.42609
                            tau =  0.8     log pseudolikelihood = -283.23886
                            
                            Iteration 0:   log pseudolikelihood = -281.33505  
                            Iteration 1:   log pseudolikelihood = -248.25193  
                            Iteration 2:   log pseudolikelihood = -242.42151  
                            Iteration 3:   log pseudolikelihood = -241.72074  
                            Iteration 4:   log pseudolikelihood = -241.71743  
                            Iteration 5:   log pseudolikelihood = -241.71733  
                            Iteration 6:   log pseudolikelihood =  -241.7166  
                            Iteration 7:   log pseudolikelihood =  -241.7166  
                            
                            Calculating robust standard errors:
                            
                            Random-effects logistic regression              Number of obs     =      2,865
                            Group variable: ID                              Number of groups  =        382
                            
                            Random effects u_i ~ Gaussian                   Obs per group:
                                                                                          min =          1
                                                                                          avg =        7.5
                                                                                          max =          9
                            
                            Integration method: mvaghermite                 Integration pts.  =         12
                            
                                                                            Wald chi2(20)     =     176.76
                            Log pseudolikelihood  =  -241.7166              Prob > chi2       =     0.0000
                            
                                                               (Std. Err. adjusted for 382 clusters in ID)
                            ------------------------------------------------------------------------------
                                         |               Robust
                                     GRI |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                            -------------+----------------------------------------------------------------
                                  SIZE_w |   2.402758   .4517696     5.32   0.000     1.517306     3.28821
                                   LEV_w |   .4664345   2.026199     0.23   0.818    -3.504843    4.437712
                                   ROA_w |   .0529381   .0319881     1.65   0.098    -.0097575    .1156337
                            CAPEXSALES_w |  -.3867555   1.913398    -0.20   0.840    -4.136947    3.363436
                                CALFCF_w |   .7934697   .9167472     0.87   0.387    -1.003322    2.590261
                                         |
                                   ICBIC |
                                     10  |          0  (empty)
                                     15  |  -5.343616   2.513504    -2.13   0.034    -10.26999   -.4172393
                                     20  |          0  (empty)
                                     30  |  -4.319857   1.727932    -2.50   0.012    -7.706542   -.9331717
                                     35  |          0  (empty)
                                     40  |  -2.310629   1.651214    -1.40   0.162     -5.54695     .925692
                                     45  |  -2.340423   1.934895    -1.21   0.226    -6.132749    1.451902
                                     50  |   -3.51768   1.654954    -2.13   0.034     -6.76133   -.2740288
                                     55  |  -2.603113   1.741397    -1.49   0.135    -6.016188    .8099617
                                     60  |  -2.627161   1.913425    -1.37   0.170    -6.377405    1.123083
                                     65  |          0  (omitted)
                                         |
                                    YEAR |
                                   2010  |   1.842385   1.408735     1.31   0.191    -.9186841    4.603454
                                   2011  |    3.38932   1.338165     2.53   0.011     .7665638    6.012076
                                   2012  |    2.78632   1.200199     2.32   0.020     .4339724    5.138668
                                   2013  |   3.031342   1.495622     2.03   0.043     .0999764    5.962707
                                   2014  |   4.732183   1.299719     3.64   0.000      2.18478    7.279585
                                   2015  |   4.675019   1.423076     3.29   0.001      1.88584    7.464197
                                   2016  |   5.867141    1.32047     4.44   0.000     3.279068    8.455214
                                   2017  |   4.610475   1.336749     3.45   0.001     1.990496    7.230455
                                         |
                                   _cons |  -40.47376   6.547187    -6.18   0.000    -53.30601   -27.64151
                            -------------+----------------------------------------------------------------
                                /lnsig2u |   2.700013   .2967942                      2.118307    3.281719
                            -------------+----------------------------------------------------------------
                                 sigma_u |    3.85745   .5724344                      2.883929    5.159602
                                     rho |   .8189375   .0440083                      .7165596    .8900127
                            ------------------------------------------------------------------------------
                            
                            . di "Pseudo-R2: " 1 - e(ll)/ll0
                            Pseudo-R2: .32566637

                            Comment


                            • #15
                              Yes Sinem Ates , what you have done is correct, and is giving you McFadden's pseudo-R.

                              Comment

                              Working...
                              X