Announcement

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

  • Margins after mixed returns "not estimable"

    Dear Statalists,

    I have a model:
    Code:
    mixed var1 var2 year##month || var3
    My year and month goes from 2019jan until and including 2025feb.
    I wish to estimate marginal effects per month and therefore run:
    Code:
    margins month, atmeans
    However, Feb until Dec returns "not estimable". Can someone explain to me how come?

    Shouldn't margins estimate marginal means across all available months?
    It estimates all months just fine if I limit the model to 2019Jan until 2024Dec.
    Let me know if I should include a dataexample, I'll try to reproduce the results.

    Many thanks!

    Best regards,
    Wei
    Last edited by Wei Hai Deng; 01 Apr 2025, 04:08.

  • #2
    Yes, a data example might be helpful. Your month is coded with values from 1 to 12?
    Best wishes

    (Stata 16.1 MP)

    Comment


    • #3
      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float OF4 byte AntHf float(Start_ar Start_mnd Forløp_2)
      17.443584 1 2024  5 1
      13.344285 1 2023  1 1
       6.832314 1 2024 11 1
      1.4278433 1 2023  2 1
       43.44666 1 2024 12 1
      17.542746 1 2024 10 1
       3.555255 2 2023  3 1
      16.168398 2 2024  2 1
       27.75516 2 2024 10 1
       43.79955 2 2024 11 1
      10.235474 2 2024 11 1
       44.63794 2 2024 12 1
       29.22329 1 2024  3 1
      18.488956 2 2024 10 1
       42.53154 2 2024 10 1
      19.569094 1 2023  6 1
       5.983066 1 2023  5 1
       37.71217 1 2024  1 1
      34.751167 1 2024 11 1
       34.33076 1 2024  7 1
       46.59673 1 2025  1 1
       22.74441 1 2024  2 1
       3.370055 2 2024 10 1
      16.899445 1 2024  7 1
       48.74424 1 2025  1 1
       36.32192 1 2024 11 1
      2.2707558 1 2024  7 1
      37.298332 1 2024 12 1
      24.806295 2 2024 12 1
      35.835808 2 2023  4 1
        42.9871 2 2024  7 1
       6.703778 2 2024  4 1
       24.42209 2 2024  6 1
       43.56094 1 2024 12 1
       38.32342 1 2024  4 1
      12.562777 2 2024  3 1
       8.318239 2 2024  6 1
      37.189793 2 2024  2 1
       49.02557 1 2024 11 1
       36.47886 1 2024  1 1
       45.05524 1 2024  3 1
      13.218246 1 2024 10 1
       44.28255 1 2024  7 1
        44.1056 1 2024 10 1
      37.446648 1 2024  3 1
       45.98131 1 2024  6 1
      34.672665 1 2024  3 1
       10.77013 1 2024  1 1
       41.42944 1 2025  2 1
      2.2107677 2 2024  5 1
       43.15189 1 2023 11 1
      17.630228 1 2023 12 1
         38.602 1 2024  9 1
      29.305996 1 2023  7 1
      16.138832 1 2024  5 1
       8.646533 1 2024 12 1
       40.26822 1 2024 12 1
      15.300095 2 2024  6 1
      10.954984 2 2023 10 1
       36.23655 1 2023  8 1
       34.82433 1 2024  3 1
       45.59672 1 2024  6 1
      33.978172 1 2024 10 1
       17.74708 1 2024  6 1
        36.9485 2 2024 12 1
       9.370083 1 2024  6 1
       15.73064 1 2024  2 1
       6.878465 1 2024  3 1
      32.688694 1 2024  5 1
      13.506597 1 2024 12 1
       44.99197 2 2024  3 1
       28.67116 2 2024  8 1
       5.573518 1 2024  4 1
      20.726135 1 2024 12 1
       .1526102 2 2024  4 1
       33.29989 2 2024  6 1
      17.314379 1 2024  5 1
      3.9011745 1 2024 11 1
       6.379067 1 2023  9 1
       11.48503 1 2024 12 1
      16.477734 1 2025  2 1
      20.720444 1 2024  1 1
       1.804237 1 2024  3 1
       4.219054 1 2024  7 1
       .4938123 2 2024 11 1
      16.002186 1 2024 11 1
      .25984827 1 2024  2 1
      11.377173 1 2024 10 1
        42.5734 1 2024  7 1
       49.10033 1 2024  6 1
      1.6239593 2 2024  6 1
       49.37423 1 2024 11 1
        44.7053 1 2024  3 1
       48.42367 1 2024  9 1
      11.961014 1 2024  9 1
       34.63668 1 2024  8 1
      24.421793 2 2024  4 1
       21.88226 1 2024  3 1
      29.290026 2 2024  7 1
      18.935461 1 2024 11 1
      end
      label values Start_mnd mnd_
      label def mnd_ 1 "Jan", modify
      label def mnd_ 2 "Feb", modify
      label def mnd_ 3 "Mar", modify
      label def mnd_ 4 "Apr", modify
      label def mnd_ 5 "May", modify
      label def mnd_ 6 "Jun", modify
      label def mnd_ 7 "Jul", modify
      label def mnd_ 8 "Aug", modify
      label def mnd_ 9 "Sep", modify
      label def mnd_ 10 "Oct", modify
      label def mnd_ 11 "Nov", modify
      label def mnd_ 12 "Dec", modify
      label values Forløp_2 Forløp_
      label def Forløp_ 1 "Brystkreft", modify
      
      * Check distribution
      tab Start_ar Start_mnd
      
      mixed OF4 Start_ar##Start_mnd AntHf || Forløp_2:
      
      margins Start_mnd, atmeans
      Last edited by Wei Hai Deng; 01 Apr 2025, 04:06.

      Comment


      • #4
        Code:
        . tab Start_mnd Start_ar
        
                   |             Start_ar
         Start_mnd |      2023       2024       2025 |     Total
        -----------+---------------------------------+----------
               Jan |         1          4          2 |         7
               Feb |         1          5          2 |         8
               Mar |         1         11          0 |        12
               Apr |         1          5          0 |         6
               May |         1          5          0 |         6
               Jun |         1         10          0 |        11
               Jul |         1          8          0 |         9
               Aug |         1          2          0 |         3
               Sep |         1          3          0 |         4
               Oct |         1          9          0 |        10
               Nov |         1         11          0 |        12
               Dec |         1         11          0 |        12
        -----------+---------------------------------+----------
             Total |        12         84          4 |       100
        Interactions that are incompletely instantiated in the data cause these problems. Because of all the zeroes in the third column, Stata has no way to calculate predicted outcomes for months Mar through Dec in 2025. Since it needs those predictions to calculate the predictive margins for those months, those are not estimable.

        Since you have no data for most of 2025 (unsurprisingly), probably your best bet is to exclude 2025 from the -margins- calculation:
        Code:
        . margins Start_mnd, at(Start_ar = (2023 2024))
        
        Predictive margins                                         Number of obs = 100
        
        Expression: Linear prediction, fixed portion, predict()
        1._at: Start_ar = 2023
        2._at: Start_ar = 2024
        
        -------------------------------------------------------------------------------
                      |            Delta-method
                      |     Margin   std. err.      z    P>|z|     [95% conf. interval]
        --------------+----------------------------------------------------------------
        _at#Start_mnd |
               1#Jan  |    12.5661   13.43158     0.94   0.349    -13.75931     38.8915
               1#Feb  |   .6496542   13.43158     0.05   0.961    -25.67575    26.97506
               1#Mar  |   5.460477   13.60665     0.40   0.688    -21.20808    32.12903
               1#Apr  |   37.74103   13.60665     2.77   0.006     11.07248    64.40958
               1#May  |   5.204877   13.43158     0.39   0.698    -21.12053    31.53028
               1#Jun  |    18.7909   13.43158     1.40   0.162    -7.534499    45.11631
               1#Jul  |   28.52781   13.43158     2.12   0.034     2.202403    54.85321
               1#Aug  |   35.45836   13.43158     2.64   0.008     9.132956    61.78376
               1#Sep  |   5.600878   13.43158     0.42   0.677    -20.72453    31.92628
               1#Oct  |   12.86021   13.60665     0.95   0.345    -13.80835    39.52876
               1#Nov  |    42.3737   13.43158     3.15   0.002      16.0483     68.6991
               1#Dec  |   16.85204   13.43158     1.25   0.210    -9.473365    43.17744
               2#Jan  |   25.64221    6.76851     3.79   0.000     12.37618    38.90825
               2#Feb  |   18.71379   6.002353     3.12   0.002     6.949397    30.47819
               2#Mar  |   28.25945   4.055415     6.97   0.000     20.31098    36.20791
               2#Apr  |   15.86688   6.080708     2.61   0.009     3.948913    27.78485
               2#May  |   16.91774   5.998596     2.82   0.005     5.160711    28.67478
               2#Jun  |    25.6395   4.294529     5.97   0.000     17.22237    34.05662
               2#Jul  |    26.9993    4.73819     5.70   0.000     17.71262    36.28598
               2#Aug  |   32.21744   9.498774     3.39   0.001     13.60018    50.83469
               2#Sep  |   32.21737   7.795362     4.13   0.000     16.93874      47.496
               2#Oct  |   24.01084   4.495417     5.34   0.000     15.19999     32.8217
               2#Nov  |   24.46936   4.039535     6.06   0.000     16.55202    32.38671
               2#Dec  |   29.52921   4.039535     7.31   0.000     21.61187    37.44656
        -------------------------------------------------------------------------------
        Or perhaps better still, just exclude the 2025 data from the regression in the first place and then use your original -margins- command, as that will get you monthly (not month-year) predictive -margins- using as much of the data as possible..
        Last edited by Clyde Schechter; 01 Apr 2025, 09:55.

        Comment

        Working...
        X