Announcement

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

  • problems with marginal effects after xtlogit fixed effects

    Hello everybody!
    I am using Stata 16 and estimating the panel logit model.
    I'm having problems in order to obtain marginal effects after xtlogit fixed effects. The problem is that the missing predicted values ​​are encountered within the estimation sample (error 322).

    For the estimation I use the command:
    xtset year indiv
    xtlogit switcher1 noleg numbernewp coalition i. year i.region i.council2 i.parties province_capital gender i.partiesformuni low_gdp medium_gdp unemployment if party_muni> 3, i (indiv) fe nolog



    however after running the command:
    margins, dydx (*) predict (pu0)

    Stata returns the error:
    missing predicted values ​​found within estimation sample (322)


    When I remove the categorical variable parties, everything works, both the regression and the subsequent marginal effects! In fact, I note that some missing predicted values are generated with respect this variable. But I think it's necessary to include this regresor in order to control the estimation.

    How can I fix this problem? Is it necessary to impose a condition that defines calculating marginal effects limited to those observations that do not generate missing values? Or do I solve the problem of missing values ​​directly and previously in my original model?
    I really appreciate if someone could help me!
    Last edited by Fra Passa; 11 May 2021, 10:55.

  • #2
    I think you need to show the full output of the regression here. Given that you have already identified that the problem is associated with the inclusion of the party variable, it is likely that there will be something anomalous about the results for party in the regression output. But that needs to be seen to make progress.

    Comment


    • #3
      Below I show the fulloutput of the regression.

      Conditional fixed-effects logistic regression Number of obs = 9,287
      Group variable: indiv Number of groups = 3,999

      Obs per group:
      min = 2
      avg = 2.3
      max = 3

      LR chi2(66) = 1989.57
      Log likelihood = -2299.7558 Prob > chi2 = 0.0000

      ----------------------------------------------------------------------------------
      switcher1 | Coef. Std. Err. z P>|z| [95% Conf. Interval]
      -----------------+----------------------------------------------------------------
      noleg | .4738186 .0842728 5.62 0.000 .3086469 .6389904
      numbernewp | -.1153223 .0243658 -4.73 0.000 -.1630784 -.0675662
      coalition | -.2196799 .1830643 -1.20 0.230 -.5784793 .1391195
      |
      year |
      2007 | .4631872 .1049441 4.41 0.000 .2575005 .6688738
      2011 | 1.135433 .1878683 6.04 0.000 .7672179 1.503648
      |
      region |
      2 | .3537834 .8709936 0.41 0.685 -1.353333 2.060899
      3 | 2.284796 1.116985 2.05 0.041 .0955446 4.474047
      4 | 60.98229 3111290 0.00 1.000 -6097954 6098076
      5 | -.4741875 1.067446 -0.44 0.657 -2.566343 1.617967
      6 | -.371473 .7981666 -0.47 0.642 -1.935851 1.192905
      7 | .1997594 .853321 0.23 0.815 -1.472719 1.872238
      8 | .3566518 1.012207 0.35 0.725 -1.627238 2.340542
      9 | .5247819 .745437 0.70 0.481 -.9362478 1.985812
      10 | .5257121 .9890727 0.53 0.595 -1.412835 2.464259
      11 | -.5665467 .8497154 -0.67 0.505 -2.231958 1.098865
      12 | .2037574 1.346197 0.15 0.880 -2.434741 2.842255
      13 | -.1504914 .7703712 -0.20 0.845 -1.660391 1.359408
      14 | -.7275906 .8876128 -0.82 0.412 -2.46728 1.012098
      15 | -.7250054 1.210051 -0.60 0.549 -3.096661 1.64665
      |
      council2 |
      9 | -.8273691 .3028954 -2.73 0.006 -1.421033 -.2337051
      11 | -1.068944 .3238433 -3.30 0.001 -1.703665 -.4342225
      13 | -.9886337 .3362984 -2.94 0.003 -1.647767 -.3295009
      17 | -.7767685 .3362663 -2.31 0.021 -1.435838 -.1176986
      21 | -.7611974 .3427392 -2.22 0.026 -1.432954 -.089441
      25 | -.7783854 .3812878 -2.04 0.041 -1.525696 -.031075
      26 | -1.575483 .4553559 -3.46 0.001 -2.467964 -.6830014
      27 | -1.599 .5086334 -3.14 0.002 -2.595903 -.6020965
      28 | 2.670323 1.300523 2.05 0.040 .1213445 5.219301
      30 | -1.367352 1.248921 -1.09 0.274 -3.815192 1.080488
      31 | 1.69304 1.302785 1.30 0.194 -.8603719 4.246452
      32 | .5395561 1.067333 0.51 0.613 -1.552379 2.631491
      40 | 2.660107 1.285209 2.07 0.038 .1411441 5.17907
      41 | 1.757517 1.332517 1.32 0.187 -.8541677 4.369202
      55 | -.1106008 1.001226 -0.11 0.912 -2.072968 1.851766
      56 | 1.354058 .9622704 1.41 0.159 -.531957 3.240074
      57 | -.7639605 .9304864 -0.82 0.412 -2.58768 1.059759
      |
      parties |
      3 | 0 (empty)
      40 | 0 (empty)
      126 | 0 (empty)
      201 | 0 (empty)
      247 | 0 (empty)
      304 | 0 (empty)
      360 | -50.43324 . . . . .
      505 | 2.777557 3200276 0.00 1.000 -6272422 6272428
      674 | 0 (empty)
      681 | 0 (empty)
      955 | -42.42239 . . . . .
      1010 | 0 (empty)
      1168 | 0 (empty)
      1170 | -32.44753 3728065 -0.00 1.000 -7306906 7306841
      1189 | 0 (empty)
      1231 | -42.98777 . . . . .
      1234 | -40.02816 3200494 -0.00 1.000 -6272894 6272814
      1255 | 51.06319 . . . . .
      1279 | -29.30252 4071706 -0.00 1.000 -7980426 7980368
      1280 | -65.35408 3201224 -0.00 1.000 -6274350 6274219
      1712 | -41.57414 . . . . .
      1742 | -42.99024 1.47e+09 -0.00 1.000 -2.88e+09 2.88e+09
      1747 | .4439837 3200276 0.00 1.000 -6272424 6272425
      1856 | 3.283004 3200276 0.00 1.000 -6272422 6272428
      1889 | 2.986428 3200276 0.00 1.000 -6272422 6272428
      1902 | -.1422848 3200276 -0.00 1.000 -6272425 6272425
      2000 | 2.26984 3200276 0.00 1.000 -6272423 6272427
      2004 | 0 (empty)
      2020 | 1.693387 3200276 0.00 1.000 -6272423 6272427
      2030 | -48.30411 . . . . .
      2031 | .1066411 3200276 0.00 1.000 -6272425 6272425
      2039 | 2.235788 3200276 0.00 1.000 -6272423 6272427
      2091 | .2148917 3200276 0.00 1.000 -6272425 6272425
      2103 | 4.511449 3200276 0.00 1.000 -6272420 6272429
      2109 | 0 (empty)
      2121 | -50.20571 . . . . .
      2140 | -37.04173 . . . . .
      2144 | -47.74507 . . . . .
      2146 | .4512953 3200276 0.00 1.000 -6272424 6272425
      2153 | 3.020057 3200276 0.00 1.000 -6272422 6272428
      2160 | 1.25209 3200276 0.00 1.000 -6272424 6272426
      2203 | 0 (empty)
      2309 | 1.212523 3200276 0.00 1.000 -6272424 6272426
      2311 | 66.11313 . . . . .
      2633 | -44.68525 . . . . .
      2654 | -49.98751 . . . . .
      2833 | -2.327356 3200276 -0.00 1.000 -6272427 6272422
      2835 | 50.77429 . . . . .
      2865 | 1.27375 3200276 0.00 1.000 -6272424 6272426
      2913 | 0 (empty)
      2927 | 0 (empty)
      2928 | 0 (empty)
      2940 | 0 (empty)
      2944 | 0 (empty)
      2964 | 1.93464 3200276 0.00 1.000 -6272423 6272427
      2976 | 0 (empty)
      2985 | .9448033 3200276 0.00 1.000 -6272424 6272426
      3003 | 0 (empty)
      3015 | -3.31e+11 . . . . .
      3019 | -5.01e+12 . . . . .
      3030 | -47.86117 . . . . .
      3042 | 0 (empty)
      3081 | -50.13958 . . . . .
      3097 | -51.13682 . . . . .
      3104 | -45.68423 . . . . .
      3107 | -45.55839 . . . . .
      3112 | -44.60118 . . . . .
      3114 | -42.98931 2.40e+09 -0.00 1.000 -4.69e+09 4.69e+09
      3159 | 0 (empty)
      3185 | 0 (empty)
      3206 | 3.735117 3200276 0.00 1.000 -6272421 6272429
      3212 | 2.372647 3200276 0.00 1.000 -6272422 6272427
      3226 | -44.21549 2.30e+09 -0.00 1.000 -4.51e+09 4.51e+09
      3229 | .8910027 3200276 0.00 1.000 -6272424 6272426
      3230 | -51.82853 . . . . .
      3233 | -51.71511 . . . . .
      3234 | 27.19675 3202195 0.00 1.000 -6276161 6276215
      3238 | 50.98881 . . . . .
      3329 | -37.02908 . . . . .
      3330 | 0 (empty)
      3357 | 52.0978 . . . . .
      3360 | -50.09209 . . . . .
      3364 | 0 (empty)
      3385 | 0 (empty)
      3388 | 3.514582 3200276 0.00 1.000 -6272421 6272428
      3389 | 52.29742 . . . . .
      3391 | -41.85444 . . . . .
      3392 | 1.813343 3200276 0.00 1.000 -6272423 6272427
      3394 | 0 (empty)
      3404 | 0 (empty)
      3410 | -.0135462 3200276 -0.00 1.000 -6272425 6272425
      3445 | 0 (empty)
      3448 | 52.70157 . . . . .
      3455 | 0 (empty)
      3462 | 0 (empty)
      3990 | 0 (empty)
      4136 | 0 (empty)
      4202 | -49.15278 . . . . .
      4267 | 51.79902 . . . . .
      4290 | 0 (empty)
      4308 | 32.33066 5585693 0.00 1.000 -1.09e+07 1.09e+07
      4396 | 0 (empty)
      4583 | 31.30751 3635948 0.00 1.000 -7126295 7126358
      4592 | 0 (empty)
      4700 | -42.89148 . . . . .
      4725 | 0 (empty)
      4734 | 0 (empty)
      4747 | -48.1344 . . . . .
      4750 | -50.56218 . . . . .
      4760 | -51.27258 . . . . .
      4804 | -39.82449 . . . . .
      4839 | 42.26746 . . . . .
      4840 | 0 (empty)
      4841 | -40.83903 . . . . .
      4843 | 62.48977 4706462 0.00 1.000 -9224433 9224558
      4847 | .7142435 3200276 0.00 1.000 -6272424 6272426
      4849 | 2.031712 3200276 0.00 1.000 -6272423 6272427
      4850 | 0 (empty)
      4851 | 0 (empty)
      4856 | -1.37718 3200276 -0.00 1.000 -6272426 6272423
      4860 | -52.08038 . . . . .
      4861 | 2.461965 3200276 0.00 1.000 -6272422 6272427
      4862 | -50.28929 . . . . .
      4866 | 4.422243 3200276 0.00 1.000 -6272420 6272429
      4871 | -59.86363 6356308 -0.00 1.000 -1.25e+07 1.25e+07
      4878 | 0 (empty)
      4879 | -60.2843 5720578 -0.00 1.000 -1.12e+07 1.12e+07
      4880 | 0 (empty)
      4882 | 1.895987 3200276 0.00 1.000 -6272423 6272427
      4915 | 0 (empty)
      4953 | 1.288188 3200276 0.00 1.000 -6272424 6272426
      5087 | -49.04554 . . . . .
      5359 | -53.50542 . . . . .
      5376 | 0 (empty)
      5466 | 0 (empty)
      5615 | 0 (empty)
      5659 | 1.851991 3200276 0.00 1.000 -6272423 6272427
      5660 | -51.32836 . . . . .
      5663 | 0 (empty)
      5664 | -51.95158 . . . . .
      5666 | 24.65332 3201337 0.00 1.000 -6274481 6274530
      5667 | 0 (empty)
      5673 | 0 (empty)
      5684 | -51.60392 . . . . .
      5689 | 0 (empty)
      5695 | -47.95202 . . . . .
      5710 | -42.64265 . . . . .
      5718 | -50.85944 . . . . .
      5721 | 3.134091 3200276 0.00 1.000 -6272422 6272428
      5786 | 0 (empty)
      5896 | 0 (empty)
      5909 | 40.62548 . . . . .
      5921 | 0 (empty)
      6006 | 0 (empty)
      6017 | -49.79462 . . . . .
      6036 | 3.716373 3200276 0.00 1.000 -6272421 6272429
      6041 | 0 (empty)
      6057 | 1.140998 3200276 0.00 1.000 -6272424 6272426
      6060 | -42.1432 . . . . .
      6061 | 0 (empty)
      6066 | -1.754475 3200276 -0.00 1.000 -6272427 6272423
      6067 | 1.59725 3200276 0.00 1.000 -6272423 6272426
      6102 | 0 (empty)
      6113 | 2.214464 3200276 0.00 1.000 -6272423 6272427
      6126 | 0 (empty)
      6155 | 2.957724 3200276 0.00 1.000 -6272422 6272428
      6183 | 0 (empty)
      6184 | -50.88921 . . . . .
      6185 | -46.43437 . . . . .
      6186 | 0 (empty)
      6189 | -44.86739 . . . . .
      6210 | -50.71036 . . . . .
      6236 | -18.76129 3200349 -0.00 1.000 -6272587 6272550
      6237 | -3.199009 3200276 -0.00 1.000 -6272428 6272422
      6240 | 1.252056 3200276 0.00 1.000 -6272424 6272426
      6260 | 0 (empty)
      6265 | -44.20674 2.54e+09 -0.00 1.000 -4.97e+09 4.97e+09
      6308 | 0 (empty)
      6317 | 0 (empty)
      6333 | 0 (empty)
      6341 | -.6425539 3200276 -0.00 1.000 -6272425 6272424
      6342 | -2.394007 3200276 -0.00 1.000 -6272427 6272422
      6394 | -50.50384 . . . . .
      6395 | 675.4667 . . . . .
      6412 | -50.96854 . . . . .
      6413 | -52.14747 . . . . .
      6442 | 11.58053 . . . . .
      6583 | 0 (empty)
      6658 | -43.19155 2.24e+09 -0.00 1.000 -4.39e+09 4.39e+09
      6720 | 1.999607 3200276 0.00 1.000 -6272423 6272427
      6749 | 54.56237 . . . . .
      6778 | 52.39341 . . . . .
      6820 | -42.69556 . . . . .
      6823 | 1.439094 3200276 0.00 1.000 -6272423 6272426
      6831 | 51.30631 . . . . .
      6893 | 0 (empty)
      6906 | -50.91797 . . . . .
      6908 | 0 (empty)
      6913 | -49.65154 . . . . .
      6917 | 51.50542 . . . . .
      6940 | 0 (empty)
      6945 | -48.74568 . . . . .
      6954 | 3.209279 3200276 0.00 1.000 -6272422 6272428
      6973 | 52.85084 . . . . .
      6974 | -50.26333 . . . . .
      6989 | -50.60724 . . . . .
      7013 | -35.90082 . . . . .
      7018 | 2.217637 3200276 0.00 1.000 -6272423 6272427
      7046 | 0 (empty)
      7047 | 0 (empty)
      7058 | 1.695918 3200276 0.00 1.000 -6272423 6272427
      7060 | 1.213576 3200276 0.00 1.000 -6272424 6272426
      7064 | 0 (empty)
      7078 | -50.04407 . . . . .
      7088 | -50.62235 . . . . .
      7093 | -48.79458 . . . . .
      7101 | -59.43105 5966329 -0.00 1.000 -1.17e+07 1.17e+07
      7111 | -48.13809 . . . . .
      7113 | 1.017225 3200276 0.00 1.000 -6272424 6272426
      7171 | 30.80471 3558287 0.00 1.000 -6974084 6974146
      7197 | 0 (empty)
      7206 | 0 (empty)
      7207 | .0809388 3200276 0.00 1.000 -6272425 6272425
      7208 | 0 (empty)
      7234 | -50.8618 . . . . .
      7261 | -50.74361 . . . . .
      7300 | 0 (empty)
      7307 | 50.58973 . . . . .
      7349 | 0 (empty)
      7396 | -49.09777 . . . . .
      7413 | 1.705891 3200276 0.00 1.000 -6272423 6272427
      7663 | -50.61969 . . . . .
      7664 | .6951297 3200276 0.00 1.000 -6272424 6272426
      7678 | 2.773321 3200276 0.00 1.000 -6272422 6272428
      7774 | -1.71e+12 . . . . .
      7778 | 0 (empty)
      7782 | 0 (empty)
      7817 | 0 (empty)
      7822 | -50.18398 . . . . .
      7829 | 0 (empty)
      7837 | -1.146759 3200276 -0.00 1.000 -6272426 6272424
      7865 | 0 (empty)
      7975 | -50.41063 . . . . .
      7984 | .4344481 3200276 0.00 1.000 -6272424 6272425
      8034 | -48.17116 . . . . .
      8085 | 0 (empty)
      8158 | 2.936776 3200276 0.00 1.000 -6272422 6272428
      8180 | 53.44193 . . . . .
      8188 | 0 (empty)
      8240 | .2435374 3200276 0.00 1.000 -6272425 6272425
      8260 | 53.95646 . . . . .
      8263 | 1.821328 3200276 0.00 1.000 -6272423 6272427
      8310 | -44.31908 2.13e+09 -0.00 1.000 -4.18e+09 4.18e+09
      8348 | 0 (empty)
      8378 | 43.76828 . . . . .
      8410 | 50.70012 . . . . .
      8445 | -49.63265 . . . . .
      8511 | 0 (empty)
      8600 | -.2892357 3200276 -0.00 1.000 -6272425 6272425
      |
      province_capital | -.3657795 .4525498 -0.81 0.419 -1.252761 .5212019
      gender | 0 (omitted)
      |
      partiesformuni |
      5 | .1634204 .0865444 1.89 0.059 -.0062035 .3330443
      6 | .2907282 .1094344 2.66 0.008 .0762406 .5052158
      7 | .2161417 .1303377 1.66 0.097 -.0393155 .4715989
      8 | .8644452 .1533089 5.64 0.000 .5639653 1.164925
      9 | .6287573 .1864788 3.37 0.001 .2632655 .9942491
      |
      low_gdp | -.0828801 .2113432 -0.39 0.695 -.4971051 .3313449
      medium_gdp | -.2469647 .1429069 -1.73 0.084 -.527057 .0331277
      unemployment | -.0099357 .0138348 -0.72 0.473 -.0370514 .01718
      ----------------------------------------------------------------------------------

      Then I run the command:
      margins, dydx(noleg) predict(pu0) post

      and Stata returns the message:
      missing predicted values encountered within the estimation sample
      r(322);

      Comment


      • #4
        Dear Fra Passa,

        Please do not compute marginal effects after xtlogit with FE. For details, see:

        http://repec.org/usug2016/santos_uksug16.pdf

        Best wishes,

        Joao

        Comment


        • #5
          @ Joao Santos Silva Thanks for the link. That's a really clear explanation.

          @ Fra Passa After abandoning the quest for marginal effects here, you still have considerable pathology in the regression model itself. First, the variable parties has an enormous number of distinct values, of which a large fraction never appear in the estimation sample (which means that they appear in the data set, but only in observations that have missing values for other variables.) It is fairly unusual to use a discrete variable with this many categories. Even if it had worked out well, and even if there were not strong reasons not to try to calculate marginal effects here, how would you make sense of these results? Next, for those that do appear, many of the coefficients are as large as 40 or 50 or more (or their negatives.) These coefficients correspond to extremely large (towards infinity) or for their negatives, extremely small (towards 0) odds ratios. In real life, an odds ratio for a dichotomous predictor greater than 4 is unusual, greater than 20 is highly suspicious, and greater than 50 is almost guaranteed to represent an error. I think what is going on in your data is that these values of parties that have huge coefficients occur very infrequently, perhaps just once or twice, and then on the chance of those few observations being all zeroes or all ones except for perhaps one reverse of that, you get this enormous coefficient. Notice that the standard errors are also missing for most of those, also suggesting that they are based on n = 1 subsamples. A quick glance at -tab parties switcher1 if e(sample)- will confirm my theory.

          So I think that you need to re-examine this parties variable. First, check if the data are even correct. If they are, I wonder whether it would make more sense to treat it as a continuous variable. If it is a count of the number of parties (in some sense of the word party that isn't apparent to me) then that might be appropriate--or you might have to transform it in some way to get the right specification of the relationship to the outcome. If it is a truly categorical variable, then it might make sense to try to coarsen it: lump together several categories into a smaller number of larger super-categories that make sense in terms of the meaning of the variable, and then use those super-categories as the model variable.
          Last edited by Clyde Schechter; 11 May 2021, 17:01.

          Comment


          • #6
            Thaks you Joao Santos Silva and Clyde Schechter for your suggests.
            As Clyde said, It is evident that there is a pathology in my model related to the variable parties. My dataset contains observations of candidates running in 4 municipal elections and I want to observe the occurence of switching party between consecutive elections. The reason for which variable parties is generating this problem is exactly what Clyde says: some values of this variable occur just once! But I can't treat it as a continous variable, because it is not count of the number of parties. I thinks I have to reflect about a form to lump in others categories based on similar parties' characteristics.
            you have been a great help!
            Best regards,
            Francesca

            Comment

            Working...
            X