Announcement

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

  • Multilevel SEM

    I have a question about SEM and would like to learn some solutions.

    Suppose I use three indicators to measure one's concern about the environment (x1 x2 x3).

    Then I will have three individual level predictors (income education age) and two country level predictors (GDP CO2).

    I have run the following model

    gsem (Concern -> x1 x2 x3) (Concern <- income education age M1[GDP] M2[CO2])

    However, Stata does not run and said

    "invalid path specification; Concern may not be the destination of a path from M1[GDP]"

    How may I revise the code and fix the problem?

    Thanks.

  • #2
    Your model is mispecified. At Stata's command line, type
    Code:
    help sem_examples
    and scroll down to the hyperlink for example 38g Random-intercept and random-slope models (multilevel) for guidance how to properly specify country level as a random effect and the two predictors for it.

    Comment


    • #3
      Hi Joseph,

      Thanks for your response.

      I have checked the Example 38g. However, the example's dependent variable (wage) is one indicator, not a latent variable measured by multiple indicators.

      For example, if I use this code, concern <- income education age log_gdp M1[countryid], the model works.

      If the concern is measured by multiple indicators (e.g., x1 x2 x3), how may I revise the code?

      Thanks,

      Feng

      Comment


      • #4
        Originally posted by Feng Hao View Post
        If the concern is measured by multiple indicators (e.g., x1 x2 x3), how may I revise the code?
        Try something like that below. (Begin at the "Begin here" comment.)

        .ÿ
        .ÿversionÿ15.1

        .ÿ
        .ÿclearÿ*

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

        .ÿ
        .ÿquietlyÿsetÿobsÿ50

        .ÿgenerateÿbyteÿcidÿ=ÿ_n

        .ÿgenerateÿdoubleÿcid_uÿ=ÿrnormal()

        .ÿ
        .ÿgenerateÿdoubleÿgdpÿ=ÿruniform()ÿ-ÿ0.5

        .ÿgenerateÿdoubleÿco2ÿ=ÿruniform()ÿ-ÿ0.5

        .ÿ
        .ÿquietlyÿexpandÿ100

        .ÿgenerateÿdoubleÿincÿ=ÿruniform()ÿ-ÿ0.5

        .ÿgenerateÿdoubleÿeduÿ=ÿruniform()ÿ-ÿ0.5

        .ÿgenerateÿdoubleÿageÿ=ÿruniform()ÿ-ÿ0.5

        .ÿ
        .ÿquietlyÿdrawnormÿx1ÿx2ÿx3,ÿdoubleÿcorr(1ÿ0.5ÿ0.5ÿ\ÿ0.5ÿ1ÿ0.5ÿ\ÿ0.5ÿ0.5ÿ1)

        .ÿforvaluesÿiÿ=ÿ1/3ÿ{
        ÿÿ2.ÿÿÿÿÿÿÿÿÿquietlyÿreplaceÿx`i'ÿ=ÿx`i'ÿ+ÿcid_uÿ+ÿgdpÿ+ÿco2ÿ+ÿincÿ+ÿeduÿ+ÿage
        ÿÿ3.ÿ}

        .ÿ
        .ÿ*
        .ÿ*ÿBeginÿhere
        .ÿ*
        .ÿgsemÿ///
        >ÿÿÿÿÿÿÿÿÿ(x1ÿx2ÿx3ÿ<-ÿConcernÿM[cid])ÿ///
        >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ(M[cid]ÿ<-ÿgdpÿco2)ÿ///
        >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ(Concernÿ<-ÿincÿeduÿage),ÿ///
        >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿnocnsreportÿnodvheaderÿnolog

        GeneralizedÿstructuralÿequationÿmodelÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿÿ=ÿÿÿÿÿÿ5,000
        Logÿlikelihoodÿ=ÿ-19550.995

        --------------------------------------------------------------------------------
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿÿÿÿCoef.ÿÿÿStd.ÿErr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿConf.ÿInterval]
        ---------------+----------------------------------------------------------------
        x1ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿÿM[cid]ÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿ(constrained)
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿConcernÿ|ÿÿÿ.9932413ÿÿÿ.0201246ÿÿÿÿ49.35ÿÿÿ0.000ÿÿÿÿÿ.9537978ÿÿÿÿ1.032685
        ÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿÿ.1265436ÿÿÿ.1379599ÿÿÿÿÿ0.92ÿÿÿ0.359ÿÿÿÿ-.1438528ÿÿÿÿÿÿ.39694
        ---------------+----------------------------------------------------------------
        x2ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿÿM[cid]ÿ|ÿÿÿÿÿ.98332ÿÿÿ.0128078ÿÿÿÿ76.78ÿÿÿ0.000ÿÿÿÿÿ.9582172ÿÿÿÿ1.008423
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿConcernÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿ(constrained)
        ÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿÿ.1272679ÿÿÿ.1356921ÿÿÿÿÿ0.94ÿÿÿ0.348ÿÿÿÿ-.1386837ÿÿÿÿ.3932194
        ---------------+----------------------------------------------------------------
        x3ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿÿM[cid]ÿ|ÿÿÿ.9937496ÿÿÿ.0126898ÿÿÿÿ78.31ÿÿÿ0.000ÿÿÿÿÿ.9688781ÿÿÿÿ1.018621
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿConcernÿ|ÿÿÿ1.009683ÿÿÿ.0201356ÿÿÿÿ50.14ÿÿÿ0.000ÿÿÿÿÿ.9702178ÿÿÿÿ1.049148
        ÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿÿ.1026384ÿÿÿ.1371048ÿÿÿÿÿ0.75ÿÿÿ0.454ÿÿÿÿ-.1660821ÿÿÿÿ.3713589
        ---------------+----------------------------------------------------------------
        M[cid]ÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿÿÿÿÿgdpÿ|ÿÿÿ.8966807ÿÿÿ.5344742ÿÿÿÿÿ1.68ÿÿÿ0.093ÿÿÿÿ-.1508695ÿÿÿÿ1.944231
        ÿÿÿÿÿÿÿÿÿÿÿco2ÿ|ÿÿÿ1.275511ÿÿÿ.4908137ÿÿÿÿÿ2.60ÿÿÿ0.009ÿÿÿÿÿÿ.313534ÿÿÿÿ2.237488
        ---------------+----------------------------------------------------------------
        Concernÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿÿÿÿÿincÿ|ÿÿÿ.9926018ÿÿÿÿ.041016ÿÿÿÿ24.20ÿÿÿ0.000ÿÿÿÿÿÿ.912212ÿÿÿÿ1.072992
        ÿÿÿÿÿÿÿÿÿÿÿeduÿ|ÿÿÿ1.079008ÿÿÿ.0409925ÿÿÿÿ26.32ÿÿÿ0.000ÿÿÿÿÿ.9986641ÿÿÿÿ1.159352
        ÿÿÿÿÿÿÿÿÿÿÿageÿ|ÿÿÿ1.010827ÿÿÿ.0406803ÿÿÿÿ24.85ÿÿÿ0.000ÿÿÿÿÿ.9310954ÿÿÿÿ1.090559
        ---------------+----------------------------------------------------------------
        ÿÿvar(e.M[cid])|ÿÿÿ.9399255ÿÿÿ.1897684ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.6327587ÿÿÿÿ1.396203
        ÿvar(e.Concern)|ÿÿÿ.4716126ÿÿÿ.0170525ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.439347ÿÿÿÿ.5062477
        ---------------+----------------------------------------------------------------
        ÿÿÿÿÿÿvar(e.x1)|ÿÿÿ.5019046ÿÿÿ.0145219ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.4742342ÿÿÿÿ.5311896
        ÿÿÿÿÿÿvar(e.x2)|ÿÿÿ.5087824ÿÿÿ.0147194ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.4807356ÿÿÿÿ.5384656
        ÿÿÿÿÿÿvar(e.x3)|ÿÿÿ.4842024ÿÿÿ.0144332ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.4567243ÿÿÿÿ.5133336
        --------------------------------------------------------------------------------

        .ÿ
        .ÿexit

        endÿofÿdo-file


        .

        Comment


        • #5
          Hi Joseph,

          Thank you so much for answering my question.

          I have been struggling with this question for weeks.

          I have some follow-up questions that I would like to ask you.

          1. According to the results produced from your data, will I interpret that "GDP has non-significant impact to concern while CO2 has positive and significant impact?"

          2. How about model fit? We use "estat gof, stats(all)" to know CFI and RMSEA after the "sem" command, How may I obtain the model fit statistics after "gsem"?

          3. If I produce an interaction between country-level GDP and individual-level education, how may I write the code based on the following code?

          gsem (Concern M[cid] -> x1 x2 x3) ///
          (M[cid] <- gdp co2) ///
          (Concern <- income education age)

          Thanks again.

          Best,

          Feng

          Comment


          • #6
            Originally posted by Feng Hao View Post
            1. According to the results produced from your data, will I interpret that "GDP has non-significant impact to concern while CO2 has positive and significant impact?"
            No. They're both important.

            2. How about model fit? We use "estat gof, stats(all)" to know CFI and RMSEA after the "sem" command, How may I obtain the model fit statistics after "gsem"?
            I don't think that there are any conventional SEM goodness-of-fit statistics with generalized SEM, but I don't know for sure—I don't do SEM goodness-of-fit testing.

            3. If I produce an interaction between country-level GDP and individual-level education, how may I write the code based on the following code?
            I haven't thought about it, but try something like the following and see whether it produces the model that you want.
            Code:
            generate double iac = gdp * edu
            gsem ///
                (x1 x2 x3 <- Concern M[cid]) ///
                    (M[cid] <- gdp co2) ///
                    (Concern <- inc edu iac age)

            Comment


            • #7
              Thanks Joseph. Yes, the code for interaction works.

              Comment


              • #8
                Hi Joseph,

                I have another question about SEM.

                If the outcome variable is binary, shall I use the gsem code or continue with the sem code?

                If using gsem, how may I make the interpretations?

                Thanks,

                Feng

                Comment

                Working...
                X