Dear Statalist members,

I am using Stata 17 MP (duly updated).

The models and the data

I am fitting negative binomial (NB2) 3-levels growth curve models of weekly counts, using meglm.

The nesting structure is : 30 occasions (weeks) < 1710 settlements < 96 districts. An extract (1 settlement 30 weeks) of the data is provided below.

A) Time-varying predictors :
at level-1
-weeknum (the ordinal number of a week in the series of 30)
-weektp (week type: four categories entered as 3 dummies)
-tclass (eight ordered categories entered as 7 dummies)

at level-3
-L1weekstock
-L1weekmob

B) Time-invariant predictors: all other.

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input double weeknumber float distrid long settlid float(countinf std2_weeknum std2_weeknumsqr weektp tclass std2_L1weekstock std2_L1weekmob std2_pcrural std2_pc65yover std2_pcforeign std2_medinc milp17)
 1 74 1   0  -.8376152   .7015992 1 2  -.3326102   -.8563091 -.39327615 -.6413893 .4492839 .4750123 27.122
 2 74 1   0  -.7798486   .6081639 1 1  -.3356403   -.1969749 -.39327615 -.6413893 .4492839 .4750123 27.122
 3 74 1   0  -.7220821  .52140254 1 1  -.3348828    -.335782 -.39327615 -.6413893 .4492839 .4750123 27.122
 4 74 1   0  -.6643155   .4413151 1 1  -.3375342   .05461322 -.39327615 -.6413893 .4492839 .4750123 27.122
 5 74 1   0   -.606549  .36790165 1 1  -.3356403   .14136773 -.39327615 -.6413893 .4492839 .4750123 27.122
 6 74 1   0 -.54878235   .3011621 1 2  -.3322314    .1587186 -.39327615 -.6413893 .4492839 .4750123 27.122
 7 74 1   0  -.4910158  .24109654 2 3  -.3363979   .21944684 -.39327615 -.6413893 .4492839 .4750123 27.122
 8 74 1   0  -.4332492   .1877049 2 2   -.334504   .05461322 -.39327615 -.6413893 .4492839 .4750123 27.122
 9 74 1   0  -.3754827  .14098725 2 4  -.3299588   -.4138612 -.39327615 -.6413893 .4492839 .4750123 27.122
10 74 1   3  -.3177161  .10094354 2 4 -.29624802  .002560559 -.39327615 -.6413893 .4492839 .4750123 27.122
11 74 1   0 -.25994954  .06757376 2 3  -.2568557  -.24035217 -.39327615 -.6413893 .4492839 .4750123 27.119
12 74 1   6   -.202183  .04087796 2 3 -.26594624   -.6307475 -.39327615 -.6413893 .4492839 .4750123 27.119
13 74 1   6  -.1444164   .0208561 2 4  -.2716278   -.8042565 -.39327615 -.6413893 .4492839 .4750123 27.113
14 74 1  14 -.08664985 .007508196 2 5 -.24928026    -.604721 -.39327615 -.6413893 .4492839 .4750123 27.107
15 74 1   3 -.02888328 .000834244 3 4  -.2326143  -.17094846 -.39327615 -.6413893 .4492839 .4750123 27.093
16 74 1   6  .02888328 .000834244 3 4  -.2299629   .08931507 -.39327615 -.6413893 .4492839 .4750123  27.09
17 74 1   6  .08664985 .007508196 3 5  -.1913281 -.006114925 -.39327615 -.6413893 .4492839 .4750123 27.084
18 74 1  14   .1444164   .0208561 3 4 -.19890356    .3669295 -.39327615 -.6413893 .4492839 .4750123 27.078
19 74 1  14    .202183  .04087796 3 5  -.1966309    .4450085 -.39327615 -.6413893 .4492839 .4750123 27.064
20 74 1  14  .25994954  .06757376 3 5 -.17579845   .59249115 -.39327615 -.6413893 .4492839 .4750123  27.05
21 74 1  41   .3177161  .10094354 3 6 -.02088059    .6185175 -.39327615 -.6413893 .4492839 .4750123 27.036
22 74 1 136   .3754827  .14098725 3 8   .4128136   .59249115 -.39327615 -.6413893 .4492839 .4750123 26.995
23 74 1 272   .4332492   .1877049 3 8   1.637763 -.032141294 -.39327615 -.6413893 .4492839 .4750123 26.859
24 74 1 272   .4910158  .24109654 4 8   3.026342   -.1969749 -.39327615 -.6413893 .4492839 .4750123 26.587
25 74 1 136  .54878235   .3011621 4 8   3.214592  -.01479041 -.39327615 -.6413893 .4492839 .4750123 26.315
26 74 1 136    .606549  .36790165 4 8  1.8313158   -.3878348 -.39327615 -.6413893 .4492839 .4750123 26.179
27 74 1  68   .6643155   .4413151 4 6   1.193842   .01123596 -.39327615 -.6413893 .4492839 .4750123 26.043
28 74 1  68   .7220821  .52140254 4 6  .54235375   .09799048 -.39327615 -.6413893 .4492839 .4750123 25.975
29 74 1  68   .7798486   .6081639 4 6   .3870571    .2367977 -.39327615 -.6413893 .4492839 .4750123 25.907
30 74 1  41   .8376152   .7015992 4 8     .26585   .28017497 -.39327615 -.6413893 .4492839 .4750123 25.839
end
The categorical predictors excepted, all predictors are 2 SD standardized: grand-mean centered then divided by 2 standard deviations.
(Gelman A 2008 “Scaling regression inputs by dividing by two standard deviations” Statistics in Medicine).


The problem:

-A) when I use the # operator to create quadratic terms (weeknum##weeknum or weeknum#weeknum), the final iteration returns the error message shown below.
Code:
meglm countinf c.std2_weeknum##c.std2_weeknum ib2.weektp ib2.weektp#c.std2_weeknum ib2.weektp#c.std2_weeknum#c.std2_weeknum ///
ib1.tclass std2_pcrural ib1.tclas s#c.std2_pcrural std2_L1weekstock std2_L1weekmob std2_pc65yover std2_pcforeign std2_medinc ///
, exposure(milp17) || distrid : || settlid: c.std2_weeknum##c.std2_weeknum ///
, difficult family(nbinomial mean) link(log) cov(unstructured) vce(robust)
or alternatively
Code:
meglm countinf std2_weeknum c.std2_weeknum#c.std2_weeknum ib2.weektp ib2.weektp#c.std2_weeknum ib2.weektp#c.std2_weeknum#c.std2_weeknum ///
ib1.tclass std2_pcrural ib1.tclass#c.std2_pcrural std2_L1weekstock std2_L1weekmob std2_pc65yover  std2_pcforeign  std2_medinc ///
, exposure(milp17) || distrid : || settlid: std2_weeknum c.std2_weeknum#c.std2_weeknum ///
, difficult family(nbinomial mean) link(log) cov(unstructured) vce(robust)
the iteration log ends with:
Code:
Iteration 11:  log pseudolikelihood = -131293.52  (not concave)
Iteration 12:  log pseudolikelihood = -131285.01  (not concave)
Iteration 13:  log pseudolikelihood = -131277.98  
Iteration 14:  log pseudolikelihood = -131272.86  
Iteration 15:  log pseudolikelihood =  -131271.5  
Iteration 16:  log pseudolikelihood = -131270.98  
Iteration 17:  log pseudolikelihood = -131270.98  
                       *:  3200  conformability error
     _gsem_ereturn__sd():     -  function returned error
         _gsem_ereturn():     -  function returned error
       st_gsem_ereturn():     -  function returned error
                 <istmt>:     -  function returned error
r(3200);

end of do-file

r(3200);

- B) when I do not use #, but instead create X^2 (weeknumsqr), the estimation procedure ends normally,
Code:
meglm countinf std2_weeknum std2_weeknumsqr ib2.weektp ib2.weektp#c.std2_weeknum ib2.weektp#c.std2_weeknumsqr ///
ib1.tclass std2_pcrural ib1.tclass#c.std2_pcrural std2_L1weekstock std2_L1weekmob std2_pc65yover  std2_pcforeign  std2_medinc ///
, exposure(milp17) || distrid : || settlid:  std2_weeknum std2_weeknumsqr ///
, difficult family(nbinomial mean) link(log) cov(unstructured) vce(robust)
leading to the following results:
Code:
Iteration 11:  log pseudolikelihood = -131293.52  (not concave)
Iteration 12:  log pseudolikelihood = -131285.01  (not concave)
Iteration 13:  log pseudolikelihood = -131277.98  
Iteration 14:  log pseudolikelihood = -131272.86  
Iteration 15:  log pseudolikelihood =  -131271.5  
Iteration 16:  log pseudolikelihood = -131270.98  
Iteration 17:  log pseudolikelihood = -131270.98  

Mixed-effects GLM                               Number of obs     =     51,300
Family: Negative binomial
Link:   Log
Overdispersion: mean

        Grouping information
        -------------------------------------------------------------
                        |     No. of       Observations per group
         Group variable |     groups    Minimum    Average    Maximum
        ----------------+--------------------------------------------
                distrid |         96         90      534.4      2,670
                settlid |      1,710         30       30.0         30
        -------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(31)     =   29843.31
Log pseudolikelihood = -131270.98               Prob > chi2       =     0.0000
                                                    (Std. err. adjusted for 96 clusters in distrid)
---------------------------------------------------------------------------------------------------
                                  |               Robust
                         countinf | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
----------------------------------+----------------------------------------------------------------
                     std2_weeknum |   3.298914   .7736116     4.26   0.000     1.782663    4.815165
                  std2_weeknumsqr |  -5.317793   1.640426    -3.24   0.001    -8.532969   -2.102617
                                  |
                           weektp |
                               1  |  -3.454767   2.946621    -1.17   0.241    -9.230038    2.320504
                               3  |  -.3165163   .0706098    -4.48   0.000     -.454909   -.1781236
                               4  |   4.843987   .4872818     9.94   0.000     3.888932    5.799042
                                  |
            weektp#c.std2_weeknum |
                               1  |   -3.15082   8.370738    -0.38   0.707    -19.55716    13.25553
                               3  |  -2.463644   .7949061    -3.10   0.002    -4.021631   -.9056565
                               4  |  -14.65873   1.526555    -9.60   0.000    -17.65073   -11.66674
                                  |
         weektp#c.std2_weeknumsqr |
                               1  |   7.216591   5.968627     1.21   0.227    -4.481703    18.91488
                               3  |   10.91105   2.087026     5.23   0.000     6.820551    15.00154
                               4  |   11.94664   1.911539     6.25   0.000     8.200094    15.69319
                                  |
                           tclass |
                               2  |   1.579361   .1812937     8.71   0.000     1.224032     1.93469
                               3  |    2.36908   .1987663    11.92   0.000     1.979505    2.758655
                               4  |   2.763744   .1977046    13.98   0.000      2.37625    3.151238
                               5  |   3.076674   .2004631    15.35   0.000     2.683773    3.469574
                               6  |   3.453519   .2009128    17.19   0.000     3.059737    3.847301
                               7  |   3.750355   .2029003    18.48   0.000     3.352678    4.148032
                               8  |   4.095897   .2064415    19.84   0.000     3.691279    4.500515
                                  |
                     std2_pcrural |    .624201   .2692187     2.32   0.020      .096542     1.15186
                                  |
            tclass#c.std2_pcrural |
                               2  |  -.7134393   .2503491    -2.85   0.004    -1.204115    -.222764
                               3  |  -.7459787   .2489973    -3.00   0.003    -1.234005   -.2579529
                               4  |  -.8330824    .251747    -3.31   0.001    -1.326498   -.3396672
                               5  |  -.7421679   .2588821    -2.87   0.004    -1.249568   -.2347682
                               6  |  -.6488989   .2634231    -2.46   0.014    -1.165199   -.1325992
                               7  |  -.5745428   .2704703    -2.12   0.034    -1.104655   -.0444308
                               8  |  -.5618221     .28133    -2.00   0.046    -1.113219   -.0104255
                                  |
                 std2_L1weekstock |   .2227779   .0439275     5.07   0.000     .1366815    .3088743
                   std2_L1weekmob |   .1751561   .0303288     5.78   0.000     .1157127    .2345994
                   std2_pc65yover |  -.0672125   .0224725    -2.99   0.003    -.1112578   -.0231672
                   std2_pcforeign |   .2212634   .0261615     8.46   0.000     .1699877     .272539
                      std2_medinc |   .0396633   .0216403     1.83   0.067    -.0027508    .0820775
                            _cons |  -4.043469   .2109965   -19.16   0.000    -4.457014   -3.629923
                       ln(milp17) |          1  (exposure)
----------------------------------+----------------------------------------------------------------
                         /lnalpha |  -1.695915   .0367845                     -1.768011   -1.623818
----------------------------------+----------------------------------------------------------------
distrid                           |
                        var(_cons)|   .0587462   .0118504                      .0395616    .0872341
----------------------------------+----------------------------------------------------------------
distrid>settlid                   |
                 var(std2_weeknum)|   1.195491   .1552879                      .9267871    1.542101
              var(std2_weeknumsqr)|   2.423071   .2574262                      1.967591    2.983991
                        var(_cons)|   .1038953   .0107819                      .0847737    .1273299
----------------------------------+----------------------------------------------------------------
distrid>settlid                   |
 cov(std2_weeknum,std2_weeknumsqr)|  -1.232618   .1880016    -6.56   0.000    -1.601095   -.8641421
           cov(std2_weeknum,_cons)|  -.1914082   .0298032    -6.42   0.000    -.2498215    -.132995
        cov(std2_weeknumsqr,_cons)|  -.0505272   .0422252    -1.20   0.231    -.1332871    .0322327
---------------------------------------------------------------------------------------------------

Specifying simpler models or more complex ones does not help.

I would like to use the # operator and then "margins" extentively.

What mistakes do I make?