Announcement

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

  • Multilevel mixed command syntax - stata 13.1

    Hello,

    I'm analysing data for getting my master's degree and decided to work with multilevel analysis.

    I have tranversal data from 165,007 children (lvl 1) grouped in 27 states (lvl 2). My outcome is their BMI (linear and cathegorical: 0 no obesity; 1 obesity) and height (linear and cathegorical: 0 no wasting; 1 wasting) and my exposure is their food consumption (10 yes/no questions on what they ate the day before). I also have contextual data from the 27 states (6 variables like state HDI and state access to health coverage percentage). My objective is to see if the correlation between what the child eats and their BMI and height varies between the states with different contextual status.

    Can I, in the same command, use all 10 exposure variables + all 6 contextual variables for each of my outcomes?

    Variables:
    Outcome #1: z_altidade
    Outcome #2: z_imcidade

    Adjusting variable #1: idade
    Adjusting variable #2: sexo

    Exposure #1: ind_feijao
    Exposure #2: ind_fruta
    Exposure #3: ind_verdura
    Exposure #4: ind_bebida
    Exposure #5: ind_macarrao
    Exposure #6: ind_doces
    Exposure #7: ind_embutido
    Exposure #8: ind_4uap
    Exposure #9: ind_semflv
    Exposure #10: ind_semultra

    Contextual #1: idh_uf
    Contextual #2: pib_uf
    Contextual #3: gini_uf
    Contextual #4: sisvan_uf
    Contextual #5: esf_uf
    Contextual #6: aps_uf

    For example, can I use the following command:

    Code:
     mixed z_altidade age sex ind_feijao ind_fruta ind_verdura ind_bebida ind_macarrao ind_doces ind_embutido ind_4uap ind_semflv ind_semultra idh_uf pib_uf gini_uf sisvan_uf esf_uf aps_uf || uf: ind_feijao ind_fruta ind_verdura ind_bebida ind_macarrao ind_doces ind_embutido ind_4uap ind_semflv ind_semultra

    I'm posting below this line a dataex of the data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long id byte sexo float(idade z_altidade z_imcidade ind_feijao ind_fruta ind_verdura ind_bebida ind_macarrao ind_doces ind_embutido ind_4uap ind_semflv ind_semultra idh_uf pib_uf gini_uf sisvan_uf esf_uf aps_uf)
      780129 0 7.323751  -2.2035506    2.463492 1 1 1 1 1 1 1 1 0 0 .687 17667.8 .527 14.05 75.99 80.91
     1308135 1 6.439425   .11371554  -.12088555 1 1 1 1 1 1 0 0 0 0 .737 26101.7 .566  5.61 61.17  70.4
     3691340 0  5.40178   -.4433573   -.6637772 1 1 1 0 0 0 0 0 0 1 .718 19716.2 .557  11.6 75.84 81.03
    10914863 1 9.790554    -1.34999   .28729343 1 1 1 1 0 0 0 0 0 0 .731   30794 .487 21.29 80.75 89.33
    11653405 0 5.724846   .18190157      -.6872 1 0 1 1 0 1 1 0 0 0 .731   30794 .487 21.29 80.75 89.33
    11694733 1 5.322382   -2.435411    2.385899 1 0 1 1 0 0 0 0 0 0 .731   30794 .487 21.29 80.75 89.33
    11899065 1 6.209445   -2.593762    .5391276 1 1 1 1 1 1 1 1 0 0 .731   30794 .487 21.29 80.75 89.33
    14752400 1 5.396304    -3.81397   1.8875575 1 1 0 1 0 1 1 0 0 0 .673 20702.3 .574 12.17 77.16 80.56
    17682730 0 6.724162   .01479333   1.2854333 1 1 1 1 0 1 0 0 0 0 .749 40788.8 .477 18.28  64.6 75.67
    18039163 1 6.360027  -.37742415   .07626039 0 0 1 0 1 0 0 0 0 0 .749 40788.8 .477 18.28  64.6 75.67
    21520938 0 8.287475   1.5279056   1.4959183 1 1 1 1 1 1 0 0 0 0 .774 45118.4 .421 38.98 81.52 91.24
    28082885 0 9.661876    1.278697    2.343362 1 1 1 1 1 1 1 1 0 0 .731   30794 .487 21.29 80.75 89.33
    28593335 0 7.457906   2.6422744    3.038634 1 1 1 1 1 1 1 1 0 0 .725 40787.3 .454 13.81 69.86  76.3
    31210988 0 6.195756    -.208791     1.17013 1 1 1 1 0 1 0 0 0 0 .731   30794 .487 21.29 80.75 89.33
    33179300 1 9.812457   .24143606  -.56850153 1 0 1 1 0 0 1 0 0 0 .687 17667.8 .527 14.05 75.99 80.91
    33320964 1 9.979466  -.05475925    .6198136 1 1 1 0 0 1 0 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    33442931 0 9.941136 -.018308386    .3775965 1 1 1 1 1 1 1 1 0 0 .744 17912.2 .562 11.69  82.9 85.23
    33449946 0 9.883641   1.3227162    1.680543 1 0 1 0 0 1 0 0 0 0 .744 17912.2 .562 11.69  82.9 85.23
    33523179 0 9.837098  -.25170115   -1.492172 1 1 0 0 1 1 1 0 0 0 .774 29732.4 .459 18.43 68.08 74.75
    33524086 1 9.960301  -.37001395   1.0945523 1 1 1 1 0 0 0 0 0 0 .774 29732.4 .459 18.43 68.08 74.75
    33624378 1  9.83436   -1.253505    .8478222 1 1 1 0 0 0 0 0 0 1 .694 13757.9 .531 18.21  85.4 87.37
    33629684 0 9.960301  -4.4110956   -.4543626 1 1 1 0 0 0 1 0 0 0 .731   30794 .487 21.29 80.75 89.33
    33656418 0 9.982204    1.393659  -1.7909104 1 1 1 1 0 0 0 0 0 0 .731   30794 .487 21.29 80.75 89.33
    33663706 1 9.990417    .1028681    .7471433 0 0 0 1 0 0 1 0 1 0 .731   30794 .487 21.29 80.75 89.33
    33686173 0 9.919233   1.0078328  -.06165731 1 0 0 1 1 1 1 1 1 0 .731   30794 .487 21.29 80.75 89.33
    33702313 0 9.886379   -.4091429   -.9671336 0 0 1 1 0 1 0 0 0 0 .731   30794 .487 21.29 80.75 89.33
    33716011 0 9.957563    .2954621   -.9046826 1 1 0 1 1 1 1 1 0 0 .731   30794 .487 21.29 80.75 89.33
    33721238 0 9.839836   -1.358993  -.29330796 1 1 1 1 1 1 1 1 0 0 .731   30794 .487 21.29 80.75 89.33
    33881793 0 9.908282   -.6458494   -.3299139 1 0 0 0 0 0 0 0 1 1 .673 20702.3 .574 12.17 77.16 80.56
    33883583 1 9.930184   -.4616807    .4848693 1 1 0 1 0 1 1 0 0 0 .673 20702.3 .574 12.17 77.16 80.56
    33883712 0 9.971252    2.178085   -.7532623 1 1 1 1 1 1 1 1 0 0 .673 20702.3 .574 12.17 77.16 80.56
    33932198 0 9.982204    .2954621   -.6237455 1 1 1 1 0 1 1 0 0 0 .673 20702.3 .574 12.17 77.16 80.56
    33966336 1 9.826146  -1.9462875  -1.6642853 1 1 1 0 0 1 0 0 0 0 .673 20702.3 .574 12.17 77.16 80.56
    33969509 0  9.87269   -.4889641  -1.0993032 1 1 1 0 0 1 1 0 0 0 .673 20702.3 .574 12.17 77.16 80.56
    33970498 1 9.987679   -1.631033  -1.5085915 1 1 1 0 0 0 1 0 0 0 .673 20702.3 .574 12.17 77.16 80.56
    33972211 0 9.878165   -.5665846   -2.962566 0 1 0 1 1 1 1 1 0 0 .673 20702.3 .574 12.17 77.16 80.56
    34266727 0 9.754962  -2.3835015    .8650157 0 0 0 1 1 1 0 0 1 0 .746 42406.1 .482  12.5 58.98 74.29
    34350730 0 9.932922   .13857687    2.366031 0 1 1 0 0 1 1 0 0 0 .783 51140.8 .526  9.46 39.47 59.98
    34359523 0  9.93566    .7661179   -1.085676 1 0 0 1 0 1 0 0 1 0 .783 51140.8 .526  9.46 39.47 59.98
    35697780 1 9.826146   -2.734424  -.26097938 1 1 0 1 1 1 0 0 0 0 .739 17722.4 .559  7.04 71.38 78.85
    35712389 1 9.848049    1.514577    3.133769 0 1 0 0 1 0 1 0 0 0 .687 17667.8 .527 14.05 75.99 80.91
    35717894 1 9.894592   .17177857   1.0009377 0 1 0 0 0 0 1 0 0 0 .687 17667.8 .527 14.05 75.99 80.91
    35718909 0 9.867214   .06318234    .3771046 1 0 1 0 1 1 1 0 0 0 .687 17667.8 .527 14.05 75.99 80.91
    35723179 0 9.987679   -.8027346   .51162016 1 1 0 0 0 0 0 0 0 1 .687 17667.8 .527 14.05 75.99 80.91
    35723211 0  9.91102    -.329046  -1.0156125 1 1 0 0 0 1 0 0 0 0 .687 17667.8 .527 14.05 75.99 80.91
    35723648 0 9.949349   -.4889641   -.8166595 0 1 0 1 0 0 0 0 0 0 .687 17667.8 .527 14.05 75.99 80.91
    35723962 0 9.650924   -.6451161   -2.863168 1 1 0 1 1 1 1 1 0 0 .687 17667.8 .527 14.05 75.99 80.91
    35724250 0 9.681041    -.329046   -2.132966 1 1 1 1 1 1 1 1 0 0 .687 17667.8 .527 14.05 75.99 80.91
    35725050 0 9.864476   -2.141002  -1.3569282 1 1 0 1 1 0 0 0 0 0 .774 29732.4 .459 18.43 68.08 74.75
    35725915 0 9.448323    .7661179   -1.085676 0 1 1 1 1 1 1 1 0 0 .687 17667.8 .527 14.05 75.99 80.91
    35729286 0 9.670089   1.4963672    2.227248 1 1 1 1 1 0 0 0 0 0 .687 17667.8 .527 14.05 75.99 80.91
    35744599 0 9.938398   -.3320789  -1.4765623 0 1 0 1 1 0 1 0 0 0 .687 17667.8 .527 14.05 75.99 80.91
    35744651 0 9.806981    .9352344  -1.0384235 1 0 0 1 1 0 1 0 1 0 .687 17667.8 .527 14.05 75.99 80.91
    35751299 0 9.946612   -.5665846    1.838676 1 1 1 1 1 1 1 1 0 0 .687 17667.8 .527 14.05 75.99 80.91
    35751867 0 9.787817    .6929493    .9781756 1 1 0 1 1 1 1 1 0 0 .687 17667.8 .527 14.05 75.99 80.91
    35756057 0 9.946612  -.17519364   1.7125967 1 0 0 0 1 1 1 0 1 0 .687 17667.8 .527 14.05 75.99 80.91
    35758838 1 9.842573    .8052379   3.2977014 1 1 0 1 0 0 0 0 0 0 .737 26101.7 .566  5.61 61.17  70.4
    35785999 1  9.79603    .5597213   .05441225 0 0 0 1 0 0 0 0 1 0 .737 26101.7 .566  5.61 61.17  70.4
    35790712 1 9.905544  -2.0683928   -.4340308 1 1 1 1 1 0 1 0 0 0 .737 26101.7 .566  5.61 61.17  70.4
    35822886 1 9.708419   -.6475776    .5029135 1 0 0 1 1 0 0 0 1 0 .718 19716.2 .557  11.6 75.84 81.03
    35823751 0 9.768652   4.0959353   2.3818388 0 0 0 1 1 1 1 1 1 0 .718 19716.2 .557  11.6 75.84 81.03
    35824767 0 9.607119   .14505918   1.0205896 1 1 1 1 1 1 0 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35826885 0 9.968514      2.0212   1.5210667 1 1 1 1 1 1 0 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35829193 1 9.946612  -.14495109  -2.1670523 1 0 0 1 1 1 0 0 1 0 .718 19716.2 .557  11.6 75.84 81.03
    35830982 1 9.916495   -.4876856    .3689188 1 0 0 1 1 1 1 1 1 0 .718 19716.2 .557  11.6 75.84 81.03
    35835015 1 9.806981    .5597213   -1.033871 1 1 1 1 0 1 0 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35855729 0 9.626284   .15071064    2.294546 1 1 1 0 1 0 0 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35858661 0 9.952087 -.018308386    -.426081 1 1 0 0 0 0 0 0 0 1 .718 19716.2 .557  11.6 75.84 81.03
    35860101 0 9.650924    -.329046 -.006827412 1 0 1 0 0 0 0 0 0 1 .718 19716.2 .557  11.6 75.84 81.03
    35861720 0 9.711157   -.8031511    1.657617 1 1 1 0 0 1 0 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35864364 0 9.861738   .53550756   2.3717341 1 1 1 0 1 0 0 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35864974 1 9.976728  -.37001395   .03137337 1 1 1 1 1 1 1 1 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35865268 1 9.631759   1.0486323    2.939897 1 0 0 1 1 1 1 1 1 0 .718 19716.2 .557  11.6 75.84 81.03
    35883387 0 9.615332   .54458046   -.6149532 1 1 1 1 1 1 0 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35885811 1 9.697468  -.07684916    .7844372 1 1 0 0 0 1 1 0 0 0 .783 51140.8 .526  9.46 39.47 59.98
    35894946 0 9.500342  .073346905    .6820206 1 0 0 1 0 0 1 0 1 0 .718 19716.2 .557  11.6 75.84 81.03
    35896062 1 9.746749   .17177857    2.223265 0 0 0 0 0 0 0 0 1 1 .718 19716.2 .557  11.6 75.84 81.03
    35901777 1  9.97399   -.5276413   1.7891778 1 0 0 1 0 0 0 0 1 0 .718 19716.2 .557  11.6 75.84 81.03
    35904894 0 9.724846   .54458046   -.6149532 1 0 0 0 0 0 0 0 1 1 .718 19716.2 .557  11.6 75.84 81.03
    35909116 0 9.689254  -.56583744   -.4097461 1 0 0 1 0 1 0 0 1 0 .718 19716.2 .557  11.6 75.84 81.03
    35909460 0 9.645449   .53550756   2.3717341 1 1 1 1 1 1 1 1 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35910715 0 9.984941   -.5665846   2.1011052 1 1 1 0 0 0 0 0 0 1 .718 19716.2 .557  11.6 75.84 81.03
    35911430 1  9.91102  -1.8869642   -2.054764 1 0 1 1 0 1 1 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35912434 0  9.97399    .7661179   -.9575977 1 1 1 0 0 1 0 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35920380 0 9.626284    .7661179  .029599974 1 1 1 0 0 1 0 0 0 0 .731   30794 .487 21.29 80.75 89.33
    35927256 0 9.278576    .4831652  -1.6933094 1 1 1 0 0 0 0 0 0 1 .718 19716.2 .557  11.6 75.84 81.03
    35927831 1  9.97399   2.1500666   1.0568627 1 0 0 1 0 1 1 0 1 0 .718 19716.2 .557  11.6 75.84 81.03
    35928430 0 9.798768   1.5673746    2.430302 0 1 0 1 1 1 1 1 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35939544 0 9.585216  -1.8261185  -2.3760092 1 1 0 1 0 1 1 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35939853 1 9.771389    .7188639  -1.5312355 1 1 1 1 0 1 0 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35942649 0 9.774127    .3030942   -.9182635 1 1 1 1 1 1 0 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35943145 1 9.976728   1.0486323  -1.7483557 1 1 0 1 1 1 1 1 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35943216 1 9.393566   -.7032761    .8461497 0 1 1 1 1 1 1 1 0 0 .673 20702.3 .574 12.17 77.16 80.56
    35943219 1 9.774127     2.31029   -.3357079 1 1 1 1 1 1 0 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35943506 1 9.817933  -1.6682752   -2.437814 1 1 1 1 1 0 1 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35943520 0  9.59343   1.7426666  -2.7563624 1 1 1 1 1 1 1 1 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35943836 1 9.620808    .8649848   2.0387847 1 1 1 1 1 1 1 1 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35943888 1 9.861738    1.597062   -.7046593 1 1 1 1 1 1 1 1 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35951485 0 9.648186  -.16768055  -1.0796583 1 0 1 1 0 1 1 0 0 0 .718 19716.2 .557  11.6 75.84 81.03
    35951663 0 9.765914    -.329046   1.1620181 1 0 0 1 1 0 0 0 1 0 .718 19716.2 .557  11.6 75.84 81.03
    end
    label values sexo sexo
    label def sexo 0 "feminino", modify
    label def sexo 1 "masculino", modify
    label values ind_feijao naosim
    label values ind_fruta naosim
    label values ind_verdura naosim
    label values ind_bebida naosim
    label values ind_macarrao naosim
    label values ind_doces naosim
    label values ind_embutido naosim
    label values ind_4uap naosim
    label values ind_semflv naosim
    label values ind_semultra naosim
    label def naosim 0 "nao", modify
    label def naosim 1 "sim", modify

  • #2
    A couple of things before answering your question. First, you did not include the uf level 2 ID variable in your data example. I created one myself using the following code, but this is only a workaround.
    Code:
    egen uf = group(gini_uf)
    Second, you did not include the age variable, which is included in your mixed statement.

    Can I, in the same command, use all 10 exposure variables + all 6 contextual variables for each of my outcomes?
    Theoretically, yes. But practically, it will be very difficult. You might be able to get away with just estimating the model you post, which has 12 random effects (two intercepts + 10 slopes). However, it is customary, though not required, to also allow for the random effects to covary, which would lead to an explosion of the number of random parameters and I'm almost positive that will not be estimable unless there is a lot of variation in the ind* variables across states.

    There are alternatives that you could consider, including creating a variable that is the sum of the different foods the child ate.
    Code:
    egen sum_ind = rowtotal(ind_feijao-ind_semultra)
    If you wanted to create a couple of different of variables of this nature that would also be possible. For example, one that is fruits and vegetables and one that is protein (meat and beans). I'm not sure what is relevant for your study. This has the benefit of reducing the random effects specification tremendously. For example, I can run this model without problem using just the data you supplied.
    Code:
    mixed z_altidade sum_ind idh_uf pib_uf gini_uf sisvan_uf esf_uf aps_uf sexo idade || uf: sum_ind, ///
    cov(un) reml
    You state,
    My objective is to see if the correlation between what the child eats and their BMI and height varies between the states with different contextual status.
    In multilevel models, this type of question would involve interactions between the child variables (ind*) and the contextual variables (*_uf), specifically:
    Code:
    mixed z_altidade c.sum_ind##c.*_uf || uf: sum_ind, cov(un) reml
    The interaction coefficients address your question. You can use margins to plot them.

    Comment

    Working...
    X