Announcement

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

  • How to include baseline measures in mixed model

    Hello, I am dealing with a mixed model using long format data. Basically I have a variable _j which indicates the wave of the data and it has five numeric values (1-5). Then I have this two sets of measurement: one measurement is only measured at wave 1 and 2 and the other one was only measured at wave 3 and wave 4. Now I need to set up a mixed model predicting wave 3 and 4 performance based on a set of predictors and I want to include wave 1 and 2 measurement results as control variables. Please see below:

    Code:
    mixed outcome AGEYEAR FEMALE baseline || DistrictID:, || ChildID: AGEYEAR, mle var pweight(PCT5LWGT0)
    But STATA gives me an error said no observations, which make sense because outcome is only available when _j = 3 or 4 but baseline is only available when _j = 1 or 2. How should I deal with this kind of issue? Is there a way for me to add the baseline in the model? Thanks a lot!

  • #2
    So you really only have data for waves 3 and 4 when all is said and done. (You don't say much about wave 5, but from what you do say I infer that you have no measurements at all for that.) What you need to do is basically copy the wave1 and wave2 measurements into the observations for waves 3 and 4. Then drop the wave 1 and wave 2 observations. You don't say whether you want both the wave 1 and wave 2 measurements as covariates in both waves 3 and 4, or whether you just want wave 1's measurement as a covariate in wave3 and wave 2's in wave 4. You also don't show any variable names. So I think you need to clarify this post before you can get any concrete advice. The pseudo-code that you show in your post doesn't even refer to these measurements at waves 1, 2, 3, and 4--or if it does it is completely obscure as to what in that code corresponds to them.

    Comment


    • #3
      Hi Clyde, thanks for your reply and sorry for the confusion. So basically let's ignore wave 5 for now and I want both wave 1 and 2 measurement to be the covariates when predicting wave 3 and 4 outcome. The data is in long format and the variable that catches information of wave is _j. Because the measurement of wave 1 and 2 (in other words, when _j =1 or 2) is different from the measurement of wave 3 and 4 (when _j =3 or 4), and the OUTCOME in the syntax refers to the measurement at wave 3 and 4 but I want to include measurement at wave 1 and 2 as the covariates to predict the OUTCOME. Please see the following table for an example, and let's say OUTCOME_BASE is the measurement when _j =1 or 2 and OUTCOME is the measurement when _j =3 or 4.

      Right now my thoughts of doing this is kinda similar to what you proposed. I create two new variables BASE1 and BASE2 and BASE1 is just a clone variable of OUTCOME_BASE when _j =1 and BASE 2 is a clone variable of OUTCOME_BASE when _j =2. Each participant will then have BASE1 across all waves and BASE2 across all waves. Then I include BASE1 and BASE2 as covariates in the model. Do you think this is correct?
      ID OUTCOME OUTCOME_BASE _j Age
      001 . 103 1 8
      001 . 100 2 9
      001 115 . 3 10
      001 117 . 4 11
      002 . 104 1 8
      002 . 105 2 9

      Comment


      • #4
        So you need to create new variables corresponding to the wave1 and wave2 outcomes (outcome_base as you call it) in the wave 3 and wave 4 observations.

        Code:
        by id (wave), sort: gen outcome_wave_1 = outcome_base[1]
        by id (wave), sort: gen outcome_wave_2 = outcome_base[2]
        drop if inlist(_j, 1, 2)
        regression_command outcome outcome_wave_1 outcome_wave_2 other variables as desired etc.
        Note: Not tested. Beware of typos.

        As an aside, why are you posting a data example this way? You have used -dataex- before in your posts--you should always use it when posting example data, so those who want to help you don't have to wrestle with your HTML table to get it into Stata.

        Comment


        • #5
          Thanks a lot for your suggestion Clyde! Sorry again for the trouble. I will use -dataex- for my future inquiry

          Comment


          • #6
            Hi Clyde, I happened to find a post in which you answered a question about interactions in mixed models: https://www.statalist.org/forums/for...=1498767518490

            I am using the mixed model and have some questions about interactions as well. So still using the data I described above, I am now facing a problem of whether and how to interact baseline measures with time and other categorical variables that I am interested to look at. To give you an example, I have the following syntax in which BEVSSRS is the continuous outcome var, BASEBEV1 and BASEBEV2 are the two continuous baseline measures, DISAB is the categorical var indicating disability type. As you can see from my syntax, I currently have 2-way and 3-way interactions going on.

            Code:
            mixed BEVSSRS BASEBEV1 BASEBEV2 AGEYEAR ib8.DISAB ib8.DISAB#c.AGEYEAR ib8.DISAB#c.BASEBEV1 i.DISAB#c.BASEBEV2 i.DISAB#c.BASEBEV1#c.AGEYEAR i.DISAB#c.BASEBEV2#c.AGEYEAR || DistrictID:, || ChildID: AGEYEAR, mle var pweight(PCT5LWGT0)
            Here is the model output:
            Code:
            mixed BEVSSRS BASEBEV1 BASEBEV2 AGEYEAR ib8.DISAB ib8.DISAB#c.AGEYEAR ib8.DISAB#c.BASEBEV1 i.DISAB#c.
            > BASEBEV2 i.DISAB#c.BASEBEV1#c.AGEYEAR i.DISAB#c.BASEBEV2#c.AGEYEAR || DistrictID:, || ChildID: AGEYEA
            > R, mle var pweight(PCT5LWGT0)
            (4384 missing values generated)
            
            Obtaining starting values by EM: 
            
            Performing gradient-based optimization: 
            
            Iteration 0:   log pseudolikelihood = -3238477.3  
            Iteration 1:   log pseudolikelihood = -3219009.2  (not concave)
            Iteration 2:   log pseudolikelihood = -3218611.3  
            Iteration 3:   log pseudolikelihood = -3217834.4  
            Iteration 4:   log pseudolikelihood = -3217775.4  
            Iteration 5:   log pseudolikelihood = -3217774.6  
            Iteration 6:   log pseudolikelihood = -3217774.6  
            
            Computing standard errors:
            
            Mixed-effects regression                        Number of obs      =      1531
            
            -----------------------------------------------------------
                            |   No. of       Observations per Group
             Group Variable |   Groups    Minimum    Average    Maximum
            ----------------+------------------------------------------
                 DistrictID |      184          1        8.3         45
                    ChildID |      793          1        1.9          2
            -----------------------------------------------------------
            
                                                            Wald chi2(53)      =    846.36
            Log pseudolikelihood = -3217774.6               Prob > chi2        =    0.0000
            
                                                     (Std. Err. adjusted for 184 clusters in DistrictID)
            --------------------------------------------------------------------------------------------
                                       |               Robust
                               BEVSSRS |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
            ---------------------------+----------------------------------------------------------------
                              BASEBEV1 |  -.5154685   .3084366    -1.67   0.095    -1.119993    .0890561
                              BASEBEV2 |   1.306434   .3028417     4.31   0.000     .7128747    1.899992
                               AGEYEAR |   5.595731    4.18367     1.34   0.181    -2.604113    13.79557
                                       |
                                 DISAB |
                                  ASD  |    158.925   108.9473     1.46   0.145    -54.60781    372.4578
                                   DD  |  -201.5103    91.7179    -2.20   0.028     -381.274   -21.74648
                                   ED  |  -70.53332   74.66228    -0.94   0.345    -216.8687    75.80205
                                   LD  |  -8.126874   114.0871    -0.07   0.943    -231.7334    215.4797
                                   ID  |  -79.38158   229.0869    -0.35   0.729    -528.3837    369.6205
                                   OI  |   226.3458   144.1853     1.57   0.116    -56.25219    508.9437
                                  OHI  |  -73.01421   103.7573    -0.70   0.482    -276.3747    130.3463
                                  LOW  |  -90.84285     81.277    -1.12   0.264    -250.1428    68.45714
                                       |
                       DISAB#c.AGEYEAR |
                                  ASD  |  -23.14191   15.37542    -1.51   0.132    -53.27718    6.993354
                                   DD  |   29.40426    13.4698     2.18   0.029     3.003937    55.80459
                                   ED  |   12.96942    10.7618     1.21   0.228    -8.123319    34.06216
                                   LD  |   1.136617   14.86868     0.08   0.939    -28.00545    30.27869
                                   ID  |   12.08597    28.9253     0.42   0.676    -44.60658    68.77852
                                   OI  |  -34.51079   20.17897    -1.71   0.087    -74.06085    5.039272
                                  OHI  |   10.76325   14.72402     0.73   0.465    -18.09529     39.6218
                                  LOW  |   11.81481   11.45393     1.03   0.302    -10.63448    34.26409
                                       |
                      DISAB#c.BASEBEV1 |
                                  ASD  |  -.8135243   .9188447    -0.89   0.376    -2.614427    .9873782
                                   DD  |   1.191503   .8233655     1.45   0.148    -.4222634     2.80527
                                   ED  |   .2693476    .935672     0.29   0.773    -1.564536    2.103231
                                   LD  |   1.076852   1.090685     0.99   0.323    -1.060852    3.214555
                                   ID  |   2.882561   2.143542     1.34   0.179    -1.318705    7.083827
                                   OI  |   .2296056   1.025936     0.22   0.823    -1.781192    2.240404
                                  OHI  |   2.166989   1.054077     2.06   0.040     .1010369    4.232942
                                  LOW  |   3.346538   1.592969     2.10   0.036     .2243751      6.4687
                                       |
                      DISAB#c.BASEBEV2 |
                                  ASD  |  -.7494775   1.159881    -0.65   0.518    -3.022803    1.523848
                                   DD  |   .9470433   .6085423     1.56   0.120    -.2456776    2.139764
                                   ED  |   .3907477   .8922031     0.44   0.661    -1.357938    2.139434
                                   LD  |  -.7704575   .7996724    -0.96   0.335    -2.337787    .7968716
                                   ID  |   -1.83118   2.608223    -0.70   0.483    -6.943204    3.280844
                                   OI  |  -2.736597   1.020208    -2.68   0.007    -4.736169   -.7370261
                                  OHI  |  -1.480676   .9134842    -1.62   0.105    -3.271072    .3097204
                                  LOW  |  -2.746906   1.266771    -2.17   0.030    -5.229732   -.2640803
                                       |
            DISAB#c.BASEBEV1#c.AGEYEAR |
                                  ASD  |   .2100272   .1104357     1.90   0.057    -.0064228    .4264773
                                   DD  |  -.0917865   .1184301    -0.78   0.438    -.3239051    .1403322
                                   ED  |   .0498333   .1214983     0.41   0.682     -.188299    .2879656
                                   LD  |  -.0454016   .1257595    -0.36   0.718    -.2918857    .2010825
                                   ID  |  -.3285384   .2696059    -1.22   0.223    -.8569562    .1998794
                                   OI  |   .0721771   .1420171     0.51   0.611    -.2061713    .3505256
                                  OHI  |  -.1892195   .1456581    -1.30   0.194    -.4747041    .0962651
                                  SLI  |   .0931748   .0408949     2.28   0.023     .0130222    .1733275
                                  LOW  |  -.3759929   .2020577    -1.86   0.063    -.7720186    .0200329
                                       |
            DISAB#c.BASEBEV2#c.AGEYEAR |
                                  ASD  |  -.0434201   .1474079    -0.29   0.768    -.3323344    .2454941
                                   DD  |  -.2810056   .0800661    -3.51   0.000    -.4379324   -.1240789
                                   ED  |  -.2220284   .1101653    -2.02   0.044    -.4379484   -.0061084
                                   LD  |  -.0544166    .107474    -0.51   0.613    -.2650618    .1562287
                                   ID  |   .1135026   .3368583     0.34   0.736    -.5467276    .7737328
                                   OI  |   .2408345   .1254458     1.92   0.055    -.0050347    .4867037
                                  OHI  |   .0346872   .1152969     0.30   0.764    -.1912907     .260665
                                  SLI  |  -.1607049   .0444786    -3.61   0.000    -.2478813   -.0735285
                                  LOW  |   .2427991    .156238     1.55   0.120    -.0634218    .5490199
                                       |
                                 _cons |   30.24442    30.6533     0.99   0.324    -29.83494    90.32378
            --------------------------------------------------------------------------------------------
            
            ------------------------------------------------------------------------------
                                         |               Robust           
              Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
            -----------------------------+------------------------------------------------
            DistrictID: Identity         |
                              var(_cons) |   46.08784   52.82817      4.874128    435.7886
            -----------------------------+------------------------------------------------
            ChildID: Independent         |
                            var(AGEYEAR) |   1.20e-12   6.64e-11      9.17e-60    1.57e+35
                              var(_cons) |    17.1794   5.764264      8.900235    33.16001
            -----------------------------+------------------------------------------------
                           var(Residual) |   81.30744    7.81502      67.34656    98.16239
            ------------------------------------------------------------------------------
            From the model results, how should I tell whether all the interactions are needed or not? I am thinking of using -testparm- but I am not sure whether this is correct.
            Then, in order to explore the for each disability type, how their expected outcome changes in response to age, I used the following syntax:
            Code:
            margins DISAB, dydx(AGEYEAR)
            Code:
            . margins DISAB, dydx(AGEYEAR)
            
            Average marginal effects                          Number of obs   =       1531
            Model VCE    : Robust
            
            Expression   : Linear prediction, fixed portion, predict()
            dy/dx w.r.t. : AGEYEAR
            
            ------------------------------------------------------------------------------
                         |            Delta-method
                         |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
            AGEYEAR      |
                   DISAB |
                    ASD  |  -1.179535   2.025711    -0.58   0.560    -5.149857    2.790786
                     DD  |   -1.14946     1.1268    -1.02   0.308    -3.357948    1.059028
                     ED  |   1.982542   1.793835     1.11   0.269    -1.533309    5.498394
                     LD  |  -2.972947   1.452847    -2.05   0.041    -5.820475   -.1254193
                     ID  |  -3.514025    2.64971    -1.33   0.185    -8.707362    1.679311
                     OI  |   1.431416   1.864419     0.77   0.443    -2.222778    5.085609
                    OHI  |   1.185473   2.351218     0.50   0.614    -3.422829    5.793774
                    SLI  |  -.8156429   .6025729    -1.35   0.176    -1.996664    .3653782
                    LOW  |   4.066647    1.78596     2.28   0.023     .5662306    7.567064
            ------------------------------------------------------------------------------
            But what if I want to know how the baseline measure affects expected outcome by disability type?

            Thanks!

            Comment


            • #7
              To test the joint significance of each interaction you can do:

              Code:
              testparm i.DISAB#c.AGEYEAR
              testparm i.DISAB#c.BASEVAR1
              // etc.
              To see the how the baseline measure affects expected outcome by disability type:

              Code:
              margins DISAB, dydx(BASEVAR1 BASEVAR2)

              Comment


              • #8
                Thanks a lot Clyde.

                Comment

                Working...
                X