Announcement

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

  • margins & marginsplot after mixed effect/multilevel modelling

    Hi All

    I've used linear spline multilevel modelling to analyses rate in change of multimorbidity in a group of individuals:

    generate the spline variables (4 variables that correspond to 4 periods, wave1 = 1982 to 1989, wave2 = 1989 to 1999, wave3 = 1999 to 2009 & wave4 = 2009 to 2015:

    Code:
    mkspline wave1 1 wave2 2 wave3 3 wave4 = wavex
    Run the multilevel model with the 4 spline variables (randome slope & random intercept):

    Code:
    mixed score wave1 wave2 wave3 wave4 sex || NSHD_ID: wavex, cov(unstr) mle stddev
    margins sex, at(wavex=(0 1 2 3 4 ))
    The multilevel model works just fine:

    Mixed-effects ML regression Number of obs = 18,615
    Group variable: NSHD_ID Number of groups = 3,723

    Obs per group:
    min = 5
    avg = 5.0
    max = 5

    Wald chi2(5) = 2057.52
    Log likelihood = -29275.269 Prob > chi2 = 0.0000

    ------------------------------------------------------------------------------
    score | Coef. Std. Err. z P>|z| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    wave1 | .4517862 .0221717 20.38 0.000 .4083305 .4952419
    wave2 | .3639538 .0221717 16.42 0.000 .3204981 .4074095
    wave3 | .2409347 .0221717 10.87 0.000 .197479 .2843904
    wave4 | .4963739 .0221717 22.39 0.000 .4529182 .5398296
    sex | .1654415 .0260374 6.35 0.000 .1144092 .2164739
    _cons | .3395521 .0425618 7.98 0.000 .2561326 .4229716
    ------------------------------------------------------------------------------

    ------------------------------------------------------------------------------
    Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
    -----------------------------+------------------------------------------------
    NSHD_ID: Unstructured |
    sd(wavex) | .4243546 .0072879 .4103083 .4388818
    sd(_cons) | .5270375 .0181214 .4926906 .5637788
    corr(wavex,_cons) | -.1251645 .033656 -.1904833 -.0587422
    -----------------------------+------------------------------------------------
    sd(Residual) | .9083197 .0060774 .896486 .9203096
    ------------------------------------------------------------------------------
    LR test vs. linear model: chi2(3) = 7825.50 Prob > chi2 = 0.0000


    However, I get the error msg below when trying to run the margins command. I haven't had this issue before. I don't want to include the 'wavex' variable in the fixed effects part of the model as I have the spline variables. Is there a way around this?

    variable 'wavex' not found in list of covariates
    r(322);

    end of do-file

    r(322);

    Thanks!
    /Amal
Working...
X