Announcement

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

  • Creating table of direct, indirect and total effects after Structural Equation Model (SEM)

    Dear all,

    I am trying to create a table with direct, indirect and total effects after a structural equation model.

    After running the codes in StataNow/SE19.5:

    ***data from the sem documentation (example 7)
    Code:
    use https://www.stata-press.com/data/r19/sem_sm1
    ***Example 7
    Code:
    sem (r_occasp <- f_occasp r_intel r_ses f_ses) (f_occasp <- r_occasp f_intel f_ses r_ses), cov(e.r_occasp*e.f_occasp) standardized
    ***the code for decomposing total effects into direct and indirect effects
    Code:
    estat teffects
    the code:
    Code:
    etable
    will only provide the direct effects (the coefficients), and the code:
    Code:
    db tables
    seems to be empty.

    I am able to produce a table using the codes:
    Code:
    sem (r_occasp <- f_occasp r_intel r_ses f_ses) (f_occasp <- r_occasp f_intel f_ses r_ses), cov(e.r_occasp*e.f_occasp) standardized
    estat teffects
    mat direct = r(direct)'
    mat indirect = r(indirect)'
    mat total = r(total)'
    mat rowjoin tabell = direct indirect total
    mat list tabell
    However, I was looking for using for instance collect table and its features (e.g. list variable labels as etable does). Is there anyone out there who can help me with this? Any tip or recommendations are gratefully acknowledged.

  • #2
    The last code should be:
    Code:
     
     sem (r_occasp <- f_occasp r_intel r_ses f_ses) (f_occasp <- r_occasp f_intel f_ses r_ses), cov(e.r_occasp*e.f_occasp) standardized estat teffects mat direct = r(direct)' mat indirect = r(indirect)' mat total = r(total)' mat coljoin tabell = direct indirect total mat list tabell

    Comment


    • #3
      Something happende with the code in #2, it should read:

      Code:
      sem (r_occasp <- f_occasp r_intel r_ses f_ses) (f_occasp <- r_occasp f_intel f_ses r_ses), cov(e.r_occasp*e.f_occasp) standardized
      estat teffects
      mat direct = r(direct)'
      mat indirect = r(indirect)'
      mat total = r(total)'
      mat rowjoin tabell = direct indirect total
      mat list tabell

      Comment


      • #4
        It is not possible to edit the post, or at least it is very time consuming. The code should read (coljoin not rowjoin):

        Code:
        sem (r_occasp <- f_occasp r_intel r_ses f_ses) (f_occasp <- r_occasp f_intel f_ses r_ses), cov(e.r_occasp*e.f_occasp) standardized
        estat teffects
        mat direct = r(direct)'
        mat indirect = r(indirect)'
        mat total = r(total)'
        mat coljoin tabell = direct indirect total
        mat list tabell

        Comment


        • #5
          etable primarily works with estimation results taken from e(). The only postestimation command it currently supports is margins.

          You can use collect get with the matrix of effects that you built, then use the Tables Builder (db tables) or make direct calls to collect to build your table.

          Here is some code I added to your example to build a simple table of effects.
          Code:
          * add descriptive column names
          mat colname tabell = Direct Indirect Total
          * consume this matrix of effects, add dimension for super-column title
          collect get effects=tabell, tag(coleq[Effect])
          * center the super title
          collect style column, dups(center)
          * arrange the collected effects into a table
          collect layout (roweq#rowname) (coleq#colname)
          Here is the resulting table.
          Code:
          -----------------------------------------------------------------------
                                                     |           Effect
                                                     |   Direct Indirect    Total
          -------------------------------------------+---------------------------
          Respondent's occupational aspiration       |
            Respondent's occupational aspiration     |        0 .0624106 .0624106
            Friend's occupational aspiration         | .2773441 .0173092 .2946533
            Respondent's intelligence                | .2854766 .0178168 .3032933
            Respondent's family socioeconomic status | .1570082 .0332001 .1902083
            Friend's family socioeconomic status     | .0973327 .0556285 .1529612
            Friend's intelligence                    |        0 .1088356 .1088356
          Friend's occupational aspiration           |
            Respondent's occupational aspiration     | .2118102 .0132192 .2250294
            Friend's occupational aspiration         |        0 .0624106 .0624106
            Respondent's intelligence                |        0 .0642406 .0642406
            Respondent's family socioeconomic status | .0794194 .0402881 .1197074
            Friend's family socioeconomic status     | .1681772 .0323987 .2005759
            Friend's intelligence                    | .3693682 .0230525 .3924207
          -----------------------------------------------------------------------

          Comment


          • #6
            Thank you very much, Jeff!

            This was very helpful.

            Comment

            Working...
            X