Announcement

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

  • Marginal effects in a panel dataset (xtprobit)

    Hi all,

    please excuse if this has been asked before, I've tried to read as many posts regarding xtprobit in a panel dataset, but to be honest haven't really gotten an answer to my question yet.

    I am just now trying to familiarise myself with probit /logit in a panel dataset. However, when trying to get marginal effects for each of the variables I'm running probit with, I only get errors or unreasonable values. When I type in "margins x y z", I get "factor variables may not contain noninteger values" and don't really understand why I'm seeing that.

    I am pretty much looking like "dprobit", or a way how to apply "margins" so that it would yield the marginal effect for each variable.

    Can someone kindly help me with that?

    Thanks

  • #2
    The problem is most likely with the original regression. Please show the exact commands and Stata output from your regression and margins commands (including any warnings or error messages along the way.)

    Also, saying "I only get errors or unreasonable values" really isn't helpful. There are literally thousands of error messages Stata can give. How can somebody help without knowing which. And what are "unreasonable" values? Unreasonableness, like beauty, is in the eye of the beholder. Always give specific descriptions, and, better even than describing things, show the actual code and output. The more you help others understand what is going on, the better your chances of getting help.

    Added: Since Stata is complaning that your data are not suitable for factor variables, it is probably best to also show an example of your data, using the -datatex- command. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      I agree with Clyde.Buy my guess is you did something like

      probit y x
      margins x

      where x is a continuous variable with noninteger values. If so, you would get the message you got. Instead you need something like

      probit y i.x
      margins x

      where x is a categorical variable. But if x is a continuous var with non-integer values, you will get an error after the probit command.

      There are various other possibilities I could run through, but it will be much easier if you provide the kind of info Clyde suggested. Also indicating your version of Stata may be helpful.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

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

      Comment


      • #4
        Clyde Schechter ,
        Richard Williams ,

        thank you for your replies. Please find attached both a data snippet using dataex as well as regression results. Hope this helps clarifying.

        Code:
        xtprobit DummyTarget lMV logAssets RoA RoE CapexAssets BVMV DtoA NetDebtR
        
        Fitting comparison model:
        
        Iteration 0:   log likelihood = -4076.6435  
        Iteration 1:   log likelihood = -3972.7326  
        Iteration 2:   log likelihood = -3971.7516  
        Iteration 3:   log likelihood = -3971.7486  
        Iteration 4:   log likelihood = -3971.7486  
        
        Fitting full model:
        
        rho =  0.0     log likelihood = -3971.7486
        rho =  0.1     log likelihood = -3345.5616
        rho =  0.2     log likelihood =  -2954.613
        rho =  0.3     log likelihood = -2678.2346
        rho =  0.4     log likelihood = -2468.1423
        rho =  0.5     log likelihood = -2301.0798
        rho =  0.6     log likelihood = -2164.0037
        rho =  0.7     log likelihood = -2046.6138
        rho =  0.8     log likelihood = -1951.6604
        
        Iteration 0:   log likelihood = -2044.9917  
        Iteration 1:   log likelihood = -897.08743  
        Iteration 2:   log likelihood = -893.87082  
        Iteration 3:   log likelihood = -887.36095  
        Iteration 4:   log likelihood = -843.80358  (not concave)
        Iteration 5:   log likelihood =  -834.5357  (not concave)
        Iteration 6:   log likelihood = -834.04178  (not concave)
        Iteration 7:   log likelihood = -833.41384  (not concave)
        Iteration 8:   log likelihood = -833.37299  (not concave)
        Iteration 9:   log likelihood =  -833.3192  (not concave)
        Iteration 10:  log likelihood = -833.21623  (not concave)
        Iteration 11:  log likelihood = -833.21623  (not concave)
        Iteration 12:  log likelihood = -824.80949  (not concave)
        Iteration 13:  log likelihood = -824.76471  
        Iteration 14:  log likelihood = -816.86937  (not concave)
        Iteration 15:  log likelihood = -816.45553  (not concave)
        Iteration 16:  log likelihood = -815.20102  
        Iteration 17:  log likelihood = -814.95537  
        Iteration 18:  log likelihood = -814.37529  
        Iteration 19:  log likelihood = -813.63325  
        Iteration 20:  log likelihood = -813.62716  
        Iteration 21:  log likelihood = -813.62666  
        Iteration 22:  log likelihood = -813.62665  
        
        Random-effects probit regression                Number of obs     =     11,161
        Group variable: nDSCD                           Number of groups  =      2,568
        
        Random effects u_i ~ Gaussian                   Obs per group:
                                                                      min =          1
                                                                      avg =        4.3
                                                                      max =          6
        
        Integration method: mvaghermite                 Integration pts.  =         12
        
                                                        Wald chi2(8)      =      83.58
        Log likelihood  = -813.62665                    Prob > chi2       =     0.0000
        
        ------------------------------------------------------------------------------
         DummyTarget |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                 lMV |   .3022343   .1016767     2.97   0.003     .1029516    .5015171
           logAssets |    -.25876   .0969837    -2.67   0.008    -.4488446   -.0686753
                 RoA |    .339834   .2658492     1.28   0.201    -.1812208    .8608888
                 RoE |  -.0010023   .0005499    -1.82   0.068      -.00208    .0000755
         CapexAssets |   1.666024   1.092997     1.52   0.127    -.4762112     3.80826
                BVMV |  -.0471042   .0839986    -0.56   0.575    -.2117384    .1175299
                DtoA |   1.526989   .1888037     8.09   0.000     1.156941    1.897038
            NetDebtR |  -.0007167   .0029551    -0.24   0.808    -.0065085    .0050751
               _cons |  -16.57642   .7791943   -21.27   0.000    -18.10362   -15.04923
        -------------+----------------------------------------------------------------
            /lnsig2u |   5.583997   .0506974                      5.484632    5.683362
        -------------+----------------------------------------------------------------
             sigma_u |   16.31359   .4135285                      15.52289    17.14456
                 rho |   .9962565   .0001891                      .9958671    .9966094
        ------------------------------------------------------------------------------
        LR test of rho=0: chibar2(01) = 6316.24                Prob >= chibar2 = 0.000
        
        
        margins lMV logAssets RoA RoE CapexAssets BVMV DtoA NetDebtR
        lMV:  factor variables may not contain noninteger values

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input byte DummyTarget float(lMV logAssets RoA RoE CapexAssets BVMV DtoA NetDebtR)
        0   1.453953 11.664908  -.0408456 -1.1902378 .00014603055  2.1049714  .7142526  12.264994
        0   2.207175  11.55676 -.02910577  -.7612015  .0008231162  2.3763452  .7132493  11.777856
        0   2.460443 12.215607 .036574617  1.8485607   .008458964    .754599  .7556608   7.247408
        0  3.9710464  12.46747  .02117429   1.376721   .009104944   .6525056  .6987669   6.489099
        0   4.594008 12.541637 .016829552  1.1784731    .03953229   .6406284  .6668478   5.508545
        0   4.651863         .          .          .            .          .         .          .
        0  3.5432756  9.043341  .08000473  .16946183   .009926732  .18051773         0  -7.132037
        0  3.3396766  9.036582 -.06805473 -.14317897    .06579417  .20840573         0  11.652324
        0  4.4767685  9.189014  .07968128  .19524406   .023393605  .06699593         0 -14.181996
        0    3.94294  8.964696  -.1673485  -.3276596    .03183329   .0877684         0   3.880843
        0   4.157945  8.895493 -.13604604  -.2485607       .02699  .05479944         0  3.1130075
        0   3.083285  9.089979  -.4387548  -.9737172   .008233702 .017683709  .4651478   .6129819
        0   4.193888  11.19987  .06892685   1.261577    .03052475   .7586918 .07501265  -.3747924
        0   4.259718 11.263592  .08494585  1.6570714    .03411949   .6719463 .11551096   .3917316
        0  4.3461404 11.327222   .0753263  1.5659574   .037145402  .50826466  .1538193  .58658063
        0   4.706914 11.390114  .11451443   2.535169    .02415115   .4379109 .12513144  .20940617
        0   4.859037  11.41958  .09087915  2.0720901     .0546724   .4260131 .10168189   .1812661
        0   5.208721 11.506806  .10490995  2.6100125    .05393903   .3493207 .09889325  .25381103
        0   1.196948  8.359603  .05127605  .05481852            0  1.5528142         0  -5.830601
        0  1.0508217  8.131236   -.224772 -.19123904            .  1.1959686         0          .
        0 -1.3862944  7.541683  -.7745358  -.3654568            .  1.0919023         .          .
        0  -2.207275  7.118016  -.5437601 -.16795994            .  1.4649243         .          .
        0  -2.525729  7.170888  -.1206764 -.03929912            .  1.7688603         .          .
        0  -.0725707         .          .          .            .          .         .          .
        0   9.147444 19.192953 .002979654   161.4518   .000205573   .3464542 .06478414  -171.1594
        end
        
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input byte DummyTarget float(lMV logAssets RoA RoE CapexAssets BVMV DtoA NetDebtR)
        1  3.706474 11.501065 -.0044018985  -.1088861  .05431032  1.412606  .04956437  .27615714
        1 4.0809216  11.49636    -.1842777  -4.536921   .1183139  1.052469  .02858973   .4481726
        1 3.1380994 11.634213     .2030028   5.736671 .070818014  3.595955 .022684796 -.08781198
        1 3.2252555  11.89487   .015097637   .5536921 .067413814 3.2352395  .10945787   .4429467
        1  2.540026 11.984547   -.03886209 -1.5589486   .0884381  7.536378  .16074604   7.815259
        1  3.416414         .            .  .11714643          .         .          .          .
        1   5.69944 12.757002  -.020511683  -1.781477  .12066934 2.3663054  .02650062  .03802625
        1  4.823984  12.71088   .012525164  1.0387985  .11842467 2.4149795  .05863588  .09283391
        1 4.6182837 12.314366   -.21680763  -12.09537   .1090028  8.765225  .10492877 -.50571805
        1 4.0839577   12.0311    -.3181791 -13.371965 .021989804  2.524885  .13871087 -.17017055
        1  3.749504 12.129893   -.14895591  -6.910138  .02956348  2.448543 .073495924 -.19660334
        1  3.836653         .            .          .          .         .          .          .
        1  6.472686  14.66071    .03209352  18.705381  .05727427 1.0208999   .3188793   1.825588
        1  6.413049 14.789265    .02647416  17.546934  .04526024  .5963251   .3215995  1.7584486
        1  7.035348 15.006763   .023059985  18.997498   .0421038  .5559817   .3725557   3.559188
        1  7.331433 15.035344    .00492969  4.1789737  .05372225  .3377626   .3508147  4.0523357
        1  7.597552  15.04751   .024930574   21.39274  .05411776   .377423   .3223201   2.796664
        1  7.549283         .            .          .          .         .          .          .
        1  4.508329 12.352162   .009275901  .53742176 .017264321 .55992794  .39130735   6.944171
        1  4.721708 12.323678    .01447813   .8152691 .029911984 .58534586   .3907317   6.625057
        1  4.734706 12.381982   .019487055   1.163204 .026280476  .6467859   .3901227   6.281123
        1 4.6663594 12.481433    .01909636   1.259074  .04390264  .6540709    .381669   6.456074
        1 4.6969285  12.77964   .029305443  2.6035044  .03671281  .6984371   .4335859   7.364879
        1  4.928485         .            .          .          .         .          .          .
        1  7.974946  15.65447    .00127186  2.0025032  .10413355 1.0404953  .08600954 -1.4016854
        end

        Comment


        • #5
          The problem is what I said in #3. Variables to the left of the comma in margins must be categorical variables specified with factor variable notation, e.g. i.female.

          Even if you were using factor variables, you said you wanted marginal effects, not adjusted predictions. To get those, do something like

          margins, dydx(*)

          You may want to read up a bit on margins. See, for example,

          https://www3.nd.edu/~rwilliam/xsoc73994/Margins01.pdf

          More handouts on margins can be found at

          https://www3.nd.edu/~rwilliam/xsoc73994/index.html

          -------------------------------------------
          Richard Williams, Notre Dame Dept of Sociology
          Stata Version: 17.0 MP (2 processor)

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

          Comment


          • #6
            Thank you.

            Just out of curiosity I've applied xtreg fixed effects to the same model, but this is omitted. Does someone know why that is the case? (The dataset is the same as above)

            Code:
            . xtreg DummyFinancialInvestor logAssets BVMV RoA DtoA, fe
            
            Fixed-effects (within) regression               Number of obs     =      1,478
            Group variable: nDSCD                           Number of groups  =        289
            
            R-sq:                                           Obs per group:
                 within  =      .                                         min =          1
                 between =      .                                         avg =        5.1
                 overall =      .                                         max =          6
            
                                                            F(4,1185)         =          .
            corr(u_i, Xb)  =      .                         Prob > F          =          .
            
            ------------------------------------------------------------------------------
            DummyFinan~r |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
               logAssets |          0  (omitted)
                    BVMV |          0  (omitted)
                     RoA |          0  (omitted)
                    DtoA |          0  (omitted)
                   _cons |   .7158322          .        .       .            .           .
            -------------+----------------------------------------------------------------
                 sigma_u |  .45643546
                 sigma_e |          0
                     rho |          1   (fraction of variance due to u_i)
            ------------------------------------------------------------------------------
            F test that all u_i=0: F(288, 1185) = .                      Prob > F =      .

            Comment


            • #7
              Nevermind, found the mistake

              Comment


              • #8
                I'm glad you found and fixed your mistake. The Forum is not just a dialog between you and those who respond to your post. There are others reading along to learn more about Stata and statistics, too. It would be helpful for them if you were to explain what the mistake was (and, if it's not too long and detailed) how you found it.

                Comment


                • #9
                  Sure. The mistake was rooted in the way the dummy variable was coded. Instead of being coded 0, it was a missing value ("."), hence the omitted model

                  Comment

                  Working...
                  X