Announcement

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

  • Moderation in SEM: Difference between creating interaction term & conducting group analysis

    Dear all,

    I have tried to conduct moderation analysis in SEM by 2 different methods, i.e. creating interaction term and conducting group analysis.
    However, I have obtained results which seem to lead to different conclusions.
    Here are the variables that I have used:
    ilo1 - ilo6: observed variables
    Ilo: latent factor (and DV)
    pre_post_r: categorical IV (0 or 1)
    sex_r: categorical moderator (0 or 1)

    By creating interaction term between pre_post_r and sex_r (sex_pp), I run the following SEM model:
    Code:
    sem (Ilo -> ilo1 ilo2 ilo3 ilo4 ilo5 ilo6) (pre_post_r -> Ilo) (sex_r -> Ilo) (sex_pp -> Ilo), cov(e.ilo2*e.ilo3) cov(e.ilo1*e.ilo2) cov(e.ilo1*e.ilo3)
    Below are the results. The interaction term (sex_pp) is insignificant. So I conclude that there is no moderation effect between the IV and the moderator.
    Code:
    Structural equation model                                Number of obs = 2,977
    Estimation method: ml
    
    Log likelihood = -28216.79
    
     ( 1)  [ilo1]Ilo = 1
    -----------------------------------------------------------------------------------
                      |                 OIM
                      | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
    ------------------+----------------------------------------------------------------
    Structural        |
      Ilo             |
           pre_post_r |   .6922629   .0669853    10.33   0.000     .5609741    .8235516
                sex_r |  -.6654334   .0517889   -12.85   0.000    -.7669378   -.5639291
               sex_pp |   .0830214   .0918951     0.90   0.366    -.0970898    .2631325
    ------------------+----------------------------------------------------------------
    Measurement       |
      ilo1            |
                  Ilo |          1  (constrained)
                _cons |    4.44004   .0393967   112.70   0.000     4.362824    4.517256
      ----------------+----------------------------------------------------------------
      ilo2            |
                  Ilo |   .7338301   .0175133    41.90   0.000     .6995047    .7681554
                _cons |   4.852122    .032443   149.56   0.000     4.788535    4.915709
      ----------------+----------------------------------------------------------------
      ilo3            |
                  Ilo |   .8969586   .0160456    55.90   0.000     .8655098    .9284074
                _cons |   4.723906   .0354097   133.41   0.000     4.654504    4.793308
      ----------------+----------------------------------------------------------------
      ilo4            |
                  Ilo |   1.071829   .0188535    56.85   0.000     1.034877    1.108781
                _cons |   4.508011   .0408367   110.39   0.000     4.427973    4.588049
      ----------------+----------------------------------------------------------------
      ilo5            |
                  Ilo |   1.150123   .0191861    59.95   0.000     1.112519    1.187727
                _cons |   4.127608   .0430686    95.84   0.000     4.043196    4.212021
      ----------------+----------------------------------------------------------------
      ilo6            |
                  Ilo |    1.05216   .0180955    58.14   0.000     1.016693    1.087626
                _cons |   4.348902   .0397949   109.28   0.000     4.270905    4.426899
    ------------------+----------------------------------------------------------------
           var(e.ilo1)|   .7572459   .0229944                      .7134926    .8036823
           var(e.ilo2)|   1.046165   .0289415                      .9909515    1.104456
           var(e.ilo3)|   .6229266   .0189183                      .5869293    .6611316
           var(e.ilo4)|   .5212302   .0174359                      .4881526    .5565491
           var(e.ilo5)|   .4115313    .015937                      .3814513    .4439832
           var(e.ilo6)|   .4391127   .0153359                      .4100605    .4702233
            var(e.Ilo)|   1.242897   .0473465                      1.153479    1.339246
    ------------------+----------------------------------------------------------------
    cov(e.ilo1,e.ilo2)|   .1561735   .0188641     8.28   0.000     .1192004    .1931465
    cov(e.ilo1,e.ilo3)|    .113366   .0154121     7.36   0.000     .0831588    .1435731
    cov(e.ilo2,e.ilo3)|   .3653889   .0185338    19.71   0.000     .3290634    .4017144
    -----------------------------------------------------------------------------------
    LR test of model vs. saturated: chi2(21) = 223.95              Prob > chi2 = 0.0000
    Afterwards, I run the following group analysis with another SEM model:
    Code:
    sem (Ilo ->  ilo1 ilo2 ilo3 ilo4 ilo5 ilo6) (pre_post_r -> Ilo), group(sex_r) ginvariant(mcoef mcons serrvar) cov( e.ilo1*e.ilo2 e.ilo1*e.ilo3 e.ilo2*e.ilo3)

    Code:
    Structural equation model                             Number of obs    = 2,977
    Grouping variable: sex_r                              Number of groups =     2
    Estimation method: ml
    
    Log likelihood = -26260.007
    
     ( 1)  [ilo1]0bn.sex_r#c.Ilo = 1
     ( 2)  [ilo2]0bn.sex_r#c.Ilo - [ilo2]1.sex_r#c.Ilo = 0
     ( 3)  [ilo3]0bn.sex_r#c.Ilo - [ilo3]1.sex_r#c.Ilo = 0
     ( 4)  [ilo4]0bn.sex_r#c.Ilo - [ilo4]1.sex_r#c.Ilo = 0
     ( 5)  [ilo5]0bn.sex_r#c.Ilo - [ilo5]1.sex_r#c.Ilo = 0
     ( 6)  [ilo6]0bn.sex_r#c.Ilo - [ilo6]1.sex_r#c.Ilo = 0
     ( 7)  [/]var(e.Ilo)#0bn.sex_r - [/]var(e.Ilo)#1.sex_r = 0
     ( 8)  [ilo1]0bn.sex_r - [ilo1]1.sex_r = 0
     ( 9)  [ilo2]0bn.sex_r - [ilo2]1.sex_r = 0
     (10)  [ilo3]0bn.sex_r - [ilo3]1.sex_r = 0
     (11)  [ilo4]0bn.sex_r - [ilo4]1.sex_r = 0
     (12)  [ilo5]0bn.sex_r - [ilo5]1.sex_r = 0
     (13)  [ilo6]0bn.sex_r - [ilo6]1.sex_r = 0
     (14)  [ilo1]1.sex_r#c.Ilo = 1
    
    Group: Male                                              Number of obs = 1,448
    
    -----------------------------------------------------------------------------------
                      |                 OIM
                      | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
    ------------------+----------------------------------------------------------------
    Structural        |
      Ilo             |
           pre_post_r |   1.031074   .0642268    16.05   0.000     .9051915    1.156956
    ------------------+----------------------------------------------------------------
    Measurement       |
      ilo1            |
                  Ilo |          1  (constrained)
                _cons |   4.102239   .0303745   135.06   0.000     4.042706    4.161772
      ----------------+----------------------------------------------------------------
      ilo2            |
                  Ilo |    .735468   .0174669    42.11   0.000     .7012335    .7697025
                _cons |    4.59934   .0268293   171.43   0.000     4.546756    4.651925
      ----------------+----------------------------------------------------------------
      ilo3            |
                  Ilo |   .9008603   .0160247    56.22   0.000     .8694524    .9322681
                _cons |   4.415707   .0273912   161.21   0.000     4.362021    4.469393
      ----------------+----------------------------------------------------------------
      ilo4            |
                  Ilo |   1.071535   .0189074    56.67   0.000     1.034478    1.108593
                _cons |   4.136944   .0307681   134.46   0.000      4.07664    4.197248
      ----------------+----------------------------------------------------------------
      ilo5            |
                  Ilo |   1.150142   .0192086    59.88   0.000     1.112494     1.18779
                _cons |   3.737108   .0318121   117.47   0.000     3.674757    3.799459
      ----------------+----------------------------------------------------------------
      ilo6            |
                  Ilo |   1.052952   .0181181    58.12   0.000     1.017441    1.088462
                _cons |   3.992495   .0296573   134.62   0.000     3.934368    4.050622
    ------------------+----------------------------------------------------------------
           var(e.ilo1)|    .759053    .033199                      .6966951    .8269924
           var(e.ilo2)|   1.018051   .0406341                      .9414452    1.100891
           var(e.ilo3)|   .5764516   .0254992                      .5285792    .6286596
           var(e.ilo4)|   .5715825   .0268171                      .5213662    .6266354
           var(e.ilo5)|   .4250043   .0230977                      .3820614    .4727739
           var(e.ilo6)|   .4385163   .0218616                      .3976951    .4835275
            var(e.Ilo)|   1.318692   .0500662                      1.224126    1.420563
    ------------------+----------------------------------------------------------------
    cov(e.ilo1,e.ilo2)|   .1849651    .027043     6.84   0.000     .1319617    .2379684
    cov(e.ilo1,e.ilo3)|   .1135263   .0215603     5.27   0.000     .0712689    .1557838
    cov(e.ilo2,e.ilo3)|   .2892495   .0248841    11.62   0.000     .2404776    .3380215
    -----------------------------------------------------------------------------------
    
    Group: Female                                            Number of obs = 1,529
    
    -----------------------------------------------------------------------------------
                      |                 OIM
                      | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
    ------------------+----------------------------------------------------------------
    Structural        |
      Ilo             |
           pre_post_r |   .4492335   .0604778     7.43   0.000     .3306992    .5677677
    ------------------+----------------------------------------------------------------
    Measurement       |
      ilo1            |
                  Ilo |          1  (constrained)
                _cons |   4.102239   .0303745   135.06   0.000     4.042706    4.161772
      ----------------+----------------------------------------------------------------
      ilo2            |
                  Ilo |    .735468   .0174669    42.11   0.000     .7012335    .7697025
                _cons |    4.59934   .0268293   171.43   0.000     4.546756    4.651925
      ----------------+----------------------------------------------------------------
      ilo3            |
                  Ilo |   .9008603   .0160247    56.22   0.000     .8694524    .9322681
                _cons |   4.415707   .0273912   161.21   0.000     4.362021    4.469393
      ----------------+----------------------------------------------------------------
      ilo4            |
                  Ilo |   1.071535   .0189074    56.67   0.000     1.034478    1.108593
                _cons |   4.136944   .0307681   134.46   0.000      4.07664    4.197248
      ----------------+----------------------------------------------------------------
      ilo5            |
                  Ilo |   1.150142   .0192086    59.88   0.000     1.112494     1.18779
                _cons |   3.737108   .0318121   117.47   0.000     3.674757    3.799459
      ----------------+----------------------------------------------------------------
      ilo6            |
                  Ilo |   1.052952   .0181181    58.12   0.000     1.017441    1.088462
                _cons |   3.992495   .0296573   134.62   0.000     3.934368    4.050622
    ------------------+----------------------------------------------------------------
           var(e.ilo1)|   .7504911   .0314915                      .6912388    .8148224
           var(e.ilo2)|   1.068583   .0410555                      .9910704    1.152157
           var(e.ilo3)|   .6594714   .0275581                      .6076112    .7157578
           var(e.ilo4)|   .4853136   .0231607                      .4419777    .5328986
           var(e.ilo5)|   .3990046   .0214138                      .3591662    .4432619
           var(e.ilo6)|   .4357954   .0209641                       .396584    .4788836
            var(e.Ilo)|   1.318692   .0500662                      1.224126    1.420563
    ------------------+----------------------------------------------------------------
    cov(e.ilo1,e.ilo2)|   .1241603   .0261024     4.76   0.000     .0730005    .1753201
    cov(e.ilo1,e.ilo3)|   .1067533   .0216582     4.93   0.000     .0643041    .1492026
    cov(e.ilo2,e.ilo3)|   .4318641   .0272252    15.86   0.000     .3785036    .4852245
    -----------------------------------------------------------------------------------
    LR test of model vs. saturated: chi2(34) = 422.95              Prob > chi2 = 0.0000
    When testing for group invariance, the Wald test shows that the coefficient of the path pre_post_r -> Ilo is significant, indicating that the effect of IV on DV is different for the different levels of moderator (0 or 1):

    Code:
    Tests for group invariance of parameters
    
    -----------------------------------------------------------------------------------
                      |            Wald test                       Score test
                      |      chi2         df    P>chi2       chi2          df    P>chi2
    ------------------+----------------------------------------------------------------
    Structural        |
      Ilo             |
           pre_post_r |    54.418          1    0.0000          .           .         .
    ------------------+----------------------------------------------------------------
    Why is there such a contradictory result? Is there any constraint that I should add or release in the group analysis? Or should I use categorical IV and moderator in SEM for testing moderation?
    Thank you very much.

  • #2
    Dear all,

    Is my post not detailed enough? It seems that my post(s) (including my last one) is not that effective and they receive no responses so far. As I am only a novice in Statalist, may anyone who can point out in what way I should amend my posts so that I may receive feedback from other users?
    Thank you so much.

    Comment


    • #3
      Notice how all those variances and covariances differ across groups. Also notice how the DF differ between the two approaches. I think your ginvariant option is wrong. I think you want to make everything ginvariant EXCEPT scoef. Example 23 in the sem manual shows ways to do this.

      At least, I think that is what you should do if you want the two approaches to produce identical results. But in practice you usually just want the measurement coefficients to be the same across groups, I.e. you want something like what you did.

      in other words, you are not running equivalent models here. I think you can make them equivalent. But, the first model isn’t necessarily what you want. It imposes a bunch of equality constraints across groups that may not be necessary or desirable.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      StataNow Version: 19.5 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Originally posted by Kwok-wing Sum View Post
        pre_post_r: categorical IV (0 or 1)
        This implies that you have repeated measurements over time (two time points) on each of your male and female whatevers.

        If so, is there a reason why you didn't set up your model to accommodates that study design, e.g., like a latent growth curve SEM?

        Or else use gsem with random effects.

        Comment


        • #5
          Thank you Prof. Williams and Dr. Coveney for your replies.

          The reason why I have added error covariances between certain items (ilo1, ilo2, ilo3) is that previously I have run CFA for the whole sample and multigroup CFA for pre- and post- groups (to test for measurement invariance), and the modification indices show that the model fit would be much better with these error covariances.
          As Prof. Williams said, I have tried to make the models more equivalent (see below). But still the coefficient of the path "pre_post_r -> Ilo" is significant. The result is still different from the SEM with interaction term.
          In this case, may I simply use the SEM model with the interaction term? Is the model correct enough?

          Code:
          sem (Ilo ->  ilo1 ilo2 ilo3 ilo4 ilo5 ilo6 ) (pre_post_r -> Ilo), group(sex_r) ginvariant(scons mcoef mcons serrvar merrvar smerrcov meanex covex) cov( e.ilo1*e.ilo2 e.ilo1*e.ilo3 e.ilo2*e.ilo3)
          Code:
          Structural equation model                             Number of obs    = 2,977
          Grouping variable: sex_r                              Number of groups =     2
          Estimation method: ml
          
          Log likelihood = -26277.853
          
          Group: Male                                              Number of obs = 1,448
          
          -----------------------------------------------------------------------------------
                            |                 OIM
                            | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
          ------------------+----------------------------------------------------------------
          Structural        |
            Ilo             |
                 pre_post_r |     1.0322   .0642604    16.06   0.000     .9062523    1.158148
          ------------------+----------------------------------------------------------------
          Measurement       |
            ilo1            |
                        Ilo |          1  (constrained)
                      _cons |   4.101196   .0303532   135.12   0.000     4.041704    4.160687
            ----------------+----------------------------------------------------------------
            ilo2            |
                        Ilo |   .7341535   .0174991    41.95   0.000     .6998558    .7684512
                      _cons |   4.603395   .0267991   171.77   0.000      4.55087     4.65592
            ----------------+----------------------------------------------------------------
            ilo3            |
                        Ilo |   .8972643   .0160334    55.96   0.000     .8658395    .9286891
                      _cons |   4.419908   .0272956   161.93   0.000     4.366409    4.473406
            ----------------+----------------------------------------------------------------
            ilo4            |
                        Ilo |   1.068358   .0188077    56.80   0.000     1.031496     1.10522
                      _cons |   4.145609   .0305574   135.67   0.000     4.085717      4.2055
            ----------------+----------------------------------------------------------------
            ilo5            |
                        Ilo |   1.148001   .0191365    59.99   0.000     1.110494    1.185507
                      _cons |   3.738373   .0317925   117.59   0.000     3.676061    3.800686
            ----------------+----------------------------------------------------------------
            ilo6            |
                        Ilo |   1.051796    .018041    58.30   0.000     1.016436    1.087155
                      _cons |   3.992465   .0296579   134.62   0.000     3.934337    4.050594
          ------------------+----------------------------------------------------------------
                 var(e.ilo1)|   .7534025   .0229478                      .7097417     .799749
                 var(e.ilo2)|   1.043402   .0288968                      .9882747    1.101604
                 var(e.ilo3)|   .6190326   .0188627                      .5831447    .6571292
                 var(e.ilo4)|   .5276721   .0175686                      .4943377    .5632543
                 var(e.ilo5)|    .413576   .0160233                      .3833336    .4462042
                 var(e.ilo6)|   .4359774   .0153031                      .4069923    .4670266
                  var(e.Ilo)|    1.32266   .0501173                      1.227991    1.424628
          ------------------+----------------------------------------------------------------
          cov(e.ilo1,e.ilo2)|   .1528803   .0188259     8.12   0.000     .1159822    .1897783
          cov(e.ilo1,e.ilo3)|   .1094717   .0153727     7.12   0.000     .0793418    .1396016
          cov(e.ilo2,e.ilo3)|    .362107   .0184853    19.59   0.000     .3258764    .3983376
          -----------------------------------------------------------------------------------
          
          Group: Female                                            Number of obs = 1,529
          
          -----------------------------------------------------------------------------------
                            |                 OIM
                            | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
          ------------------+----------------------------------------------------------------
          Structural        |
            Ilo             |
                 pre_post_r |   .4496628   .0606062     7.42   0.000     .3308769    .5684487
          ------------------+----------------------------------------------------------------
          Measurement       |
            ilo1            |
                        Ilo |          1  (constrained)
                      _cons |   4.101196   .0303532   135.12   0.000     4.041704    4.160687
            ----------------+----------------------------------------------------------------
            ilo2            |
                        Ilo |   .7341535   .0174991    41.95   0.000     .6998558    .7684512
                      _cons |   4.603395   .0267991   171.77   0.000      4.55087     4.65592
            ----------------+----------------------------------------------------------------
            ilo3            |
                        Ilo |   .8972643   .0160334    55.96   0.000     .8658395    .9286891
                      _cons |   4.419908   .0272956   161.93   0.000     4.366409    4.473406
            ----------------+----------------------------------------------------------------
            ilo4            |
                        Ilo |   1.068358   .0188077    56.80   0.000     1.031496     1.10522
                      _cons |   4.145609   .0305574   135.67   0.000     4.085717      4.2055
            ----------------+----------------------------------------------------------------
            ilo5            |
                        Ilo |   1.148001   .0191365    59.99   0.000     1.110494    1.185507
                      _cons |   3.738373   .0317925   117.59   0.000     3.676061    3.800686
            ----------------+----------------------------------------------------------------
            ilo6            |
                        Ilo |   1.051796    .018041    58.30   0.000     1.016436    1.087155
                      _cons |   3.992465   .0296579   134.62   0.000     3.934337    4.050594
          ------------------+----------------------------------------------------------------
                 var(e.ilo1)|   .7534025   .0229478                      .7097417     .799749
                 var(e.ilo2)|   1.043402   .0288968                      .9882747    1.101604
                 var(e.ilo3)|   .6190326   .0188627                      .5831447    .6571292
                 var(e.ilo4)|   .5276721   .0175686                      .4943377    .5632543
                 var(e.ilo5)|    .413576   .0160233                      .3833336    .4462042
                 var(e.ilo6)|   .4359774   .0153031                      .4069923    .4670266
                  var(e.Ilo)|    1.32266   .0501173                      1.227991    1.424628
          ------------------+----------------------------------------------------------------
          cov(e.ilo1,e.ilo2)|   .1528803   .0188259     8.12   0.000     .1159822    .1897783
          cov(e.ilo1,e.ilo3)|   .1094717   .0153727     7.12   0.000     .0793418    .1396016
          cov(e.ilo2,e.ilo3)|    .362107   .0184853    19.59   0.000     .3258764    .3983376
          -----------------------------------------------------------------------------------
          LR test of model vs. saturated: chi2(43) = 458.64              Prob > chi2 = 0.0000
          
          Tests for group invariance of parameters
          
          -----------------------------------------------------------------------------------
                            |            Wald test                       Score test
                            |      chi2         df    P>chi2       chi2          df    P>chi2
          ------------------+----------------------------------------------------------------
          Structural        |
            Ilo             |
                 pre_post_r |    54.419          1    0.0000          .           .         .
          I considered Dr. Coveney's advice of running a latent growth curve SEM before, but it seems that the way that it treats the intercept and slope of the growth curve is rather complicated. Also, I have only 2 time points, which I am not sure if it can be regarded as a "growth" model.
          May Dr. Coveney suggest how I may run it?
          Besides, what difference would it make if I run the above model with gsem? Any changes that I should make in the above Stata command?

          Thank you very much again.
          Last edited by Kwok-wing Sum; 16 Oct 2023, 19:53.

          Comment


          • #6
            I have a feeling your last model is still a bit off. Note that the parameters are slightly different from your original interaction model. What happens if you drop scons from the ginvariant option? It seems the original interaction model allowed the structural intercepts to differ by sex, but the last model constrains them to be the same.

            " In this case, may I simply use the SEM model with the interaction term? Is the model correct enough?"

            Well, that model certainly doesn't fit perfectly. I think you'd still need to explore whether that is the best you can do, e.g. should you allow more differences across groups?

            I think my preferred model would be your original two group model, with ginvariant left off completely, which would default to ginvariant(mcoef mcons). When comparing groups you usually want the coefficients of the measurement model to be the same (but you should test if this is actually true). You can test other equalities across groups if you want to but imposing them may not gain you that much (besides a more parsimonious model).

            I haven't done models like this in a while so I may be missing something. But, try what I suggest above (especially dropping scons from ginvariant) and see what happens.
            -------------------------------------------
            Richard Williams, Notre Dame Dept of Sociology
            StataNow Version: 19.5 MP (2 processor)

            EMAIL: [email protected]
            WWW: https://www3.nd.edu/~rwilliam

            Comment


            • #7
              You might add the showg option to your sem commands. It will show the estimated means for the latent variable and will make it easy to see what the equality constraints are.

              -------------------------------------------
              Richard Williams, Notre Dame Dept of Sociology
              StataNow Version: 19.5 MP (2 processor)

              EMAIL: [email protected]
              WWW: https://www3.nd.edu/~rwilliam

              Comment


              • #8
                Thank you Prof. Williams again for your reply.
                As advised, I have run the two group models by dropping scons from ginvariant:
                Code:
                sem (Ilo ->  ilo1 ilo2 ilo3 ilo4 ilo5 ilo6 ) (pre_post_r -> Ilo), group(sex_r) ginvariant(mcoef mcons serrvar merrvar smerrcov meanex covex) cov( e.ilo1*e.ilo2 e.ilo1*e.ilo3 e.ilo2*e.ilo3)
                Below are the results. But it seems that the path "pre_post_r -> Ilo" is still significant.
                I am thinking about whether it is the properties of the interaction term (e.g., its error covariance) in my original interaction model which makes it different from the two group models. If this is the case, should I take the results of the two group models as correct, and interpret that there is no gender difference in the effect of "pre_post_r" on the latent variable (though it is contradictory to the interaction model by now)?

                Thank you so much again.

                Code:
                Structural equation model                             Number of obs    = 2,977
                Grouping variable: sex_r                              Number of groups =     2
                Estimation method: ml
                
                Log likelihood = -26277.853
                
                Group: Male                                              Number of obs = 1,448
                
                -----------------------------------------------------------------------------------
                                  |                 OIM
                                  | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
                ------------------+----------------------------------------------------------------
                Structural        |
                  Ilo             |
                       pre_post_r |     1.0322   .0642604    16.06   0.000     .9062523    1.158148
                ------------------+----------------------------------------------------------------
                Measurement       |
                  ilo1            |
                              Ilo |          1  (constrained)
                            _cons |   4.101196   .0303532   135.12   0.000     4.041704    4.160687
                  ----------------+----------------------------------------------------------------
                  ilo2            |
                              Ilo |   .7341535   .0174991    41.95   0.000     .6998558    .7684512
                            _cons |   4.603395   .0267991   171.77   0.000      4.55087     4.65592
                  ----------------+----------------------------------------------------------------
                  ilo3            |
                              Ilo |   .8972643   .0160334    55.96   0.000     .8658395    .9286891
                            _cons |   4.419908   .0272956   161.93   0.000     4.366409    4.473406
                  ----------------+----------------------------------------------------------------
                  ilo4            |
                              Ilo |   1.068358   .0188077    56.80   0.000     1.031496     1.10522
                            _cons |   4.145609   .0305574   135.67   0.000     4.085717      4.2055
                  ----------------+----------------------------------------------------------------
                  ilo5            |
                              Ilo |   1.148001   .0191365    59.99   0.000     1.110494    1.185507
                            _cons |   3.738373   .0317925   117.59   0.000     3.676061    3.800686
                  ----------------+----------------------------------------------------------------
                  ilo6            |
                              Ilo |   1.051796    .018041    58.30   0.000     1.016436    1.087155
                            _cons |   3.992465   .0296579   134.62   0.000     3.934337    4.050594
                ------------------+----------------------------------------------------------------
                       var(e.ilo1)|   .7534025   .0229478                      .7097417     .799749
                       var(e.ilo2)|   1.043402   .0288968                      .9882747    1.101604
                       var(e.ilo3)|   .6190326   .0188627                      .5831447    .6571292
                       var(e.ilo4)|   .5276721   .0175686                      .4943377    .5632543
                       var(e.ilo5)|    .413576   .0160233                      .3833336    .4462042
                       var(e.ilo6)|   .4359774   .0153031                      .4069923    .4670266
                        var(e.Ilo)|    1.32266   .0501173                      1.227991    1.424628
                ------------------+----------------------------------------------------------------
                cov(e.ilo1,e.ilo2)|   .1528803   .0188259     8.12   0.000     .1159822    .1897783
                cov(e.ilo1,e.ilo3)|   .1094717   .0153727     7.12   0.000     .0793418    .1396016
                cov(e.ilo2,e.ilo3)|    .362107   .0184853    19.59   0.000     .3258764    .3983376
                -----------------------------------------------------------------------------------
                
                Group: Female                                            Number of obs = 1,529
                
                -----------------------------------------------------------------------------------
                                  |                 OIM
                                  | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
                ------------------+----------------------------------------------------------------
                Structural        |
                  Ilo             |
                       pre_post_r |   .4496628   .0606062     7.42   0.000     .3308769    .5684487
                ------------------+----------------------------------------------------------------
                Measurement       |
                  ilo1            |
                              Ilo |          1  (constrained)
                            _cons |   4.101196   .0303532   135.12   0.000     4.041704    4.160687
                  ----------------+----------------------------------------------------------------
                  ilo2            |
                              Ilo |   .7341535   .0174991    41.95   0.000     .6998558    .7684512
                            _cons |   4.603395   .0267991   171.77   0.000      4.55087     4.65592
                  ----------------+----------------------------------------------------------------
                  ilo3            |
                              Ilo |   .8972643   .0160334    55.96   0.000     .8658395    .9286891
                            _cons |   4.419908   .0272956   161.93   0.000     4.366409    4.473406
                  ----------------+----------------------------------------------------------------
                  ilo4            |
                              Ilo |   1.068358   .0188077    56.80   0.000     1.031496     1.10522
                            _cons |   4.145609   .0305574   135.67   0.000     4.085717      4.2055
                  ----------------+----------------------------------------------------------------
                  ilo5            |
                              Ilo |   1.148001   .0191365    59.99   0.000     1.110494    1.185507
                            _cons |   3.738373   .0317925   117.59   0.000     3.676061    3.800686
                  ----------------+----------------------------------------------------------------
                  ilo6            |
                              Ilo |   1.051796    .018041    58.30   0.000     1.016436    1.087155
                            _cons |   3.992465   .0296579   134.62   0.000     3.934337    4.050594
                ------------------+----------------------------------------------------------------
                       var(e.ilo1)|   .7534025   .0229478                      .7097417     .799749
                       var(e.ilo2)|   1.043402   .0288968                      .9882747    1.101604
                       var(e.ilo3)|   .6190326   .0188627                      .5831447    .6571292
                       var(e.ilo4)|   .5276721   .0175686                      .4943377    .5632543
                       var(e.ilo5)|    .413576   .0160233                      .3833336    .4462042
                       var(e.ilo6)|   .4359774   .0153031                      .4069923    .4670266
                        var(e.Ilo)|    1.32266   .0501173                      1.227991    1.424628
                ------------------+----------------------------------------------------------------
                cov(e.ilo1,e.ilo2)|   .1528803   .0188259     8.12   0.000     .1159822    .1897783
                cov(e.ilo1,e.ilo3)|   .1094717   .0153727     7.12   0.000     .0793418    .1396016
                cov(e.ilo2,e.ilo3)|    .362107   .0184853    19.59   0.000     .3258764    .3983376
                -----------------------------------------------------------------------------------
                LR test of model vs. saturated: chi2(43) = 458.64              Prob > chi2 = 0.0000
                
                .
                Code:
                Tests for group invariance of parameters
                
                -----------------------------------------------------------------------------------
                                  |            Wald test                       Score test
                                  |      chi2         df    P>chi2       chi2          df    P>chi2
                ------------------+----------------------------------------------------------------
                Structural        |
                  Ilo             |
                       pre_post_r |    54.419          1    0.0000          .           .         .
                ------------------+----------------------------------------------------------------

                Comment


                • #9
                  Originally posted by Kwok-wing Sum View Post
                  I considered . . . a latent growth curve SEM before, but it seems that the way that it treats the intercept and slope of the growth curve is rather complicated. Also, I have only 2 time points, which I am not sure if it can be regarded as a "growth" model.
                  Yes, latent growth curve SEMs can get hard to fathom. With multiple indicator variables, you'd first form confirmatory factor analysis-like latent factors at each time point and then treat the intercept and slope latent factors like the second level of a two-level CFA. It's illustrated as Example 6.14 in Mplus's user's manual.

                  But with only two time points, it's liable to get dicey and you might be better off just to omit the captive-intermediate first-level CFA latent factors and load the indicators on the intercept and slope latent factors directly, applying the measurement-invariance constraints there. The approach is illustrated in the output below as the first model fit—it's at the "SEM (growth-curve like)" comment. (The stuff at the beginning is just to create a fictitious dataset for illustration. I've used only three indicator variables for brevity, but the approach will be the same with your six indicator variables.)

                  . . . how I may run it?
                  Besides, what difference would it make if I run the above model with gsem? Any changes that I should make in the above Stata command?
                  I illustrate a random-slope, within-and-between formulation using gsem below at the "-gsem- random-slope model, within-and-between formulation" comment. The model is slightly different from that of the latent growth curve formulation above in that it allows for intercepts for each of the indicator variables (growth curve formulations typically set them at zero for identification of the means of the slope and intercept latent factors); nevertheless, the results are essentially the same for the fixed effects of sex, time and sex × time interaction.

                  Below last I fit an analogous model using mixed, with the indicator variables included as another fixed effect. Again the results for the effects of interest and for the variances and covariance of intercept and random slope are essentially the same within estimation error, as are the residual variance estimates for the indicator variables. Principal estimates are tabulated below for ease of comparison. (SEM-GC is the growth curve-like formulation using sem, SEM-WB is the random slope, within-and-between formulation using gsem and MIXED is with mixed)

                  Main effects of sex (coefficient ± standard error)
                  SEM-GC 0.54 ± 0.03
                  SEM-WB 0.54 ± 0.05
                  MIXED 0.54 ± 0.05

                  Main effects of time
                  SEM-GC 0.51 ± 0.03
                  SEM-WB 0.51 ± 0.04 (avg.)
                  MIXED 0.51 ± 0.04

                  Sex × time interaction
                  SEM-GC 0.46 ± 0.06
                  SEM-WB 0.50 ± 0.06
                  MIXED 0.49 ± 0.06

                  Intercept Variance (coefficient only)
                  SEM-GC 1.6
                  SEM-WB 1.6
                  MIXED 1.6

                  Random Slope Variance
                  SEM-GC 1.9
                  SEM-WB 2.0
                  MIXED 1.9

                  Intercept*Slope Covariance
                  SEM-GC -0.76
                  SEM-WB -0.77
                  MIXED -0.75

                  Here is the output. The corresponding do-file and log file are attached.

                  .ÿ
                  .ÿversionÿ18.0

                  .ÿ
                  .ÿlogÿcloseÿ_all

                  .ÿlogÿusingÿ"GrowthÿCurve.smcl",ÿnomsgÿname(lo)

                  .ÿ
                  .ÿclearÿ*

                  .ÿ
                  .ÿ//ÿseedem
                  .ÿsetÿseedÿ960930312

                  .ÿ
                  .ÿquietlyÿdrawnormÿinterceptÿslope,ÿdoubleÿcorr(1ÿ-0.25ÿ\ÿ-0.25ÿ1)ÿn(3000)

                  .ÿgenerateÿbyteÿsexÿ=ÿmod(_n,ÿ2)

                  .ÿ
                  .ÿtempnameÿCorr

                  .ÿmatrixÿdefineÿ`Corr'ÿ=ÿJ(3,ÿ3,ÿ0.5)ÿ+ÿI(3)ÿ*ÿ0.5

                  .ÿforvaluesÿtimÿ=ÿ0/1ÿ{
                  ÿÿ2.ÿÿÿÿÿquietlyÿdrawnormÿe1`tim'ÿe2`tim'ÿe3`tim',ÿdoubleÿcorr(`Corr')
                  ÿÿ3.ÿÿÿÿÿforvaluesÿiÿ=ÿ1/3ÿ{
                  ÿÿ4.ÿÿÿÿÿÿÿÿÿgenerateÿdoubleÿout`i'`tim'ÿ=ÿ///
                  >ÿÿÿÿÿÿÿÿÿÿÿÿÿ0ÿ+ÿinterceptÿ+ÿ///
                  >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿsexÿ/ÿ2ÿ+ÿ///
                  >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ`tim'ÿ*ÿ(1/2ÿ+ÿslope)ÿ+ÿ///
                  >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿsexÿ*ÿ`tim'ÿ/ÿ2ÿ+ÿ///
                  >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿe`i'`tim'
                  ÿÿ5.ÿÿÿÿÿ}
                  ÿÿ6.ÿ}

                  .ÿ
                  .ÿ*
                  .ÿ*ÿSEMÿ(growth-curveÿlike)
                  .ÿ*
                  .ÿconstraintÿdefineÿÿ1ÿ[out10]Interceptÿ=ÿ1

                  .ÿconstraintÿdefineÿÿ2ÿ[out11]Interceptÿ=ÿ1

                  .ÿconstraintÿdefineÿÿ3ÿ[out11]Slopeÿ=ÿ1

                  .ÿ
                  .ÿconstraintÿdefineÿÿ4ÿ[out20]Interceptÿ=ÿ[out21]Intercept

                  .ÿconstraintÿdefineÿÿ5ÿ[out30]Interceptÿ=ÿ[out31]Intercept

                  .ÿconstraintÿdefineÿÿ6ÿ[out21]Interceptÿ=ÿ[out21]Slope

                  .ÿconstraintÿdefineÿÿ7ÿ[out31]Interceptÿ=ÿ[out31]Slope

                  .ÿ
                  .ÿconstraintÿdefineÿÿ8ÿ[/]var(e.out10)ÿ=ÿ[/]var(e.out11)

                  .ÿconstraintÿdefineÿÿ9ÿ[/]var(e.out20)ÿ=ÿ[/]var(e.out21)

                  .ÿconstraintÿdefineÿ10ÿ[/]var(e.out30)ÿ=ÿ[/]var(e.out31)

                  .ÿ
                  .ÿgenerateÿbyteÿtimÿ=ÿ!sex

                  .ÿ
                  .ÿconstraintÿdefineÿ11ÿ[Intercept]timÿ=ÿ0

                  .ÿ
                  .ÿsemÿ///
                  >ÿÿÿÿÿÿÿÿÿ(out*ÿ<-ÿIntercept,ÿnoconstant)ÿ///
                  >ÿÿÿÿÿÿÿÿÿ(out?1ÿ<-ÿSlope,ÿnoconstant)ÿ///
                  >ÿÿÿÿÿÿÿÿÿ(InterceptÿSlopeÿ<-ÿtimÿsex,ÿnoconstant),ÿ///
                  >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿconstraints(1/11)ÿ///
                  >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿcovariance((e.Intercept*e.Slope))ÿ///
                  >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿnocnsreportÿnodescribeÿnolog

                  StructuralÿequationÿmodelÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿ=ÿ3,000
                  Estimationÿmethod:ÿml

                  Logÿlikelihoodÿ=ÿ-30753.295

                  -----------------------------------------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿOIM
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿCoefficientÿÿstd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
                  ------------------------+----------------------------------------------------------------
                  Structuralÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿInterceptÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿsexÿ|ÿÿÿ.5429784ÿÿÿ.0341708ÿÿÿÿ15.89ÿÿÿ0.000ÿÿÿÿÿÿ.476005ÿÿÿÿ.6099519
                  ÿÿ----------------------+----------------------------------------------------------------
                  ÿÿSlopeÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿtimÿ|ÿÿÿ.5102283ÿÿÿ.0346671ÿÿÿÿ14.72ÿÿÿ0.000ÿÿÿÿÿ.4422821ÿÿÿÿ.5781746
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿsexÿ|ÿÿÿ1.003576ÿÿÿ.0393589ÿÿÿÿ25.50ÿÿÿ0.000ÿÿÿÿÿ.9264335ÿÿÿÿ1.080718
                  ------------------------+----------------------------------------------------------------
                  Measurementÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿout10ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿInterceptÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿ(constrained)
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿÿÿÿÿÿÿÿÿ0ÿÿ(constrained)
                  ÿÿ----------------------+----------------------------------------------------------------
                  ÿÿout20ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿInterceptÿ|ÿÿÿ.9973584ÿÿÿ.0088294ÿÿÿ112.96ÿÿÿ0.000ÿÿÿÿÿ.9800532ÿÿÿÿ1.014664
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿÿÿÿÿÿÿÿÿ0ÿÿ(constrained)
                  ÿÿ----------------------+----------------------------------------------------------------
                  ÿÿout30ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿInterceptÿ|ÿÿÿ.9946205ÿÿÿ.0087487ÿÿÿ113.69ÿÿÿ0.000ÿÿÿÿÿ.9774734ÿÿÿÿ1.011768
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿÿÿÿÿÿÿÿÿ0ÿÿ(constrained)
                  ÿÿ----------------------+----------------------------------------------------------------
                  ÿÿout11ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿInterceptÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿ(constrained)
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿSlopeÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿ(constrained)
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿÿÿÿÿÿÿÿÿ0ÿÿ(constrained)
                  ÿÿ----------------------+----------------------------------------------------------------
                  ÿÿout21ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿInterceptÿ|ÿÿÿ.9973584ÿÿÿ.0088294ÿÿÿ112.96ÿÿÿ0.000ÿÿÿÿÿ.9800532ÿÿÿÿ1.014664
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿSlopeÿ|ÿÿÿ.9973584ÿÿÿ.0088294ÿÿÿ112.96ÿÿÿ0.000ÿÿÿÿÿ.9800532ÿÿÿÿ1.014664
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿÿÿÿÿÿÿÿÿ0ÿÿ(constrained)
                  ÿÿ----------------------+----------------------------------------------------------------
                  ÿÿout31ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿInterceptÿ|ÿÿÿ.9946205ÿÿÿ.0087487ÿÿÿ113.69ÿÿÿ0.000ÿÿÿÿÿ.9774734ÿÿÿÿ1.011768
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿSlopeÿ|ÿÿÿ.9946205ÿÿÿ.0087487ÿÿÿ113.69ÿÿÿ0.000ÿÿÿÿÿ.9774734ÿÿÿÿ1.011768
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿÿÿÿÿÿÿÿÿ0ÿÿ(constrained)
                  ------------------------+----------------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿÿÿÿvar(e.out10)|ÿÿÿ.4961152ÿÿÿ.0139092ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.4695891ÿÿÿÿ.5241397
                  ÿÿÿÿÿÿÿÿÿÿÿÿvar(e.out20)|ÿÿÿ.5169276ÿÿÿ.0141649ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.4898974ÿÿÿÿ.5454493
                  ÿÿÿÿÿÿÿÿÿÿÿÿvar(e.out30)|ÿÿÿÿ.494592ÿÿÿ.0138505ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.468177ÿÿÿÿ.5224974
                  ÿÿÿÿÿÿÿÿÿÿÿÿvar(e.out11)|ÿÿÿ.4961152ÿÿÿ.0139092ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.4695891ÿÿÿÿ.5241397
                  ÿÿÿÿÿÿÿÿÿÿÿÿvar(e.out21)|ÿÿÿ.5169276ÿÿÿ.0141649ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.4898974ÿÿÿÿ.5454493
                  ÿÿÿÿÿÿÿÿÿÿÿÿvar(e.out31)|ÿÿÿÿ.494592ÿÿÿ.0138505ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.468177ÿÿÿÿ.5224974
                  ÿÿÿÿÿÿÿÿvar(e.Intercept)|ÿÿÿ1.572194ÿÿÿ.0477378ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.481359ÿÿÿÿ1.668598
                  ÿÿÿÿÿÿÿÿÿÿÿÿvar(e.Slope)|ÿÿÿ1.949152ÿÿÿ.0624624ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.830493ÿÿÿÿ2.075502
                  ------------------------+----------------------------------------------------------------
                  cov(e.Intercept,e.Slope)|ÿÿ-.7580683ÿÿÿ.0409676ÿÿÿ-18.50ÿÿÿ0.000ÿÿÿÿ-.8383634ÿÿÿ-.6777733
                  -----------------------------------------------------------------------------------------

                  .ÿ//ÿsexÿ×ÿtimÿinteraction
                  .ÿlincomÿ[Slope]sexÿ-ÿ[Intercept]sex

                  ÿ(ÿ1)ÿÿ-ÿ[Intercept]sexÿ+ÿ[Slope]sexÿ=ÿ0

                  ------------------------------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
                  -------------+----------------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿ(1)ÿ|ÿÿÿ.4605971ÿÿÿ.0626489ÿÿÿÿÿ7.35ÿÿÿ0.000ÿÿÿÿÿ.3378075ÿÿÿÿ.5833866
                  ------------------------------------------------------------------------------

                  .ÿ
                  .ÿ*
                  .ÿ*ÿ-gsem-ÿrandom-slopeÿmodel,ÿwithin-and-betweenÿformulation
                  .ÿ*
                  .ÿkeepÿsexÿout*

                  .ÿgenerateÿintÿpidÿ=ÿ_n

                  .ÿquietlyÿreshapeÿlongÿout1ÿout2ÿout3,ÿi(pid)ÿj(tim)

                  .ÿ
                  .ÿgsemÿ///
                  >ÿÿÿÿÿÿÿÿÿ(out?ÿ<-ÿi.timÿM0[pid]ÿ1.tim#M1[pid])ÿ///
                  >ÿÿÿÿÿÿÿÿÿ(M0[pid]ÿM1[pid]ÿ<-ÿi.sex),ÿ///
                  >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿcovariance(e.M0[pid]*e.M1[pid])ÿ///
                  >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿnocnsreportÿnodvheaderÿdifficultÿnolog

                  GeneralizedÿstructuralÿequationÿmodelÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿ=ÿ6,000
                  Logÿlikelihoodÿ=ÿ-26397.1

                  ------------------------------------------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
                  -------------------------+----------------------------------------------------------------
                  out1ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.timÿ|ÿÿÿ.5105775ÿÿÿÿ.042022ÿÿÿÿ12.15ÿÿÿ0.000ÿÿÿÿÿ.4282159ÿÿÿÿ.5929392
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿM0[pid]ÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿ(constrained)
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿtim#M1[pid]ÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿ(constrained)
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿ-.0118826ÿÿÿ.0357285ÿÿÿÿ-0.33ÿÿÿ0.739ÿÿÿÿ-.0819093ÿÿÿÿÿ.058144
                  -------------------------+----------------------------------------------------------------
                  out2ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.timÿ|ÿÿÿ.5121864ÿÿÿ.0417436ÿÿÿÿ12.27ÿÿÿ0.000ÿÿÿÿÿ.4303704ÿÿÿÿ.5940024
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿM0[pid]ÿ|ÿÿÿ.9926379ÿÿÿ.0112807ÿÿÿÿ87.99ÿÿÿ0.000ÿÿÿÿÿ.9705282ÿÿÿÿ1.014748
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿtim#M1[pid]ÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿ|ÿÿÿ.9850132ÿÿÿ.0149378ÿÿÿÿ65.94ÿÿÿ0.000ÿÿÿÿÿ.9557358ÿÿÿÿ1.014291
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿÿ.0066585ÿÿÿ.0356315ÿÿÿÿÿ0.19ÿÿÿ0.852ÿÿÿÿ-.0631779ÿÿÿÿÿ.076495
                  -------------------------+----------------------------------------------------------------
                  out3ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.timÿ|ÿÿÿ.5042191ÿÿÿ.0415053ÿÿÿÿ12.15ÿÿÿ0.000ÿÿÿÿÿ.4228702ÿÿÿÿ.5855679
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿM0[pid]ÿ|ÿÿÿ.9923839ÿÿÿ.0111816ÿÿÿÿ88.75ÿÿÿ0.000ÿÿÿÿÿ.9704684ÿÿÿÿ1.014299
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿtim#M1[pid]ÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿ|ÿÿÿ.9837346ÿÿÿ.0148352ÿÿÿÿ66.31ÿÿÿ0.000ÿÿÿÿÿ.9546582ÿÿÿÿ1.012811
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿÿÿ.005367ÿÿÿ.0355074ÿÿÿÿÿ0.15ÿÿÿ0.880ÿÿÿÿ-.0642262ÿÿÿÿ.0749601
                  -------------------------+----------------------------------------------------------------
                  M0[pid]ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.sexÿ|ÿÿÿÿ.544308ÿÿÿ.0484154ÿÿÿÿ11.24ÿÿÿ0.000ÿÿÿÿÿ.4494156ÿÿÿÿ.6392004
                  -------------------------+----------------------------------------------------------------
                  M1[pid]ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.sexÿ|ÿÿÿ.4970093ÿÿÿ.0557831ÿÿÿÿÿ8.91ÿÿÿ0.000ÿÿÿÿÿ.3876764ÿÿÿÿ.6063422
                  -------------------------+----------------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿÿÿvar(e.M0[pid])|ÿÿÿ1.579528ÿÿÿ.0495803ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.485282ÿÿÿÿ1.679755
                  ÿÿÿÿÿÿÿÿÿÿÿvar(e.M1[pid])|ÿÿÿ1.979694ÿÿÿ.0690054ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.848962ÿÿÿÿ2.119669
                  -------------------------+----------------------------------------------------------------
                  ÿcov(e.M0[pid],e.M1[pid])|ÿÿ-.7658207ÿÿÿ.0417177ÿÿÿ-18.36ÿÿÿ0.000ÿÿÿÿ-.8475859ÿÿÿ-.6840554
                  -------------------------+----------------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿvar(e.out1)|ÿÿÿ.4920182ÿÿÿ.0142119ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.4649372ÿÿÿÿ.5206765
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿvar(e.out2)|ÿÿÿ.5193569ÿÿÿ.0143494ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.4919804ÿÿÿÿ.5482567
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿvar(e.out3)|ÿÿÿÿ.495891ÿÿÿÿ.014079ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.4690503ÿÿÿÿ.5242675
                  ------------------------------------------------------------------------------------------

                  .ÿ//ÿAverageÿtimÿeffectÿ(ignoringÿindicatorÿconstants)
                  .ÿlincomÿ([out1]1.timÿ+ÿ[out2]1.timÿ+ÿ[out3]1.tim)ÿ/ÿ3

                  ÿ(ÿ1)ÿÿ.3333333*[out1]1.timÿ+ÿ.3333333*[out2]1.timÿ+ÿ.3333333*[out3]1.timÿ=ÿ0

                  ------------------------------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
                  -------------+----------------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿ(1)ÿ|ÿÿÿ.5089943ÿÿÿ.0389318ÿÿÿÿ13.07ÿÿÿ0.000ÿÿÿÿÿ.4326895ÿÿÿÿ.5852992
                  ------------------------------------------------------------------------------

                  .ÿ
                  .ÿ*
                  .ÿ*ÿ-mixed-
                  .ÿ*
                  .ÿquietlyÿreshapeÿlongÿout,ÿi(pidÿtim)ÿj(ind)

                  .ÿmixedÿoutÿi.sex##i.timÿi.indÿ||ÿpid:ÿtim,ÿcovariance(unstructured)ÿ///
                  >ÿÿÿÿÿÿÿÿÿresiduals(independent,ÿby(ind))ÿnolrtestÿnolog

                  Mixed-effectsÿMLÿregressionÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿ=ÿÿ18,000
                  Groupÿvariable:ÿpidÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿgroupsÿ=ÿÿÿ3,000
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿObsÿperÿgroup:
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿminÿ=ÿÿÿÿÿÿÿ6
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿavgÿ=ÿÿÿÿÿ6.0
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿmaxÿ=ÿÿÿÿÿÿÿ6
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWaldÿchi2(5)ÿÿÿÿÿ=ÿ1136.50
                  Logÿlikelihoodÿ=ÿ-26398.004ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿÿÿÿÿÿ=ÿÿ0.0000

                  --------------------------------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿÿÿoutÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
                  ---------------+----------------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿ1.sexÿ|ÿÿÿ.5414935ÿÿÿ.0480434ÿÿÿÿ11.27ÿÿÿ0.000ÿÿÿÿÿ.4473302ÿÿÿÿ.6356569
                  ÿÿÿÿÿÿÿÿÿ1.timÿ|ÿÿÿ.5088338ÿÿÿ.0389306ÿÿÿÿ13.07ÿÿÿ0.000ÿÿÿÿÿ.4325313ÿÿÿÿ.5851363
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿsex#timÿ|
                  ÿÿÿÿÿÿÿÿÿÿ1ÿ1ÿÿ|ÿÿÿ.4920562ÿÿÿ.0550561ÿÿÿÿÿ8.94ÿÿÿ0.000ÿÿÿÿÿ.3841482ÿÿÿÿ.5999642
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿindÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿ2ÿÿ|ÿÿÿ.0154798ÿÿÿ.0130061ÿÿÿÿÿ1.19ÿÿÿ0.234ÿÿÿÿ-.0100116ÿÿÿÿ.0409712
                  ÿÿÿÿÿÿÿÿÿÿÿÿ3ÿÿ|ÿÿÿ.0099766ÿÿÿ.0128493ÿÿÿÿÿ0.78ÿÿÿ0.437ÿÿÿÿ-.0152076ÿÿÿÿ.0351609
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿ-.0083652ÿÿÿ.0347733ÿÿÿÿ-0.24ÿÿÿ0.810ÿÿÿÿ-.0765197ÿÿÿÿ.0597892
                  --------------------------------------------------------------------------------

                  ------------------------------------------------------------------------------
                  ÿÿRandom-effectsÿparametersÿÿ|ÿÿÿEstimateÿÿÿStd.ÿerr.ÿÿÿÿÿ[95%ÿconf.ÿinterval]
                  -----------------------------+------------------------------------------------
                  pid:ÿUnstructuredÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿvar(tim)ÿ|ÿÿÿ1.938513ÿÿÿ.0588627ÿÿÿÿÿÿÿ1.82651ÿÿÿÿ2.057384
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿvar(_cons)ÿ|ÿÿÿ1.563692ÿÿÿ.0447514ÿÿÿÿÿÿ1.478396ÿÿÿÿÿ1.65391
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿcov(tim,_cons)ÿ|ÿÿ-.7538533ÿÿÿ.0399979ÿÿÿÿÿ-.8322478ÿÿÿ-.6754588
                  -----------------------------+------------------------------------------------
                  Residual:ÿIndependent,ÿÿÿÿÿÿÿ|
                  ÿÿÿÿbyÿindÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1:ÿvar(e)ÿ|ÿÿÿ.4980293ÿÿÿ.0133712ÿÿÿÿÿÿ.4724998ÿÿÿÿ.5249382
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ2:ÿvar(e)ÿ|ÿÿÿ.5169173ÿÿÿ.0136577ÿÿÿÿÿÿÿÿ.49083ÿÿÿÿ.5443911
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ3:ÿvar(e)ÿ|ÿÿÿ.4926044ÿÿÿÿ.013329ÿÿÿÿÿÿ.4671606ÿÿÿÿ.5194339
                  ------------------------------------------------------------------------------

                  .ÿ
                  .ÿquietlyÿlogÿcloseÿlo

                  .ÿ
                  .ÿexit

                  endÿofÿdo-file


                  .


                  For the latent growth curve formulation with sem above, I've coded the constraints explicitly beforehand. In earlier experience, I've found that the syntax parser occasionally gets confused when I try to impose constraints simultaneously on both indicator intercepts and factor loadings using path notation syntax.

                  The attached do-file contains code for the random slope, single-equation formulation with gsem (see Example 38g in the user's manual). It follows the exit command and so it's not run and shown in the output above, but it does give the same results as the three approaches above.
                  Attached Files

                  Comment


                  • #10
                    This has been driving me crazy. As I suspected, your 2 approaches were not equivalent. To make them equivalent, I think the groups model would have to allow the mean of Ilo to differ between groups. But, I can't figure out how to do that.

                    So instead, I changed your single goup model to NOT allow the means to differ by groups. Which is not a good model, but it is equivalent to the groups model you have been running (I think). That is, if you run this with your own data, I think both approaches will give you the same results.


                    Code:
                    * Createv a mockup of data
                    webuse nhanes2f, clear
                    renvars houssiz age height weight bpsystol bpdiast black sex \ ///
                        ilo1 ilo2 ilo3 ilo4 ilo5 ilo6 pre_post_r sex_r
                    gen sex_pp = pre_post_r * sex_r
                    
                    * Run single group model, excluding sex dummy
                    sem (Ilo -> ilo1 ilo2 ilo3 ilo4 ilo5 ilo6) (pre_post_r -> Ilo) (sex_r -> Ilo@0) (sex_pp -> Ilo), ///
                        cov(e.ilo2*e.ilo3) cov(e.ilo1*e.ilo2) cov(e.ilo1*e.ilo3) ///
                        nolog nocnsr
                    
                    * This runs the equivalent multi-group model
                    sem (Ilo ->  ilo1 ilo2 ilo3 ilo4 ilo5 ilo6 ) (pre_post_r -> Ilo), /// 
                        group(sex_r) ginvariant(mcoef mcons serrvar merrvar smerrcov meanex covex) /// 
                        cov( e.ilo1*e.ilo2 e.ilo1*e.ilo3 e.ilo2*e.ilo3) ///
                        nolog showg nocnsr
                    
                    estat ginvariant, showp(scoef)
                    That still leaves open which is the best model to use, since neither of the above models is very good! My inclination is to do what I said earlier, and just use the ginvariant defaults.

                    Code:
                    * Best model?
                    sem (Ilo ->  ilo1 ilo2 ilo3 ilo4 ilo5 ilo6 ) (pre_post_r -> Ilo), /// 
                        group(sex_r)  /// 
                        cov( e.ilo1*e.ilo2 e.ilo1*e.ilo3 e.ilo2*e.ilo3) ///
                        nolog showg nocnsr
                    
                    estat ginvariant, showp(scoef scons)
                    With my fake data, you would conclude that the effect of pre_post_r does not significantly differ by group. I don't know what your real data will show.
                    -------------------------------------------
                    Richard Williams, Notre Dame Dept of Sociology
                    StataNow Version: 19.5 MP (2 processor)

                    EMAIL: [email protected]
                    WWW: https://www3.nd.edu/~rwilliam

                    Comment


                    • #11
                      It dawned on me afterwards that the postestimation computation above of the sex × tim interaction for the growth curve-like SEM incorrectly used [Intercept]sex for the baseline when that had already been accounted for by loading the second time point's indicators on the Intercept latent factor's sex predictor. It's the time effect that's not been deducted from the [Slope]sex coefficient (due to the noconstant specification). The interaction term is is correctly
                      Code:
                      lincom [Slope]sex - [Slope]tim
                      and the corrected comparison table:

                      Main effects of sex (coefficient ± standard error)
                      SEM-GC 0.54 ± 0.03
                      SEM-WB 0.54 ± 0.05
                      MIXED 0.54 ± 0.05

                      Main effects of time
                      SEM-GC 0.51 ± 0.03
                      SEM-WB 0.51 ± 0.04 (avg.)
                      MIXED 0.51 ± 0.04

                      Sex × time interaction
                      SEM-GC 0.49 ± 0.05
                      SEM-WB 0.50 ± 0.06
                      MIXED 0.49 ± 0.06

                      Intercept Variance (coefficient only)
                      SEM-GC 1.6
                      SEM-WB 1.6
                      MIXED 1.6

                      Random Slope Variance
                      SEM-GC 1.9
                      SEM-WB 2.0
                      MIXED 1.9

                      Intercept*Slope Covariance
                      SEM-GC -0.76
                      SEM-WB -0.77
                      MIXED -0.75

                      Revised do-file and log file are attached.
                      Attached Files

                      Comment


                      • #12
                        Thank you Prof. Williams for your tryout.
                        Yes, you are right in saying that the revised interaction model produces the exactly same result as the groups model. I have tried your codes and the results are below.
                        However, setting sex_r -> Ilo@0 in the interaction model seems to mean that we drop this path, i.e., the main effect of sex, right?
                        As far as I know, to test moderation effect, the main effects of both the IV (pre & post) and the moderator (sex) and the interaction term have to be included. Would it be correct if we drop the main effect of sex?
                        BTW, it can be seen from the results below that the interaction term has become significant (insignificant in the original model). But I wonder if it has something to do with the dropping the path sex_r -> Ilo

                        Thank you Dr. Coveney for your advice also. I think it may take some time for me to digest and try out the growth model that you mentioned. There are in fact quite many syntaxes that I don't understand (those run before gsem or mixed).

                        Revised interaction model (by setting sex_r -> Ilo@0):
                        Code:
                        -----------------------------------------------------------------------------------
                                          |                 OIM
                                          | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
                        ------------------+----------------------------------------------------------------
                        Structural        |
                          Ilo             |
                               pre_post_r |     1.0322   .0642604    16.06   0.000     .9062523    1.158148
                                   sex_pp |  -.5825375   .0789673    -7.38   0.000    -.7373106   -.4277644
                        ------------------+----------------------------------------------------------------
                        Measurement       |
                          ilo1            |
                                      Ilo |          1  (constrained)
                                    _cons |   4.101196   .0303532   135.12   0.000     4.041704    4.160687
                          ----------------+----------------------------------------------------------------
                          ilo2            |
                                      Ilo |   .7341535   .0174991    41.95   0.000     .6998558    .7684512
                                    _cons |   4.603395   .0267991   171.77   0.000      4.55087     4.65592
                          ----------------+----------------------------------------------------------------
                          ilo3            |
                                      Ilo |   .8972643   .0160334    55.96   0.000     .8658395    .9286891
                                    _cons |   4.419908   .0272956   161.93   0.000     4.366409    4.473406
                          ----------------+----------------------------------------------------------------
                          ilo4            |
                                      Ilo |   1.068358   .0188077    56.80   0.000     1.031496     1.10522
                                    _cons |   4.145609   .0305574   135.67   0.000     4.085717      4.2055
                          ----------------+----------------------------------------------------------------
                          ilo5            |
                                      Ilo |   1.148001   .0191365    59.99   0.000     1.110494    1.185507
                                    _cons |   3.738373   .0317925   117.59   0.000     3.676061    3.800686
                          ----------------+----------------------------------------------------------------
                          ilo6            |
                                      Ilo |   1.051796    .018041    58.30   0.000     1.016436    1.087155
                                    _cons |   3.992465   .0296579   134.62   0.000     3.934337    4.050594
                        ------------------+----------------------------------------------------------------
                               var(e.ilo1)|   .7534025   .0229478                      .7097417     .799749
                               var(e.ilo2)|   1.043402   .0288968                      .9882747    1.101604
                               var(e.ilo3)|   .6190326   .0188627                      .5831447    .6571292
                               var(e.ilo4)|   .5276721   .0175686                      .4943377    .5632543
                               var(e.ilo5)|    .413576   .0160233                      .3833336    .4462042
                               var(e.ilo6)|   .4359774   .0153031                      .4069923    .4670266
                                var(e.Ilo)|    1.32266   .0501173                      1.227991    1.424628
                        ------------------+----------------------------------------------------------------
                        cov(e.ilo1,e.ilo2)|   .1528803   .0188259     8.12   0.000     .1159822    .1897783
                        cov(e.ilo1,e.ilo3)|   .1094717   .0153727     7.12   0.000     .0793417    .1396016
                        cov(e.ilo2,e.ilo3)|    .362107   .0184853    19.59   0.000     .3258764    .3983376
                        -----------------------------------------------------------------------------------
                        LR test of model vs. saturated: chi2(22) = 388.62              Prob > chi2 = 0.0000
                        Groups model:
                        Code:
                        -----------------------------------------------------------------------------------
                                          |                 OIM
                                          | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
                        ------------------+----------------------------------------------------------------
                        Structural        |
                          Ilo             |
                               pre_post_r |
                                    Male  |     1.0322   .0642604    16.06   0.000     .9062523    1.158148
                                  Female  |   .4496628   .0606062     7.42   0.000     .3308769    .5684487
                        ------------------+----------------------------------------------------------------
                        Measurement       |
                          ilo1            |
                                      Ilo |[*] |          1  (constrained)
                                    _cons |[*] |   4.101196   .0303532   135.12   0.000     4.041704    4.160687
                          ----------------+----------------------------------------------------------------
                          ilo2            |
                                      Ilo |[*] |   .7341535   .0174991    41.95   0.000     .6998558    .7684512
                                    _cons |[*] |   4.603395   .0267991   171.77   0.000      4.55087     4.65592
                          ----------------+----------------------------------------------------------------
                          ilo3            |
                                      Ilo |[*] |   .8972643   .0160334    55.96   0.000     .8658395    .9286891
                                    _cons |[*] |   4.419908   .0272956   161.93   0.000     4.366409    4.473406
                          ----------------+----------------------------------------------------------------
                          ilo4            |
                                      Ilo |[*] |   1.068358   .0188077    56.80   0.000     1.031496     1.10522
                                    _cons |[*] |   4.145609   .0305574   135.67   0.000     4.085717      4.2055
                          ----------------+----------------------------------------------------------------
                          ilo5            |
                                      Ilo |[*] |   1.148001   .0191365    59.99   0.000     1.110494    1.185507
                                    _cons |[*] |   3.738373   .0317925   117.59   0.000     3.676061    3.800686
                          ----------------+----------------------------------------------------------------
                          ilo6            |
                                      Ilo |[*] |   1.051796    .018041    58.30   0.000     1.016436    1.087155
                                    _cons |[*] |   3.992465   .0296579   134.62   0.000     3.934337    4.050594
                        ------------------+----------------------------------------------------------------
                               var(e.ilo1)|[*] |   .7534025   .0229478                      .7097417     .799749
                               var(e.ilo2)|[*] |   1.043402   .0288968                      .9882747    1.101604
                               var(e.ilo3)|[*] |   .6190326   .0188627                      .5831447    .6571292
                               var(e.ilo4)|[*] |   .5276721   .0175686                      .4943377    .5632543
                               var(e.ilo5)|[*] |    .413576   .0160233                      .3833336    .4462042
                               var(e.ilo6)|[*] |   .4359774   .0153031                      .4069923    .4670266
                                var(e.Ilo)|[*] |    1.32266   .0501173                      1.227991    1.424628
                        ------------------+----------------------------------------------------------------
                        cov(e.ilo1,e.ilo2)|[*] |   .1528803   .0188259     8.12   0.000     .1159822    .1897783
                        cov(e.ilo1,e.ilo3)|[*] |   .1094717   .0153727     7.12   0.000     .0793418    .1396016
                        cov(e.ilo2,e.ilo3)|[*] |    .362107   .0184853    19.59   0.000     .3258764    .3983376
                        -----------------------------------------------------------------------------------
                        Note:[*] identifies parameter estimates constrained to be equal across groups.
                        LR test of model vs. saturated: chi2(43) = 458.64              Prob > chi2 = 0.0000

                        Comment


                        • #13
                          It would NOT be correct to drop the main effect of sex. Basically I was showing how to get a single group model and a two group model to give identical Incorrect effects. If I could have cloned your original single group model I would have but I couldn’t figure out how.

                          My own inclination is to run the last model I showed, using only the default settings of ginvariant. What result does it give you?

                          Getting back to basics, there is still the question of whether this is a good latent variable model at all. Do these 6 indicators really reflect a single latent variable?
                          -------------------------------------------
                          Richard Williams, Notre Dame Dept of Sociology
                          StataNow Version: 19.5 MP (2 processor)

                          EMAIL: [email protected]
                          WWW: https://www3.nd.edu/~rwilliam

                          Comment


                          • #14
                            Thank you Prof. Williams again.
                            I did try your last two groups model. Below are the results. The path pre_post_r -> Ilo is significant, so it contradicts with the original interaction model.
                            Even though you have shown identical incorrect effects, it is thought-provoking and makes me think the other way around, i.e., what constraint(s) I should release in your two groups model, so that it may produce identical correct results with the interaction model (though adjustment to the interaction model is still needed). I have tried to release some of the constraints but failed to get identical results.

                            Yes, these 6 indicators do load on a single latent variable when I run the SEM model with all observations without grouping. I think the goodness-of-fit indices are acceptable (though not very good and some modifications are needed). Please see the table at the bottom.

                            Code:
                            . sem (Ilo ->  ilo1 ilo2 ilo3 ilo4 ilo5 ilo6 ) (pre_post_r -> Ilo), group(sex_r)  cov( e.ilo1*e.ilo2 e.ilo1*e.ilo3 e.ilo2*e.ilo3) nolog showg nocnsr
                            (3987 observations with missing values excluded)
                            
                            Endogenous variables
                              Measurement: ilo1 ilo2 ilo3 ilo4 ilo5 ilo6
                              Latent:      Ilo
                            
                            Exogenous variables
                              Observed: pre_post_r
                            
                            Structural equation model                             Number of obs    = 2,977
                            Grouping variable: sex_r                              Number of groups =     2
                            Estimation method: ml
                            
                            Log likelihood = -26255.936
                            
                            -----------------------------------------------------------------------------------
                                              |                 OIM
                                              | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
                            ------------------+----------------------------------------------------------------
                            Structural        |
                              Ilo             |
                                   pre_post_r |
                                        Male  |   1.057029   .0668884    15.80   0.000     .9259299    1.188128
                                      Female  |    .475181   .0593236     8.01   0.000     .3589088    .5914531
                            ------------------+----------------------------------------------------------------
                            Measurement       |
                              ilo1            |
                                          Ilo |[*] |          1  (constrained)
                                        _cons |[*] |   4.076275   .0316695   128.71   0.000     4.014204    4.138346
                              ----------------+----------------------------------------------------------------
                              ilo2            |
                                          Ilo |[*] |   .7354143   .0174511    42.14   0.000     .7012108    .7696178
                                        _cons |[*] |   4.580237   .0276641   165.57   0.000     4.526016    4.634457
                              ----------------+----------------------------------------------------------------
                              ilo3            |
                                          Ilo |[*] |   .9005706   .0160093    56.25   0.000     .8691929    .9319483
                                        _cons |[*] |   4.392349    .028554   153.83   0.000     4.336385    4.448314
                              ----------------+----------------------------------------------------------------
                              ilo4            |
                                          Ilo |[*] |   1.071573   .0189109    56.66   0.000     1.034508    1.108638
                                        _cons |[*] |   4.109271   .0322031   127.60   0.000     4.046155    4.172388
                              ----------------+----------------------------------------------------------------
                              ilo5            |
                                          Ilo |[*] |   1.150107   .0191952    59.92   0.000     1.112485    1.187729
                                        _cons |[*] |   3.707391   .0334018   110.99   0.000     3.641925    3.772857
                              ----------------+----------------------------------------------------------------
                              ilo6            |
                                          Ilo |[*] |   1.052774   .0181001    58.16   0.000     1.017299     1.08825
                                        _cons |[*] |   3.965231    .031095   127.52   0.000     3.904285    4.026176
                            ------------------+----------------------------------------------------------------
                                   var(e.ilo1)|
                                        Male  |   .7583969   .0331749                      .6960847    .8262871
                                      Female  |   .7504299   .0314838                      .6911917    .8147451
                                   var(e.ilo2)|
                                        Male  |    1.01689   .0405871                       .940373    1.099634
                                      Female  |    1.06846   .0410409                      .9909743    1.152004
                                   var(e.ilo3)|
                                        Male  |   .5753334   .0254611                      .5275335    .6274644
                                      Female  |   .6600116   .0275646                       .608138    .7163101
                                   var(e.ilo4)|
                                        Male  |   .5715683   .0268245                      .5213389    .6266371
                                      Female  |    .486231   .0231963                      .4428279    .5338883
                                   var(e.ilo5)|
                                        Male  |   .4239916   .0230802                      .3810848    .4717293
                                      Female  |   .3998188    .021425                      .3599565    .4440956
                                   var(e.ilo6)|
                                        Male  |   .4376258    .021837                      .3968524    .4825884
                                      Female  |   .4365623    .020979                      .3973213     .479679
                                    var(e.Ilo)|
                                        Male  |   1.433753   .0694416                       1.30391    1.576525
                                      Female  |   1.211685   .0577822                      1.103565    1.330397
                            ------------------+----------------------------------------------------------------
                            cov(e.ilo1,e.ilo2)|
                                        Male  |   .1839323    .027015     6.81   0.000     .1309838    .2368809
                                      Female  |   .1240563   .0260917     4.75   0.000     .0729175    .1751951
                            cov(e.ilo1,e.ilo3)|
                                        Male  |   .1126119   .0215364     5.23   0.000     .0704013    .1548224
                                      Female  |   .1070265   .0216561     4.94   0.000     .0645814    .1494716
                            cov(e.ilo2,e.ilo3)|
                                        Male  |   .2880909   .0248446    11.60   0.000     .2393964    .3367854
                                      Female  |    .432002    .027221    15.87   0.000     .3786499    .4853541
                            -----------------------------------------------------------------------------------
                            Note:[*] identifies parameter estimates constrained to be equal across groups.
                            LR test of model vs. saturated: chi2(33) = 414.81              Prob > chi2 = 0.0000
                            
                            . estat ginvariant, showp(scoef scons)
                            
                            Tests for group invariance of parameters
                            
                            ------------------------------------------------------------------------------
                                         |            Wald test                       Score test
                                         |      chi2         df    P>chi2       chi2          df    P>chi2
                            -------------+----------------------------------------------------------------
                            Structural   |
                              Ilo        |
                              pre_post_r |    54.061          1    0.0000          .           .         .
                            ------------------------------------------------------------------------------
                            Goodness-of-fit indices of the original model (without grouping):

                            Code:
                            ----------------------------------------------------------------------------
                            Fit statistic        |      Value   Description
                            ---------------------+------------------------------------------------------
                            Likelihood ratio     |
                                      chi2_ms(6) |     69.971   model vs. saturated
                                        p > chi2 |      0.000
                                     chi2_bs(15) |  14706.878   baseline vs. saturated
                                        p > chi2 |      0.000
                            ---------------------+------------------------------------------------------
                            Population error     |
                                           RMSEA |      0.060   Root mean squared error of approximation
                             90% CI, lower bound |      0.048
                                     upper bound |      0.073
                                          pclose |      0.089   Probability RMSEA <= 0.05
                            ---------------------+------------------------------------------------------
                            Information criteria |
                                             AIC |  49020.749   Akaike's information criterion
                                             BIC |  49146.721   Bayesian information criterion
                            ---------------------+------------------------------------------------------
                            Baseline comparison  |
                                             CFI |      0.996   Comparative fit index
                                             TLI |      0.989   Tucker–Lewis index
                            ---------------------+------------------------------------------------------
                            Size of residuals    |
                                            SRMR |      0.011   Standardized root mean squared residual
                                              CD |      0.937   Coefficient of determination
                            ----------------------------------------------------------------------------

                            Comment


                            • #15
                              Originally posted by Kwok-wing Sum View Post
                              I think it may take some time for me to digest and try out the growth model that you mentioned.
                              Yeah, me too, for example, I mistakenly thought that constraining its intercept to zero is necessary for identification of the sex and time effects. Not so, and it's better for it to be freed in order to facilitate estimation of a nonzero constant (fixed-effects intercept).

                              Updates to code in red below; corresponding do-file and log file again attached.
                              Code:
                              quietly drawnorm intercept slope, double corr(1 -0.25 \ -0.25 1) n(3000)
                              generate byte sex = mod(_n, 2)
                              
                              tempname Corr
                              matrix define `Corr' = J(3, 3, 0.5) + I(3) * 0.5
                              forvalues tim = 0/1 {
                                  quietly drawnorm e1`tim' e2`tim' e3`tim', double corr(`Corr')
                                  forvalues i = 1/3 {
                                      generate double out`i'`tim' = ///
                                          10 + intercept + ///
                                              sex / 2 + ///
                                              `tim' * (1/2 + slope) + ///
                                                  sex * `tim' / 2 + ///
                                                      e`i'`tim'
                                  }
                              }
                              
                              *
                              * SEM (growth-curve like)
                              *
                              constraint define  1 [out10]Intercept = 1
                              constraint define  2 [out11]Intercept = 1
                              constraint define  3 [out11]Slope = 1
                              
                              constraint define  4 [out20]Intercept = [out21]Intercept
                              constraint define  5 [out30]Intercept = [out31]Intercept
                              constraint define  6 [out21]Intercept = [out21]Slope
                              constraint define  7 [out31]Intercept = [out31]Slope
                              
                              constraint define  8 [/]var(e.out10) = [/]var(e.out11)
                              constraint define  9 [/]var(e.out20) = [/]var(e.out21)
                              constraint define 10 [/]var(e.out30) = [/]var(e.out31)
                              
                              generate byte tim = !sex
                              
                              * constraint define 11 [Intercept]tim = 0
                              
                              sem ///
                                  (out* <- Intercept, noconstant) ///
                                  (out?1 <- Slope, noconstant) ///
                                  (Intercept Slope <- tim sex, noconstant), ///
                                      constraints(1/10) ///
                                      covariance((e.Intercept*e.Slope)) ///
                                          nocnsreport nodescribe nolog
                              // sex
                              lincom [Intercept]sex - [Intercept]tim
                              // sex × tim interaction
                              lincom [Slope]sex - [Slope]tim
                              Updated coefficient-comparison table below reflects the changes, including a new section for fixed-effects intercept (constant) and slight changes in standard errors for growth curve-like SEM due to relaxation of constraints. (The growth curve-like SEM's standard errors now match the other two methods' more closely than in #11 above.)

                              Intercept (coefficient ± standard error)
                              SEM-GC 9.99 ± 0.03
                              SEM-WB 9.99 ± 0.04
                              MIXED 9.99 ± 0.03


                              Main effects of sex
                              SEM-GC 0.54 ± 0.05
                              SEM-WB 0.54 ± 0.05
                              MIXED 0.54 ± 0.05

                              Main effects of time
                              SEM-GC 0.51 ± 0.03
                              SEM-WB 0.51 ± 0.04 (avg.)
                              MIXED 0.51 ± 0.04

                              Sex × time interaction
                              SEM-GC 0.49 ± 0.06
                              SEM-WB 0.50 ± 0.06
                              MIXED 0.49 ± 0.06

                              Intercept Variance (coefficient only)
                              SEM-GC 1.6
                              SEM-WB 1.6
                              MIXED 1.6

                              Random Slope Variance
                              SEM-GC 1.9
                              SEM-WB 2.0
                              MIXED 1.9

                              Intercept*Slope Covariance
                              SEM-GC -0.76
                              SEM-WB -0.77
                              MIXED -0.75
                              Attached Files

                              Comment

                              Working...
                              X