Announcement

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

  • gSEM syntax

    I am trying to teach myself SEM and I cannot work out the syntax for the following.

    I have a longitudinal dataset where each patient (pid) gives an opinion (q) at each of three times (t) and I want to use multinomial logistic regression for the analysis. I can model the effect of time:

    gsem (q<- i.t), mlogit

    but how do I allow for the fact that the data is repeated on patient?


    I have ordered a copy of Discovering Structural Equation Modeling Using Stata, Revised Edition, by Alan Acock but as it has not arrived yet I would be grateful for some advice.

    Thanks,
    Janet

  • #2
    Take a look at the help file for sem and gsem and click on the hyperlink for Examples in the Stata user's manual for SEM. What you probably want is shown in Example 41g. Something like the following is one model you could contemplate. (Begin at the "Begin here" comment.)

    .ÿ
    .ÿversionÿ16.1

    .ÿ
    .ÿclearÿ*

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

    .ÿ
    .ÿquietlyÿsetÿobsÿ250

    .ÿgenerateÿintÿpidÿ=ÿ_n

    .ÿgenerateÿdoubleÿpid_uÿ=ÿrnormal(0,ÿ0.25)

    .ÿ
    .ÿquietlyÿexpandÿ3

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

    .ÿ
    .ÿgenerateÿdoubleÿxb2ÿ=ÿln(0.25)ÿ*ÿpid_u

    .ÿgenerateÿdoubleÿxb3ÿ=ÿln(0.75)ÿ*ÿpid_u

    .ÿgenerateÿdoubleÿDÿ=ÿ1ÿ+ÿxb2ÿ+ÿxb3

    .ÿ
    .ÿgenerateÿdoubleÿpr1ÿ=ÿ1ÿ/ÿD

    .ÿgenerateÿdoubleÿpr2ÿ=ÿexp(xb2)ÿ/ÿD

    .ÿ
    .ÿgenerateÿdoubleÿranduÿ=ÿruniform()

    .ÿ
    .ÿgenerateÿbyteÿoutÿ=ÿcond(randuÿ<ÿpr1,ÿ1,ÿcond(randuÿ<ÿ(pr1ÿ+ÿpr2),ÿ2,ÿ3))

    .ÿ
    .ÿ*
    .ÿ*ÿBeginÿhere
    .ÿ*
    .ÿgsemÿ(outÿ<-ÿi.timÿM[pid]@1),ÿmlogitÿnocnsreportÿnodvheaderÿnolog

    GeneralizedÿstructuralÿequationÿmodelÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿÿ=ÿÿÿÿÿÿÿÿ750
    Logÿlikelihoodÿ=ÿ-305.34164

    ------------------------------------------------------------------------------
    ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿÿÿÿCoef.ÿÿÿStd.ÿErr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿConf.ÿInterval]
    -------------+----------------------------------------------------------------
    1.outÿÿÿÿÿÿÿÿ|ÿÿ(baseÿoutcome)
    -------------+----------------------------------------------------------------
    2.outÿÿÿÿÿÿÿÿ|
    ÿÿÿÿÿÿÿÿÿtimÿ|
    ÿÿÿÿÿÿÿÿÿÿ2ÿÿ|ÿÿ-.1502994ÿÿÿ.3168809ÿÿÿÿ-0.47ÿÿÿ0.635ÿÿÿÿ-.7713745ÿÿÿÿ.4707757
    ÿÿÿÿÿÿÿÿÿÿ3ÿÿ|ÿÿ-.1502994ÿÿÿ.3168809ÿÿÿÿ-0.47ÿÿÿ0.635ÿÿÿÿ-.7713745ÿÿÿÿ.4707757
    ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
    ÿÿÿÿÿÿM[pid]ÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿ(constrained)
    ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
    ÿÿÿÿÿÿÿ_consÿ|ÿÿÿ-2.86867ÿÿÿÿ.361206ÿÿÿÿ-7.94ÿÿÿ0.000ÿÿÿÿ-3.576621ÿÿÿÿ-2.16072
    -------------+----------------------------------------------------------------
    3.outÿÿÿÿÿÿÿÿ|
    ÿÿÿÿÿÿÿÿÿtimÿ|
    ÿÿÿÿÿÿÿÿÿÿ2ÿÿ|ÿÿÿ-.063288ÿÿÿ1.020947ÿÿÿÿ-0.06ÿÿÿ0.951ÿÿÿÿ-2.064307ÿÿÿÿ1.937731
    ÿÿÿÿÿÿÿÿÿÿ3ÿÿ|ÿÿÿ-.063288ÿÿÿ1.020947ÿÿÿÿ-0.06ÿÿÿ0.951ÿÿÿÿ-2.064307ÿÿÿÿ1.937731
    ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
    ÿÿÿÿÿÿM[pid]ÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿ(constrained)
    ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
    ÿÿÿÿÿÿÿ_consÿ|ÿÿ-5.759042ÿÿÿ.7763325ÿÿÿÿ-7.42ÿÿÿ0.000ÿÿÿÿ-7.280626ÿÿÿ-4.237459
    -------------+----------------------------------------------------------------
    ÿÿvar(M[pid])|ÿÿÿ4.531446ÿÿÿÿ1.45332ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ2.416799ÿÿÿÿ8.496364
    ------------------------------------------------------------------------------

    .ÿ
    .ÿexit

    endÿofÿdo-file


    .


    Acknowledgements to these two sources.

    Comment


    • #3
      Joseph,
      Thank you for the code and references.

      I had looked at Example 41g but I misunderstood the M1[suspect]@1 syntax.

      Janet

      Comment

      Working...
      X