Announcement

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

  • Multilevel modeling does not converge

    Dear Statalist members,

    I hope some of you can explain to me what happens in my model. I have students nested in school. School is nested within municipalities. I have students' characteristics (fem, first_immigration, second_generation, education_father, education_mother). I created also some variables at school level (Level 2) like: I want to know the % of females in each school. I wrote


    When the variable is dummy, I used "sum" while when the variable is not dummy but I have 1,2,3,4 for example, I used "count" like

    [CODE] egen n_fem= sum (fem), by(school) ge perc_fem = (n_fem / num_student_total)*100 [\CODE]



    I did the same to create some variables at municipality level (Level 3). To see the % of educated parents in a municipality, % of immigrants first generation and so on.

    Then I run the following code:
    [CODE] mixed students_score fem first_generation, second_generation, education_father education_mother ///
    centre south || municipality: perc_females perc_educated_father perc_educated_mother || school: perc_females perc_educated_father_municipality , mle [\CODE]

    Dependent variable is "student score". If I run the null model, everything is ok. I run the first model with only students' characteristics and nothing for level 3 (municipality) and nothing in level 2 (school) and everything is ok.

    However, when I run the model with covariates at school and municipality levels, my model does not converge. Iteractions are endless and I got close to them "not concave"
    I have no missing values but I do not understand why the model does not converge and I do not get results I would like to read.

    I would like to understand with your help where I made the mistake.

    I look forward to hearing from you.

    Thank you
    Simona
    Last edited by Simona Ferraro; 13 Mar 2018, 07:55.

  • #2
    Unfortunately, the commands are not fully readable, since the CODE delimiters didn't work well for you.

    That said, I believe there is a confusion concerning the random slopes and the level of each predictor.
    Best regards,

    Marcos

    Comment


    • #3
      Thank you Marcos,

      the code is readable now. I used the same above but it did not work.
      I know that I should write the fixed part in the beginning, then I use || municipality: var1 var2 var3 || school: var1 var2 var3, mle

      What do I do wrong?

      Thank you
      With kind regards,
      Simona

      Code:
      egen n_fem= sum (fem), by(school) ge perc_fem = (n_fem / num_student_total)*100
      Code:
      mixed students_score fem first_generation second_generation education_father education_mother ///
      centre south || municipality: perc_females perc_educated_father perc_educated_mother || school: perc_females perc_educated_father_municipality , mle
      Last edited by Simona Ferraro; 13 Mar 2018, 08:23.

      Comment


      • #4
        Simona:
        why did you plug in commas after (eg) -first_generation-?
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Hello Carlo,

          thank you for your help. No, I did not use there. Sorry typo. I fixed the code.
          I know that I have to write only my covariates and I read Stata file but still I do not understand why I have problems.



          Comment


          • #6
            Simona:
            the usual recipe is to add one predictor at time and see when Stata starts to choke on.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              I started with the null model:
              Code:
               wle_ita_200 ||  municipality: || school: , mle
              and everything was ok

              Then, I started adding all covariates for te fixed part of the model:
              Code:
              mixed wle_ita_200 fem anticip posticip first_generation second_generation education_father education_mother centre south || denominazione: || codice_plesso: , mle
              Once I add at least, only one covariate for Level 2 or Level 3 or for both Level 2 and Level 3, the model does not converge. I get the "not concave" and standard deviation is not at municipality level and school level but I read also the standard deviation for the covariate I included. I do not see the standard errors but only "."

              Comment


              • #8
                I post below the output from the regression without any covariate for school level and for municipality level. Variable names are not in English language but level 3 denominazione: ||
                and level 2 is codice_plesso: , mle

                So in this first model, I just run the fixed part of the model with only student characteristics. Once I add covariates for other levels, the model does not converge and I get non concave and also (backed up) and I add them one by one.
                Does anyone know what happens? I would be very grateful as I do not know anymore what to check.

                Code:
                . mixed wle_ita_200 fem anticipatario posticipatario immig_prima immig_seconda /// 
                > titolo_padre_1 titolo_madre_1 centro sud || denominazione: || codice_plesso: , mle      
                
                Performing EM optimization: 
                
                Performing gradient-based optimization: 
                
                Iteration 0:   log likelihood = -2026704.6  
                Iteration 1:   log likelihood = -2026693.1  
                Iteration 2:   log likelihood = -2026693.1  
                
                Computing standard errors:
                
                Mixed-effects ML regression                     Number of obs     =    399,193
                
                -------------------------------------------------------------
                                |     No. of       Observations per Group
                 Group Variable |     Groups    Minimum    Average    Maximum
                ----------------+--------------------------------------------
                   denominazi~e |      5,260          1       75.9     20,649
                   codice_ple~o |     12,748          1       31.3        209
                -------------------------------------------------------------
                
                                                                Wald chi2(9)      =   21050.75
                Log likelihood = -2026693.1                     Prob > chi2       =     0.0000
                
                --------------------------------------------------------------------------------
                   wle_ita_200 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                ---------------+----------------------------------------------------------------
                           fem |   5.144252   .1201284    42.82   0.000     4.908805    5.379699
                 anticipatario |  -3.091126    .575905    -5.37   0.000    -4.219879   -1.962373
                posticipatario |  -11.43795   .4759465   -24.03   0.000    -12.37079   -10.50511
                   immig_prima |  -20.59855   .3801676   -54.18   0.000    -21.34367   -19.85344
                 immig_seconda |  -17.33226   .2320447   -74.69   0.000    -17.78706   -16.87746
                titolo_padre_1 |    9.08571   .2207809    41.15   0.000     8.652987    9.518433
                titolo_madre_1 |   11.42817    .199214    57.37   0.000     11.03772    11.81862
                        centro |   .5977719   .7086843     0.84   0.399    -.7912237    1.986768
                           sud |   5.724031   .6029194     9.49   0.000      4.54233    6.905731
                         _cons |   206.9311   .3693798   560.21   0.000     206.2072    207.6551
                --------------------------------------------------------------------------------
                
                ------------------------------------------------------------------------------
                  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
                -----------------------------+------------------------------------------------
                denominazi~e: Identity       |
                                  var(_cons) |   38.31626   5.481571      28.94737     50.7174
                -----------------------------+------------------------------------------------
                codice_ple~o: Identity       |
                                  var(_cons) |   521.1125   8.521772       504.675    538.0855
                -----------------------------+------------------------------------------------
                               var(Residual) |   1394.683   3.174931      1388.474    1400.919
                ------------------------------------------------------------------------------
                LR test vs. linear model: chi2(2) = 83811.24              Prob > chi2 = 0.0000
                
                Note: LR test is conservative and provided only for reference.

                Comment


                • #9
                  Simona Ferraro
                  Once I add covariates for the other levels, the model does not converge (...)
                  Apparently, you did not read the second paragraph in #2.
                  Best regards,

                  Marcos

                  Comment


                  • #10
                    Dear Marcos,
                    I read the second paragraph in #2. I got a bit confused and I would like to run a proper model
                    My question is: when I run the multilevel, should I include all my covariates, for each level just after the dependent variable as fixed part and, at the same time, include some of them related to one level, after the command || level?

                    Should I do, for example:

                    mixed dep variable var1 var2 var3 var4 .var5 var6 var7 var8... all for all levels || denominazione: || codice_plesso: var1 var2 var3 var4 only for this level, mle????

                    Thus, should I have variables at level 2 on both sides? Probably does my mistake come from there?

                    Thank you
                    With kind regards,

                    Simona

                    Comment


                    • #11
                      Indeed, Simona. This is the issue, already informed in #2. You are mistaking random slopes for levels of covariates. You may wish to take a look at an example in the Stata Manual with a random slope. Then you’ll understand the difference.
                      Best regards,

                      Marcos

                      Comment


                      • #12
                        Dear Marcos,

                        thank you again for your post. I read the Stata manual and I also asked to an expert who works with multilevel who told me that I must have all my covariates immediately after the dependent variable and then, after each level I include only covariates for that level.
                        After xtmixed I have my dependent variable plus covariates for that level (student level) and this is the fixed part of the model. then I have the level 3 and I include covariates for that level and then I add the indication || Level 2: add covariates for this level.

                        Stata manual also indicates dep variable || level 3: covariates || level 2: covariates, mle
                        Where do I make the mistake? I weite here to have someone who can clarify me the problem. I understand it is in the random part because from the output above, the fixed part works.
                        Should I write all my covariates after the dep variable and leave empty the random part? In this way I have not the random slope. How should I include my covariates? I did as written in Stata, covariates for Level 3 are created using by(denominazione) and for level 2 using by(school_complex) in order to have, for example, the % of students female in each school_complex.
                        all those new covariates are included according to the level.

                        xtmixed dep variable var1 var2 var3 || denominazione: var1 var2 var3 var4 var5 || codice_plesso: var1 var2 var3

                        In level denominazione and level codice_plesso, variables are different. In level 1, for example, I have dummy female, in level 2 I have % female in that level, in level 3 I add % female in that level.
                        I would really appreciate if someone can tell me how must write my model because this is what I wrote after reading Stata manual.

                        Thank you again for your time in reading my post.
                        With kind regards,
                        Simona

                        Comment


                        • #13
                          As it was highlighted twice, including covariates is not the same as including random slopes. I have never seen a multilevel mixed model - nor such an example in whatsoever decent text concerning the matter -where it was suggested - let alone, necessary - to include all predictors as random slopes. Little wonder such a weird model fails to converge. Adding random slopes is part and parcel of the core-knowledge that should be grasped before delving with mixed models. Usually, it is a tentative approach, done with deep roots in the rationale as well as after checking postestimations. Hopefully that helps.
                          Best regards,

                          Marcos

                          Comment


                          • #14
                            Dear Marcos,
                            thank you for your answers!

                            With kind regards,
                            Simona

                            Comment


                            • #15
                              Hi Marcos,

                              I realize that you all are discussing about multilevel models and I have the following situation.

                              // at village level & family level//
                              // DV: zlen (Height for Age Z score) IV:hlth_hyg_nut2 (intervention)//
                              // Other IVs or covariate: educational level, child sex, dietary diversity, income, number of drinking sources a household has in each season//
                              // zlen_flag==0 is excluding extreme values as suggested by WHO//
                              // with dietary diversity//

                              mixed zlen i.hlth_hyg_nut2 i.caregiver_edu3 i.child_sex2 i.dietarydiversity_category i.fiveincomecat2 i.total_drinkingsource3 ///
                              i.ecologicalzone i.year##i.treat_control if zlen_flag==0 ||vlgname2:||family_id:

                              estimates store zlen_hlygnut_vlgfamilywithD

                              estat icc

                              //creating a variable that indicate sample used in the above model//
                              gen in_model=e(sample). // this was created after getting the not-testable error message and rerun the models and contrast command, yet gave the not-testable error message for vars: year, treat_control i.year##i.treat_control

                              contrast hlth_hyg_nut2 caregiver_edu3 child_sex2 dietarydiversity_category fiveincomecat2 total_drinkingsource3 ///
                              ecologicalzone year treat_control i.year##i.treat_control
                              // ??????? year treat_control i.year##i.treat_control: not testable??? after running contrast command//



                              Another clarification I would like to get is that ecological zone is placed under fixed part of the model (left side of this || ), does that mean that I am comparing zone 2, 3, 4, to zone 1. Is that what I should be doing? Does it mean that I am comparing whether the interventions would have different effectiveness in each zones comparing to zone 1? Where in the syntax do I indicate which to use as a base or reference category I am comparing to?

                              Also, how do I add mediation (and moderation) syntax? Whether dietary diversity might be mediating between the children's height for age outcome (Y) and intervention (X)? What else can I do pre and post estimations?

                              Hope to hear from you soon.

                              Thank you,
                              Aye Aye



                              Comment

                              Working...
                              X