Announcement

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

  • Mixed-effects logistic regression for panel data

    Hello, I am using mixed-effects logistic regression for panel data in STATA 15, and I was wondering if my commands are correct.

    My DV is a binary variable, and each respondent was surveyed once a year for five years. So, each respondent has five repeated measures. In the data, the respondent identifier is the variable ID. I also have time-varying covariates IV1, IV2, and time-invariant covariates IV3 and IV4, and a time variable Year. I want to use a mixed-effects logistic regression as follows:

    Code:
    melogit DV IV1 IV2 IV3 IV4 Year || ID: Year, cov(un)
    But, this is kind of like a growth curve model except for the binary DV. I was wondering if my command is correct, and what is the difference between a growth curve model and a mixed-effects logistic model for panel data. Thank you very much!

  • #2
    Hi Yapeng,

    I am also working in the same area and i think i have spotted your issue.

    Is you goal to have random coefficient for the year? This is not the typical approach for growth curve models so i assume this is not the case.

    Furthermore, you were treat year as a continuous variable. If this was the case, do not put a factor prefix. But you might want to consider not doing this, or if you are doing it re base the number so it not the current calendar year (age or year since the study began for example).

    I would change your syntax to

    Code
    melogit DV IV1 IV2 IV3 IV4 i.Year || ID:, cov(un)
    This allows for fixed effects for the year's (as that is part of the feature of the mixed model), random intercepts for the id's.

    I do not see why you are specifying the co-variance structure to be unrestrained, as you only have one level the code should change this (from my experience) to identity. So there is no need to change this.

    Hope this helps

    Comment


    • #3
      Originally posted by Robert Wells View Post
      Hi Yapeng,

      I am also working in the same area and i think i have spotted your issue.

      Is you goal to have random coefficient for the year? This is not the typical approach for growth curve models so i assume this is not the case.

      Furthermore, you were treat year as a continuous variable. If this was the case, do not put a factor prefix. But you might want to consider not doing this, or if you are doing it re base the number so it not the current calendar year (age or year since the study began for example).

      I would change your syntax to

      Code


      This allows for fixed effects for the year's (as that is part of the feature of the mixed model), random intercepts for the id's.

      I do not see why you are specifying the co-variance structure to be unrestrained, as you only have one level the code should change this (from my experience) to identity. So there is no need to change this.

      Hope this helps
      Hi Robert,

      Thank you for your reply! Actually, I want to add a random slope for the year since I want to get a rate of change, like people usually do in a growth curve model. I know it is doable in a growth curve model such as
      Code:
      mixed DV IV year || ID: year, cov(un)
      However, I am not sure if this is doable when the DV is a binary rather than continuous variable. I am still confused about how to deal with time in a mixed-effects model for a binary outcome.

      Best,
      Yapeng

      Comment


      • #4
        Originally posted by Robert Wells View Post
        Hi Yapeng,

        I am also working in the same area and i think i have spotted your issue.

        Is you goal to have random coefficient for the year? This is not the typical approach for growth curve models so i assume this is not the case.

        Furthermore, you were treat year as a continuous variable. If this was the case, do not put a factor prefix. But you might want to consider not doing this, or if you are doing it re base the number so it not the current calendar year (age or year since the study began for example).

        I would change your syntax to

        Code


        This allows for fixed effects for the year's (as that is part of the feature of the mixed model), random intercepts for the id's.

        I do not see why you are specifying the co-variance structure to be unrestrained, as you only have one level the code should change this (from my experience) to identity. So there is no need to change this.

        Hope this helps
        Hi Robert,

        Thank you for your reply! Actually, I want to add a random slope for the year since I want to get a rate of change, like people usually do in a growth curve model. I know it is doable in a growth curve model such as
        Code:
        mixed DV IV year || ID: year, cov(un)
        However, I am not sure if this is doable when the DV is a binary rather than continuous variable. I am still confused about how to deal with time in a mixed-effects model for a binary outcome.

        Best,
        Yapeng

        Comment


        • #5
          Hi Yapeng,

          Random Coefficient growth curve model it then. in that case, the cov(un) option is warranted.

          In that case, i believe your current syntax is fine. I personally, would add a quadratic term for year in the fixed equation. This allows your growth curve to approach some sort of maximum (or otherwise)

          The adjusted code would be

          Code:
          generate year2=year^2 
           mixed DV IV year year2 || ID: year, cov(un)
          I highly recommend the book Multi-level and Longitudinal Modelling using Stata. It has a number of chapters that address your problem. Complete with code.

          Cheers
          Rob

          Comment


          • #6
            Originally posted by Yapeng Wang View Post
            I am using mixed-effects logistic regression for panel data in STATA 15. . . this is kind of like a growth curve model except for the binary DV. I was wondering if my command is correct, and what is the difference between a growth curve model and a mixed-effects logistic model for panel data.
            The random slope hierarchical logistic regression model that you show for -melogit- gives the same fit as a logistic growth curve model in -gsem-. See below. (Pardon my specification for the latter if it appears clumsy.) Both models are fitted to a toy dataset created for illustration.

            .ÿ
            .ÿversionÿ15.1

            .ÿ
            .ÿclearÿ*

            .ÿ
            .ÿsetÿseedÿ`=strreverse("155422")'

            .ÿ
            .ÿquietlyÿsetÿobsÿ200

            .ÿgenerateÿintÿpidÿ=ÿ_n

            .ÿquietlyÿdrawnormÿpid_interceptÿpid_slope,ÿdoubleÿcorr(1ÿ-0.25ÿ\ÿ-0.25ÿ1)

            .ÿgenerateÿdoubleÿticÿ=ÿruniform()ÿ-ÿ0.5ÿ//ÿTime-invariantÿcovariate

            .ÿ
            .ÿquietlyÿexpandÿ5

            .ÿbysortÿpid:ÿgenerateÿbyteÿtimÿ=ÿ_n

            .ÿgenerateÿdoubleÿtvcÿ=ÿruniform()ÿ-ÿ0.5ÿ//ÿTime-varyingÿcovariate

            .ÿ
            .ÿgenerateÿdoubleÿxbÿ=ÿ///
            >ÿÿÿÿÿÿÿÿÿ0ÿ+ÿpid_interceptÿ+ÿ0ÿ*ÿticÿ+ÿ///
            >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ(timÿ-ÿ3)ÿ/ÿ2ÿ*ÿ(1/5ÿ+ÿpid_slope)ÿ+ÿ0ÿ*ÿtvc

            .ÿgenerateÿbyteÿoutÿ=ÿrbinomial(1,ÿinvlogit(xb))

            .ÿ
            .ÿ*
            .ÿ*ÿBeginÿhere
            .ÿ*
            .ÿmelogitÿoutÿc.(ticÿtimÿtvc)ÿ||ÿpid:ÿtim,ÿcovariance(unstructured)ÿnolog

            Mixed-effectsÿlogisticÿregressionÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿÿ=ÿÿÿÿÿÿ1,000
            Groupÿvariable:ÿÿÿÿÿÿÿÿÿÿÿÿÿpidÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿgroupsÿÿ=ÿÿÿÿÿÿÿÿ200

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

            Integrationÿmethod:ÿmvaghermiteÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿIntegrationÿpts.ÿÿ=ÿÿÿÿÿÿÿÿÿÿ7

            ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWaldÿchi2(3)ÿÿÿÿÿÿ=ÿÿÿÿÿÿÿ3.55
            Logÿlikelihoodÿ=ÿ-664.71764ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿÿÿÿÿÿÿ=ÿÿÿÿÿ0.3138
            --------------------------------------------------------------------------------
            ÿÿÿÿÿÿÿÿÿÿÿoutÿ|ÿÿÿÿÿÿCoef.ÿÿÿStd.ÿErr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿConf.ÿInterval]
            ---------------+----------------------------------------------------------------
            ÿÿÿÿÿÿÿÿÿÿÿticÿ|ÿÿÿ.1959145ÿÿÿ.3754731ÿÿÿÿÿ0.52ÿÿÿ0.602ÿÿÿÿ-.5399992ÿÿÿÿ.9318281
            ÿÿÿÿÿÿÿÿÿÿÿtimÿ|ÿÿÿ.1197285ÿÿÿÿ.067201ÿÿÿÿÿ1.78ÿÿÿ0.075ÿÿÿÿ-.0119832ÿÿÿÿ.2514401
            ÿÿÿÿÿÿÿÿÿÿÿtvcÿ|ÿÿ-.1141664ÿÿÿ.2831145ÿÿÿÿ-0.40ÿÿÿ0.687ÿÿÿÿ-.6690607ÿÿÿÿ.4407279
            ÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿ-.3988859ÿÿÿÿ.238745ÿÿÿÿ-1.67ÿÿÿ0.095ÿÿÿÿ-.8668175ÿÿÿÿ.0690458
            ---------------+----------------------------------------------------------------
            pidÿÿÿÿÿÿÿÿÿÿÿÿ|
            ÿÿÿÿÿÿÿvar(tim)|ÿÿÿ.3061836ÿÿÿ.1232728ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.1390846ÿÿÿÿ.6740387
            ÿÿÿÿÿvar(_cons)|ÿÿÿ4.633829ÿÿÿÿ1.69718ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ2.260373ÿÿÿÿ9.499482
            ---------------+----------------------------------------------------------------
            pidÿÿÿÿÿÿÿÿÿÿÿÿ|
            ÿcov(tim,_cons)|ÿÿ-1.019001ÿÿÿ.4213028ÿÿÿÿ-2.42ÿÿÿ0.016ÿÿÿÿ-1.844739ÿÿÿ-.1932623
            --------------------------------------------------------------------------------
            LRÿtestÿvs.ÿlogisticÿmodel:ÿchi2(3)ÿ=ÿ52.48ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿ=ÿ0.0000

            Note:ÿLRÿtestÿisÿconservativeÿandÿprovidedÿonlyÿforÿreference.

            .ÿ
            .ÿkeepÿpidÿt*ÿout

            .ÿgenerateÿbyteÿtimeÿ=ÿtim

            .ÿquietlyÿreshapeÿwideÿticÿtvcÿtimÿout,ÿi(pid)ÿj(time)

            .ÿrenameÿtic1ÿtic

            .ÿdropÿtic?

            .ÿ
            .ÿforvaluesÿiÿ=ÿ2/5ÿ{
            ÿÿ2.ÿÿÿÿÿÿÿÿÿconstraintÿdefineÿ`i'ÿ_b[out`i':_cons]ÿ=ÿ_b[out1:_cons]
            ÿÿ3.ÿÿÿÿÿÿÿÿÿconstraintÿdefineÿ10`i'ÿ_b[out`i':tim`i']ÿ=ÿ_b[out1:tim1]
            ÿÿ4.ÿ}

            .ÿgsemÿ///
            >ÿÿÿÿÿÿÿÿÿ(out1ÿ<-ÿc.tic@iÿc.tim1ÿc.tvc1@vÿI@1ÿS@1,ÿlogit)ÿ///
            >ÿÿÿÿÿÿÿÿÿ(out2ÿ<-ÿc.tic@iÿc.tim2ÿc.tvc2@vÿI@1ÿS@2,ÿlogit)ÿ///
            >ÿÿÿÿÿÿÿÿÿ(out3ÿ<-ÿc.tic@iÿc.tim3ÿc.tvc3@vÿI@1ÿS@3,ÿlogit)ÿ///
            >ÿÿÿÿÿÿÿÿÿ(out4ÿ<-ÿc.tic@iÿc.tim4ÿc.tvc4@vÿI@1ÿS@4,ÿlogit)ÿ///
            >ÿÿÿÿÿÿÿÿÿ(out5ÿ<-ÿc.tic@iÿc.tim5ÿc.tvc5@vÿI@1ÿS@5,ÿlogit),ÿ///
            >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿcollinearÿconstraints(2/5ÿ102/105)ÿ///
            >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿnodvheaderÿnocnsreportÿnolog

            GeneralizedÿstructuralÿequationÿmodelÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿÿ=ÿÿÿÿÿÿÿÿ200
            Logÿlikelihoodÿ=ÿ-664.72063

            ------------------------------------------------------------------------------
            ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿÿÿÿCoef.ÿÿÿStd.ÿErr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿConf.ÿInterval]
            -------------+----------------------------------------------------------------
            out1ÿÿÿÿÿÿÿÿÿ|
            ÿÿÿÿÿÿÿÿÿticÿ|ÿÿÿ.1960443ÿÿÿ.3754558ÿÿÿÿÿ0.52ÿÿÿ0.602ÿÿÿÿ-.5398356ÿÿÿÿ.9319243
            ÿÿÿÿÿÿÿÿtim1ÿ|ÿÿÿ.1197392ÿÿÿ.0671983ÿÿÿÿÿ1.78ÿÿÿ0.075ÿÿÿÿ-.0119671ÿÿÿÿ.2514456
            ÿÿÿÿÿÿÿÿtvc1ÿ|ÿÿ-.1140352ÿÿÿ.2830953ÿÿÿÿ-0.40ÿÿÿ0.687ÿÿÿÿ-.6688917ÿÿÿÿ.4408213
            ÿÿÿÿÿÿÿÿÿÿÿIÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ2.42e-17ÿÿ4.1e+16ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿÿÿÿÿÿ1
            ÿÿÿÿÿÿÿÿÿÿÿSÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ1.40e-16ÿÿ7.2e+15ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿÿÿÿÿÿ1
            ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.3989264ÿÿÿ.2387248ÿÿÿÿ-1.67ÿÿÿ0.095ÿÿÿÿ-.8668185ÿÿÿÿ.0689657
            -------------+----------------------------------------------------------------
            out2ÿÿÿÿÿÿÿÿÿ|
            ÿÿÿÿÿÿÿÿÿticÿ|ÿÿÿ.1960443ÿÿÿ.3754558ÿÿÿÿÿ0.52ÿÿÿ0.602ÿÿÿÿ-.5398356ÿÿÿÿ.9319243
            ÿÿÿÿÿÿÿÿtim2ÿ|ÿÿÿ.1197392ÿÿÿ.0671983ÿÿÿÿÿ1.78ÿÿÿ0.075ÿÿÿÿ-.0119671ÿÿÿÿ.2514456
            ÿÿÿÿÿÿÿÿtvc2ÿ|ÿÿ-.1140352ÿÿÿ.2830953ÿÿÿÿ-0.40ÿÿÿ0.687ÿÿÿÿ-.6688917ÿÿÿÿ.4408213
            ÿÿÿÿÿÿÿÿÿÿÿIÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ5.73e-44ÿÿ1.7e+43ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿÿÿÿÿÿ1
            ÿÿÿÿÿÿÿÿÿÿÿSÿ|ÿÿÿÿÿÿÿÿÿÿ2ÿÿÿ2.22e-43ÿÿ9.0e+42ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ2ÿÿÿÿÿÿÿÿÿÿÿ2
            ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.3989264ÿÿÿ.2387248ÿÿÿÿ-1.67ÿÿÿ0.095ÿÿÿÿ-.8668185ÿÿÿÿ.0689657
            -------------+----------------------------------------------------------------
            out3ÿÿÿÿÿÿÿÿÿ|
            ÿÿÿÿÿÿÿÿÿticÿ|ÿÿÿ.1960443ÿÿÿ.3754558ÿÿÿÿÿ0.52ÿÿÿ0.602ÿÿÿÿ-.5398356ÿÿÿÿ.9319243
            ÿÿÿÿÿÿÿÿtim3ÿ|ÿÿÿ.1197392ÿÿÿ.0671983ÿÿÿÿÿ1.78ÿÿÿ0.075ÿÿÿÿ-.0119671ÿÿÿÿ.2514456
            ÿÿÿÿÿÿÿÿtvc3ÿ|ÿÿ-.1140352ÿÿÿ.2830953ÿÿÿÿ-0.40ÿÿÿ0.687ÿÿÿÿ-.6688917ÿÿÿÿ.4408213
            ÿÿÿÿÿÿÿÿÿÿÿIÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ3.25e-43ÿÿ3.1e+42ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿÿÿÿÿÿ1
            ÿÿÿÿÿÿÿÿÿÿÿSÿ|ÿÿÿÿÿÿÿÿÿÿ3ÿÿÿ1.61e-43ÿÿ1.9e+43ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ3ÿÿÿÿÿÿÿÿÿÿÿ3
            ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.3989264ÿÿÿ.2387248ÿÿÿÿ-1.67ÿÿÿ0.095ÿÿÿÿ-.8668185ÿÿÿÿ.0689657
            -------------+----------------------------------------------------------------
            out4ÿÿÿÿÿÿÿÿÿ|
            ÿÿÿÿÿÿÿÿÿticÿ|ÿÿÿ.1960443ÿÿÿ.3754558ÿÿÿÿÿ0.52ÿÿÿ0.602ÿÿÿÿ-.5398356ÿÿÿÿ.9319243
            ÿÿÿÿÿÿÿÿtim4ÿ|ÿÿÿ.1197392ÿÿÿ.0671983ÿÿÿÿÿ1.78ÿÿÿ0.075ÿÿÿÿ-.0119671ÿÿÿÿ.2514456
            ÿÿÿÿÿÿÿÿtvc4ÿ|ÿÿ-.1140352ÿÿÿ.2830953ÿÿÿÿ-0.40ÿÿÿ0.687ÿÿÿÿ-.6688917ÿÿÿÿ.4408213
            ÿÿÿÿÿÿÿÿÿÿÿIÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ1.64e-43ÿÿ6.1e+42ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿÿÿÿÿÿ1
            ÿÿÿÿÿÿÿÿÿÿÿSÿ|ÿÿÿÿÿÿÿÿÿÿ4ÿÿÿ2.49e-43ÿÿ1.6e+43ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ4ÿÿÿÿÿÿÿÿÿÿÿ4
            ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.3989264ÿÿÿ.2387248ÿÿÿÿ-1.67ÿÿÿ0.095ÿÿÿÿ-.8668185ÿÿÿÿ.0689657
            -------------+----------------------------------------------------------------
            out5ÿÿÿÿÿÿÿÿÿ|
            ÿÿÿÿÿÿÿÿÿticÿ|ÿÿÿ.1960443ÿÿÿ.3754558ÿÿÿÿÿ0.52ÿÿÿ0.602ÿÿÿÿ-.5398356ÿÿÿÿ.9319243
            ÿÿÿÿÿÿÿÿtim5ÿ|ÿÿÿ.1197392ÿÿÿ.0671983ÿÿÿÿÿ1.78ÿÿÿ0.075ÿÿÿÿ-.0119671ÿÿÿÿ.2514456
            ÿÿÿÿÿÿÿÿtvc5ÿ|ÿÿ-.1140352ÿÿÿ.2830953ÿÿÿÿ-0.40ÿÿÿ0.687ÿÿÿÿ-.6688917ÿÿÿÿ.4408213
            ÿÿÿÿÿÿÿÿÿÿÿIÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿ(constrained)
            ÿÿÿÿÿÿÿÿÿÿÿSÿ|ÿÿÿÿÿÿÿÿÿÿ5ÿÿ(constrained)
            ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.3989264ÿÿÿ.2387248ÿÿÿÿ-1.67ÿÿÿ0.095ÿÿÿÿ-.8668185ÿÿÿÿ.0689657
            -------------+----------------------------------------------------------------
            ÿÿÿÿÿÿÿvar(I)|ÿÿÿ4.625699ÿÿÿ1.689133ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ2.261258ÿÿÿÿ9.462471
            ÿÿÿÿÿÿÿvar(S)|ÿÿÿ.3057181ÿÿÿ.1229581ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.1389865ÿÿÿÿ.6724648
            -------------+----------------------------------------------------------------
            ÿÿÿÿÿcov(I,S)|ÿÿ-1.017124ÿÿÿ.4196862ÿÿÿÿ-2.42ÿÿÿ0.015ÿÿÿÿ-1.839694ÿÿÿ-.1945538
            ------------------------------------------------------------------------------

            .ÿ
            .ÿexit

            endÿofÿdo-file


            .

            Comment


            • #7
              Originally posted by Robert Wells View Post
              Hi Yapeng,

              Random Coefficient growth curve model it then. in that case, the cov(un) option is warranted.

              In that case, i believe your current syntax is fine. I personally, would add a quadratic term for year in the fixed equation. This allows your growth curve to approach some sort of maximum (or otherwise)

              The adjusted code would be

              Code:
              generate year2=year^2
              mixed DV IV year year2 || ID: year, cov(un)
              I highly recommend the book Multi-level and Longitudinal Modelling using Stata. It has a number of chapters that address your problem. Complete with code.

              Cheers
              Rob
              Hi Rob, Thank you very much!

              Comment


              • #8
                Originally posted by Joseph Coveney View Post
                The random slope hierarchical logistic regression model that you show for -melogit- gives the same fit as a logistic growth curve model in -gsem-. See below. (Pardon my specification for the latter if it appears clumsy.) Both models are fitted to a toy dataset created for illustration.

                .ÿ
                .ÿversionÿ15.1

                .ÿ
                .ÿclearÿ*

                .ÿ
                .ÿsetÿseedÿ`=strreverse("155422")'

                .ÿ
                .ÿquietlyÿsetÿobsÿ200

                .ÿgenerateÿintÿpidÿ=ÿ_n

                .ÿquietlyÿdrawnormÿpid_interceptÿpid_slope,ÿdoubleÿcorr(1ÿ-0.25ÿ\ÿ-0.25ÿ1)

                .ÿgenerateÿdoubleÿticÿ=ÿruniform()ÿ-ÿ0.5ÿ//ÿTime-invariantÿcovariate

                .ÿ
                .ÿquietlyÿexpandÿ5

                .ÿbysortÿpid:ÿgenerateÿbyteÿtimÿ=ÿ_n

                .ÿgenerateÿdoubleÿtvcÿ=ÿruniform()ÿ-ÿ0.5ÿ//ÿTime-varyingÿcovariate

                .ÿ
                .ÿgenerateÿdoubleÿxbÿ=ÿ///
                >ÿÿÿÿÿÿÿÿÿ0ÿ+ÿpid_interceptÿ+ÿ0ÿ*ÿticÿ+ÿ///
                >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ(timÿ-ÿ3)ÿ/ÿ2ÿ*ÿ(1/5ÿ+ÿpid_slope)ÿ+ÿ0ÿ*ÿtvc

                .ÿgenerateÿbyteÿoutÿ=ÿrbinomial(1,ÿinvlogit(xb))

                .ÿ
                .ÿ*
                .ÿ*ÿBeginÿhere
                .ÿ*
                .ÿmelogitÿoutÿc.(ticÿtimÿtvc)ÿ||ÿpid:ÿtim,ÿcovariance(unstructured)ÿnolog

                Mixed-effectsÿlogisticÿregressionÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿÿ=ÿÿÿÿÿÿ1,000
                Groupÿvariable:ÿÿÿÿÿÿÿÿÿÿÿÿÿpidÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿgroupsÿÿ=ÿÿÿÿÿÿÿÿ200

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

                Integrationÿmethod:ÿmvaghermiteÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿIntegrationÿpts.ÿÿ=ÿÿÿÿÿÿÿÿÿÿ7

                ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWaldÿchi2(3)ÿÿÿÿÿÿ=ÿÿÿÿÿÿÿ3.55
                Logÿlikelihoodÿ=ÿ-664.71764ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿÿÿÿÿÿÿ=ÿÿÿÿÿ0.3138
                --------------------------------------------------------------------------------
                ÿÿÿÿÿÿÿÿÿÿÿoutÿ|ÿÿÿÿÿÿCoef.ÿÿÿStd.ÿErr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿConf.ÿInterval]
                ---------------+----------------------------------------------------------------
                ÿÿÿÿÿÿÿÿÿÿÿticÿ|ÿÿÿ.1959145ÿÿÿ.3754731ÿÿÿÿÿ0.52ÿÿÿ0.602ÿÿÿÿ-.5399992ÿÿÿÿ.9318281
                ÿÿÿÿÿÿÿÿÿÿÿtimÿ|ÿÿÿ.1197285ÿÿÿÿ.067201ÿÿÿÿÿ1.78ÿÿÿ0.075ÿÿÿÿ-.0119832ÿÿÿÿ.2514401
                ÿÿÿÿÿÿÿÿÿÿÿtvcÿ|ÿÿ-.1141664ÿÿÿ.2831145ÿÿÿÿ-0.40ÿÿÿ0.687ÿÿÿÿ-.6690607ÿÿÿÿ.4407279
                ÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿ-.3988859ÿÿÿÿ.238745ÿÿÿÿ-1.67ÿÿÿ0.095ÿÿÿÿ-.8668175ÿÿÿÿ.0690458
                ---------------+----------------------------------------------------------------
                pidÿÿÿÿÿÿÿÿÿÿÿÿ|
                ÿÿÿÿÿÿÿvar(tim)|ÿÿÿ.3061836ÿÿÿ.1232728ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.1390846ÿÿÿÿ.6740387
                ÿÿÿÿÿvar(_cons)|ÿÿÿ4.633829ÿÿÿÿ1.69718ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ2.260373ÿÿÿÿ9.499482
                ---------------+----------------------------------------------------------------
                pidÿÿÿÿÿÿÿÿÿÿÿÿ|
                ÿcov(tim,_cons)|ÿÿ-1.019001ÿÿÿ.4213028ÿÿÿÿ-2.42ÿÿÿ0.016ÿÿÿÿ-1.844739ÿÿÿ-.1932623
                --------------------------------------------------------------------------------
                LRÿtestÿvs.ÿlogisticÿmodel:ÿchi2(3)ÿ=ÿ52.48ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿ=ÿ0.0000

                Note:ÿLRÿtestÿisÿconservativeÿandÿprovidedÿonlyÿforÿreference.

                .ÿ
                .ÿkeepÿpidÿt*ÿout

                .ÿgenerateÿbyteÿtimeÿ=ÿtim

                .ÿquietlyÿreshapeÿwideÿticÿtvcÿtimÿout,ÿi(pid)ÿj(time)

                .ÿrenameÿtic1ÿtic

                .ÿdropÿtic?

                .ÿ
                .ÿforvaluesÿiÿ=ÿ2/5ÿ{
                ÿÿ2.ÿÿÿÿÿÿÿÿÿconstraintÿdefineÿ`i'ÿ_b[out`i':_cons]ÿ=ÿ_b[out1:_cons]
                ÿÿ3.ÿÿÿÿÿÿÿÿÿconstraintÿdefineÿ10`i'ÿ_b[out`i':tim`i']ÿ=ÿ_b[out1:tim1]
                ÿÿ4.ÿ}

                .ÿgsemÿ///
                >ÿÿÿÿÿÿÿÿÿ(out1ÿ<-ÿc.tic@iÿc.tim1ÿc.tvc1@vÿI@1ÿS@1,ÿlogit)ÿ///
                >ÿÿÿÿÿÿÿÿÿ(out2ÿ<-ÿc.tic@iÿc.tim2ÿc.tvc2@vÿI@1ÿS@2,ÿlogit)ÿ///
                >ÿÿÿÿÿÿÿÿÿ(out3ÿ<-ÿc.tic@iÿc.tim3ÿc.tvc3@vÿI@1ÿS@3,ÿlogit)ÿ///
                >ÿÿÿÿÿÿÿÿÿ(out4ÿ<-ÿc.tic@iÿc.tim4ÿc.tvc4@vÿI@1ÿS@4,ÿlogit)ÿ///
                >ÿÿÿÿÿÿÿÿÿ(out5ÿ<-ÿc.tic@iÿc.tim5ÿc.tvc5@vÿI@1ÿS@5,ÿlogit),ÿ///
                >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿcollinearÿconstraints(2/5ÿ102/105)ÿ///
                >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿnodvheaderÿnocnsreportÿnolog

                GeneralizedÿstructuralÿequationÿmodelÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿÿ=ÿÿÿÿÿÿÿÿ200
                Logÿlikelihoodÿ=ÿ-664.72063

                ------------------------------------------------------------------------------
                ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿÿÿÿCoef.ÿÿÿStd.ÿErr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿConf.ÿInterval]
                -------------+----------------------------------------------------------------
                out1ÿÿÿÿÿÿÿÿÿ|
                ÿÿÿÿÿÿÿÿÿticÿ|ÿÿÿ.1960443ÿÿÿ.3754558ÿÿÿÿÿ0.52ÿÿÿ0.602ÿÿÿÿ-.5398356ÿÿÿÿ.9319243
                ÿÿÿÿÿÿÿÿtim1ÿ|ÿÿÿ.1197392ÿÿÿ.0671983ÿÿÿÿÿ1.78ÿÿÿ0.075ÿÿÿÿ-.0119671ÿÿÿÿ.2514456
                ÿÿÿÿÿÿÿÿtvc1ÿ|ÿÿ-.1140352ÿÿÿ.2830953ÿÿÿÿ-0.40ÿÿÿ0.687ÿÿÿÿ-.6688917ÿÿÿÿ.4408213
                ÿÿÿÿÿÿÿÿÿÿÿIÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ2.42e-17ÿÿ4.1e+16ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿÿÿÿÿÿ1
                ÿÿÿÿÿÿÿÿÿÿÿSÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ1.40e-16ÿÿ7.2e+15ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿÿÿÿÿÿ1
                ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.3989264ÿÿÿ.2387248ÿÿÿÿ-1.67ÿÿÿ0.095ÿÿÿÿ-.8668185ÿÿÿÿ.0689657
                -------------+----------------------------------------------------------------
                out2ÿÿÿÿÿÿÿÿÿ|
                ÿÿÿÿÿÿÿÿÿticÿ|ÿÿÿ.1960443ÿÿÿ.3754558ÿÿÿÿÿ0.52ÿÿÿ0.602ÿÿÿÿ-.5398356ÿÿÿÿ.9319243
                ÿÿÿÿÿÿÿÿtim2ÿ|ÿÿÿ.1197392ÿÿÿ.0671983ÿÿÿÿÿ1.78ÿÿÿ0.075ÿÿÿÿ-.0119671ÿÿÿÿ.2514456
                ÿÿÿÿÿÿÿÿtvc2ÿ|ÿÿ-.1140352ÿÿÿ.2830953ÿÿÿÿ-0.40ÿÿÿ0.687ÿÿÿÿ-.6688917ÿÿÿÿ.4408213
                ÿÿÿÿÿÿÿÿÿÿÿIÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ5.73e-44ÿÿ1.7e+43ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿÿÿÿÿÿ1
                ÿÿÿÿÿÿÿÿÿÿÿSÿ|ÿÿÿÿÿÿÿÿÿÿ2ÿÿÿ2.22e-43ÿÿ9.0e+42ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ2ÿÿÿÿÿÿÿÿÿÿÿ2
                ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.3989264ÿÿÿ.2387248ÿÿÿÿ-1.67ÿÿÿ0.095ÿÿÿÿ-.8668185ÿÿÿÿ.0689657
                -------------+----------------------------------------------------------------
                out3ÿÿÿÿÿÿÿÿÿ|
                ÿÿÿÿÿÿÿÿÿticÿ|ÿÿÿ.1960443ÿÿÿ.3754558ÿÿÿÿÿ0.52ÿÿÿ0.602ÿÿÿÿ-.5398356ÿÿÿÿ.9319243
                ÿÿÿÿÿÿÿÿtim3ÿ|ÿÿÿ.1197392ÿÿÿ.0671983ÿÿÿÿÿ1.78ÿÿÿ0.075ÿÿÿÿ-.0119671ÿÿÿÿ.2514456
                ÿÿÿÿÿÿÿÿtvc3ÿ|ÿÿ-.1140352ÿÿÿ.2830953ÿÿÿÿ-0.40ÿÿÿ0.687ÿÿÿÿ-.6688917ÿÿÿÿ.4408213
                ÿÿÿÿÿÿÿÿÿÿÿIÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ3.25e-43ÿÿ3.1e+42ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿÿÿÿÿÿ1
                ÿÿÿÿÿÿÿÿÿÿÿSÿ|ÿÿÿÿÿÿÿÿÿÿ3ÿÿÿ1.61e-43ÿÿ1.9e+43ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ3ÿÿÿÿÿÿÿÿÿÿÿ3
                ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.3989264ÿÿÿ.2387248ÿÿÿÿ-1.67ÿÿÿ0.095ÿÿÿÿ-.8668185ÿÿÿÿ.0689657
                -------------+----------------------------------------------------------------
                out4ÿÿÿÿÿÿÿÿÿ|
                ÿÿÿÿÿÿÿÿÿticÿ|ÿÿÿ.1960443ÿÿÿ.3754558ÿÿÿÿÿ0.52ÿÿÿ0.602ÿÿÿÿ-.5398356ÿÿÿÿ.9319243
                ÿÿÿÿÿÿÿÿtim4ÿ|ÿÿÿ.1197392ÿÿÿ.0671983ÿÿÿÿÿ1.78ÿÿÿ0.075ÿÿÿÿ-.0119671ÿÿÿÿ.2514456
                ÿÿÿÿÿÿÿÿtvc4ÿ|ÿÿ-.1140352ÿÿÿ.2830953ÿÿÿÿ-0.40ÿÿÿ0.687ÿÿÿÿ-.6688917ÿÿÿÿ.4408213
                ÿÿÿÿÿÿÿÿÿÿÿIÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ1.64e-43ÿÿ6.1e+42ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿÿÿÿÿÿ1
                ÿÿÿÿÿÿÿÿÿÿÿSÿ|ÿÿÿÿÿÿÿÿÿÿ4ÿÿÿ2.49e-43ÿÿ1.6e+43ÿÿÿ0.000ÿÿÿÿÿÿÿÿÿÿÿÿ4ÿÿÿÿÿÿÿÿÿÿÿ4
                ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.3989264ÿÿÿ.2387248ÿÿÿÿ-1.67ÿÿÿ0.095ÿÿÿÿ-.8668185ÿÿÿÿ.0689657
                -------------+----------------------------------------------------------------
                out5ÿÿÿÿÿÿÿÿÿ|
                ÿÿÿÿÿÿÿÿÿticÿ|ÿÿÿ.1960443ÿÿÿ.3754558ÿÿÿÿÿ0.52ÿÿÿ0.602ÿÿÿÿ-.5398356ÿÿÿÿ.9319243
                ÿÿÿÿÿÿÿÿtim5ÿ|ÿÿÿ.1197392ÿÿÿ.0671983ÿÿÿÿÿ1.78ÿÿÿ0.075ÿÿÿÿ-.0119671ÿÿÿÿ.2514456
                ÿÿÿÿÿÿÿÿtvc5ÿ|ÿÿ-.1140352ÿÿÿ.2830953ÿÿÿÿ-0.40ÿÿÿ0.687ÿÿÿÿ-.6688917ÿÿÿÿ.4408213
                ÿÿÿÿÿÿÿÿÿÿÿIÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿ(constrained)
                ÿÿÿÿÿÿÿÿÿÿÿSÿ|ÿÿÿÿÿÿÿÿÿÿ5ÿÿ(constrained)
                ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.3989264ÿÿÿ.2387248ÿÿÿÿ-1.67ÿÿÿ0.095ÿÿÿÿ-.8668185ÿÿÿÿ.0689657
                -------------+----------------------------------------------------------------
                ÿÿÿÿÿÿÿvar(I)|ÿÿÿ4.625699ÿÿÿ1.689133ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ2.261258ÿÿÿÿ9.462471
                ÿÿÿÿÿÿÿvar(S)|ÿÿÿ.3057181ÿÿÿ.1229581ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.1389865ÿÿÿÿ.6724648
                -------------+----------------------------------------------------------------
                ÿÿÿÿÿcov(I,S)|ÿÿ-1.017124ÿÿÿ.4196862ÿÿÿÿ-2.42ÿÿÿ0.015ÿÿÿÿ-1.839694ÿÿÿ-.1945538
                ------------------------------------------------------------------------------

                .ÿ
                .ÿexit

                endÿofÿdo-file


                .
                Hi Joseph, thank you for your detailed post! It is very helpful!

                Comment

                Working...
                X