Announcement

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

  • MULTILEVEL – Mixed Effects Model Specification with Random Intercept and Slopes

    Dear STATA colleagues,

    I am working with data containing approximately 300 000 individuals, grouped into 100 groups and I would like to ask your help to check two specifications of a mixed-effects model with two levels and to code the appropriate model with random slopes with different decompositions of X’s Betas.

    Considering that:
    Xij=Explanatory variables (unit: individual)
    Wij=Control variables (unit: individual)
    Zj=Group Variables (unit: group - GroupID)

    We first formulated the following specification with a random-intercept:
    Specification 1: Y=B0+B1.X1+B2.X2+B3.X3+B4.W1+B5.W2+B6.W3+B7.W4+B8. Z1+B9.Z2+B10.Z3+error1

    Here, we want to decompose the intercept considering different levels explained by group variables, as follows:

    B0=a00 + a01.Z1 + a02.Z2 + a03.Z3 + error2


    To do that on STATA (knowing that Y; X1; W2; W3; W4; Z2; Z3 are continuous variables and that X2; X3; W1; Z1 are binary Variables) we built the following code:

    mixed Y X1 X2 X3 W1 W2 W3 W4 Z1 Z2 Z3|| GroupID: , covariance(unstructured)

    Then, as we found that B1, B2 and/or B3 in Specification 1 are statistically significant, we moved to the Specification 2 with random-intercept and random-slopes, as follows:

    Specification 2:
    Y=B0+B1.X1+B2.X2+B3.X3+B4.W1+B5.W2+B6.W3+B7.W4+B8. Z1+B9.Z2+B10.Z3+error1

    Where we want to decompose the intercept but also (by assumption) the slope of X1; X2 and X3 with different specifications as follows:

    B0=a00+ a01.Z1+a02.Z2+a03.Z3+error2

    B1=a10+ a11.Z1+error3
    B2=a20+ a21.Z1+a22.Z2+error4
    B3=a30+ a31.Z1+a32.Z2+a33.Z3+error5


    With specification 2, we intend not only to control the effect of Group on betas’ slope but also to verify how Group variables (i.e., Z1; Z2 and Z3) influence that slope: mitigating or exacerbating the effect of explanatory variables on the dependent.

    In other words, analogous with other models, we want to capture the interactive effect between explanatory and group variables.

    I will appreciate it very much if you could help me with the design of the code on STATA addressing our specification 2.

    Thank you in advance for all insights we can provide me about.

  • #2
    Hi Ricardo:

    It sounds to me like you want two things: 1) random slopes for group variables (Zi=1...k) and 2) an interaction term between explanatory variables and group variables (Xi * Zi). Does that sound right? If so, all you need to do is specify the variable you want as a random slope behind the colon in the mixed command and specify the interaction in the list of variables. For example:

    Code:
    mixed  X1 X2 X3 W1 W2 W3 W4 Z1 Z2 Z3 || groupID: Z1 Z2 Z3
    The above provides random slopes for Z1 Z2 and Z3

    Code:
    mixed  c.X1##c.Z1 X2 X3 W1 W2 W3 W4 Z2 Z3 || groupID: Z1 Z2 Z3
    The above provides random slopes for Z1 Z2 and Z3, and it also provides an interaction between X1 and Z1.

    Now I'm not sure if you want to do all of this in one model. Specifying several interactions and several random slopes in one model might pose computational problems. This is something you will have to explore yourself.

    Comment


    • #3
      Hi Chris,

      Thank you for your insights. I am wondering if the random slopes of the explanatory variables (X1 X2 X3) at the first level are explained by group variables at the second level (Z1 Z2 Z3). So, considering the code that you provide here, I ask if it makes sense to replace the right-hand specification (groupID: X1 X2 X3) of the random effect equation as follows:

      Code Specification 2 (without interaction):
      Code:
       
       mixed  X1 X2 X3 W1 W2 W3 W4 Z1 Z2 Z3 || groupID: X1 X2 X3
      The above provides random slopes for X1 X2 and X3

      Code Specification 2 (with interaction):
      Code:
       
       mixed  c.X1##c.Z1 X2 X3 W1 W2 W3 W4 Z2 Z3 || groupID: X1 X2 X3
      The above provides random slopes for X1 X2 and X3, and it also provides an interaction between X1 and Z1.

      Thank you in advance.

      Comment


      • #4
        Yes I think that should be fine.

        Comment


        • #5
          Thank you, Chris. Just one additional question, given that X2 and X3 are dummies is necessary to specify any Stata command or specify these factor-variables at the right-hand specification for nested data or the command is correctly specified?

          Thank you in advance and wish you a good weekend,

          Comment

          Working...
          X