Announcement

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

  • Analizing direct and indirect effect in a panel data using SEM command

    Good afternoon,

    I have a panel data that looks like the following:
    ID year Bth Dth int_y ptn_y o_in m_in patnum pat_e sales size exportn industry gextid country age
    20 2008 8 2 1 3 1 1 0 0 39389620 63 25.1 15 7.4 1 61
    20 2011 10 2 4 5 3 4 1 0 52623691 152 40.7 15 0 1 64
    20 2014 10 3 1 6 3 4 1 0 110100000 101 36.6 15 42.4 1 67
    22 2008 10 1 2 3 2 0 0 0 496600000 1489 7 22 0 1 66
    22 2011 10 4 1 6 3 2 8 4 511000000 1784 40.6 22 0 1 69
    22 2014 10 4 2 5 2 0 7 2 384200000 1569 72.7 22 0 1 72
    25 2008 5 0 0 0 0 0 0 0 21834200 154 5.4 15 16.4 1 60
    25 2011 8 0 0 0 0 0 0 0 21796024 134 4.9 15 2 1 63
    25 2014 8 0 0 1 0 1 0 0 23578268 124 6.4 15 0 1 66
    27 2008 9 3 1 3 2 1 4 3 52746431 462 1 12 3.3 1 44
    27 2011 9 3 1 3 1 0 0 0 42999533 330 0 12 0 1 47
    27 2014 8 0 1 2 1 1 0 0 44002188 357 51.9 12 0 1 50
    30 2008 7 3 2 3 3 1 0 0 574600000 126 0 13 31.3 1 43
    30 2011 10 5 0 0 2 2 0 0 381700000 134 4.2 13 12 1 46
    30 2014 10 4 1 2 0 0 1 0 354700000 121 2.2 13 5.5 1 49
    32 2008 7 2 0 2 2 1 0 0 37786689 88 8.9 23 0 1 39
    32 2011 7 2 0 0 0 2 0 0 17159611 67 0.9 23 0 1 42
    32 2014 8 4 0 1 0 0 0 0 12281532 83 1 23 0 1 45
    33 2008 2 0 0 0 2 3 0 0 62449255 378 15 14 0 1 34
    33 2011 2 0 0 0 2 3 0 0 31658394 240 0 14 0 1 37
    33 2014 1 0 0 0 0 0 0 0 26131847 200 0 14 0 1 40
    36 2008 6 2 0 0 0 0 2 2 4349675 56 0 18 0 1 52
    36 2011 5 2 0 0 3 4 5 5 8511439 92 0 18 0 1 55
    36 2014 6 2 2 1 2 3 0 0 7360923 82 50.3 18 0 1 58
    40 2008 10 2 1 4 0 0 0 0 25614595 44 0 10 7.4 0 33
    40 2011 10 3 1 2 0 0 0 0 25171278 45 0.8 10 6.3 0 36
    40 2014 10 4 0 0 0 0 0 0 24140456 44 2.5 10 0 0 39
    42 2008 6 0 1 2 1 0 0 0 372300000 238 3.5 14 0 1 33
    42 2011 9 0 1 3 3 0 0 0 262400000 225 5.2 14 20.3 1 36
    42 2014 9 0 1 5 3 0 0 0 284300000 228 0.5 14 16.4 1 39
    43 2008 8 1 0 0 2 1 0 0 18024408 80 0 19 20.9 1 35
    43 2011 7 0 0 0 2 1 0 0 19699301 90 0 19 16.1 1 38
    43 2014 7 0 0 0 2 0 0 0 20152976 99 0 19 0 1 41
    46 2008 8 3 1 3 1 1 0 0 17146389 75 0.5 17 2.4 1 30
    46 2011 9 2 0 2 1 1 0 0 20721491 70 0.3 17 2.7 1 33
    46 2014 7 2 0 0 2 0 0 0 27607344 75 0.3 17 19.3 1 36
    57 2008 6 2 0 0 0 0 1 0 22878934 21 1.9 17 99.5 1 20
    57 2011 10 4 0 0 0 0 1 0 14147998 26 1.9 17 100 1 23
    57 2014 10 4 0 0 0 1 1 0 10609470 26 2.8 17 100 1 26
    62 2008 10 2 0 0 0 0 0 0 2290688 17 34.5 16 0 1 15
    62 2011 10 2 0 0 0 0 0 0 2346570 15 15.2 16 0 1 18
    62 2014 10 0 0 0 0 0 0 0 1719451 14 8.9 16 0 1 21
    63 2008 9 1 0 0 0 0 0 0 21529736 108 42.9 15 0 1 18
    64 2008 10 3 3 4 3 4 3 2 10300167 52 51.6 15 0 1 18
    64 2011 10 1 0 1 3 4 0 0 9212141 35 44 15 0 1 21
    64 2014 9 5 0 5 3 3 1 0 10609470 40 46.4 15 0 1 24
    65 2011 5 2 0 0 2 0 0 0 3239057 30 30.9 12 0 1 21
    66 2008 9 0 0 1 0 0 4 1 22136526 100 21.8 17 6.7 0 17
    66 2011 10 0 0 0 0 0 2 1 12129950 77 25 17 0 1 20
    66 2014 10 0 0 0 0 2 0 0 11536365 62 51.4 17 21.2 1 23
    68 2008 6 2 0 0 0 0 0 0 19244274 107 0.4 17 13.6 1
    72 2008 7 1 2 4 1 0 0 0 375100000 833 47.7 14 7.5 1 15
    72 2011 7 1 1 4 3 0 0 0 231000000 749 38.1 14 25.2 1 18
    72 2014 7 2 1 5 1 0 0 0 324900000 798 53.1 14 21.2 1 21
    74 2008 1 1 0 0 0 0 0 0 17487783 307 0 21 0 1 15
    74 2014 4 0 0 0 0 0 0 0 49747173 2591 4.4 21 100 1 21
    75 2008 1 0 0 0 0 0 0 0 182500000 248 0.9 14 0 1 14
    75 2014 5 2 0 1 0 0 0 0 69436368 190 2.5 14 0 1 20
    77 2008 10 2 1 2 2 0 0 0 6023716 50 7 15 10 1 14
    77 2011 10 0 0 2 1 0 0 0 7237005 58 0 15 0 1 17
    82 2008 10 2 0 0 0 0 0 0 42801299 100 0 18 0 0 12
    82 2011 10 2 0 0 0 0 0 0 26827256 52 0 18 0 0 15
    82 2014 10 2 0 4 0 0 13 0 11847118 55 0 18 0 0 18
    88 2008 5 0 0 0 0 0 0 0 61785588 365 67.8 15 0 1 11
    88 2011 5 0 0 0 0 0 0 0 70115789 332 34.5 15 0 1 14
    88 2014 4 0 0 0 0 0 1 0 77315502 372 41 15 0 1 17
    In this panel data:

    Independent variables: Bth, Dth, int_y, ptn_y

    Mediating variables: o_in, m_in

    Depending variables: patnum, pat_epus

    Control variables: sales, size, exportn, industry, gextid, country, newage

    With this panel data I would like to analyze the direct and indirect effect that the independents variables have on the dependent variables. Looking for recommendation of how to perform this analysis I have found that in stata, the SEM command can be used to obtain both the direct and indirect effect when performing mediation. As the data need to be arranged in wide format to perform the analysis, a limitation that I have seen is that I am only able to perfom the analysis in a cross sectional matter. Is there a way to perform this analysis with SEM including the longitudinal characteristic of the dataset?

    Also, as the dependent variables patnum and patent_epus represent the number of “pat” requested of each type for the firms in the years analyzed, is it ok to use the “sem” command or is it better to use the “gsem” command?

    Thank you very much in advanced for your help.

    Jose Luis

  • #2
    While both SEM and GSEM can be applied to test mediation analysis, for nesting data structure, you need GSEM (Generalized Structural Equation Model) command. Once the model is fitted for random intercepts/coefficients, you can test the indirect effects which are tested using post-estimation command -nlcom- for path x->z->y. See the help file for -sem- and -gsem-
    Roman

    Comment


    • #3
      You may want to look at xtdpdml, available from SSC. What you want to do is more complicated than what it does but it can give you some ideas of how to code it. The support page is at

      https://www3.nd.edu/~rwilliam/dynamic/index.html

      See especially sections 2.3 and 4 of

      https://www3.nd.edu/~rwilliam/dynamic/SJPaper.pdf
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

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

      Comment


      • #4
        Thank you very much for your replying. Is it possible to perform the gsem command or the xtdpdml in Stata 12?

        Comment


        • #5
          Xtdpdml, probably. Use the v12 option. I don’t think gsem showed up til later but I could be wrong. In any event you can look at xtdpdml to see how it does things and then see if you can get ideas for your own problem.
          -------------------------------------------
          Richard Williams, Notre Dame Dept of Sociology
          Stata Version: 17.0 MP (2 processor)

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

          Comment


          • #6
            Dear all,
            Dear Richard,

            I have unbalanced panel data for a maximum of four waves per individual. Based on this data I estimate the following regression with individual fixed effects:

            HTML Code:
            xtreg y i.x1 x2 i.x3 x4, fe vce(cluster id)
            where y is a 5-category variable and x1 is also a 5-category variable.

            Now, I would like to decompose the effect of x1 into a direct effect and an indirect effect via mediation analysis. The mediator that I have in mind is a continuous variable z, which has a positive effect on y, while x1 has a negative effect on y.

            How can I estimate the direct and indirect effect while controlling for unobserved heterogeneity using individual fixed effects?

            Does xtdpdml by Richard Williams fit my problem? And if so, how would I apply the command, i.e. how to indicate that I have panel data, that I want fixed effects and that I want the standard errors clustered at the individual level etc.?

            I have posted this question separately earlier last week, but still don't know how to go ahead: https://www.statalist.org/forums/for...direct-effects I hope, someone here can help me.

            Thanks a lot,
            Stephanie

            (I work with Stata 15 on Windows.)

            Comment


            • #7
              Dear all,

              I would really apprechiate some help regarding my problem. Please let me know in case my question was not stated clearly and I will try to rephrase it.

              Best wishes,
              Staphanie

              Comment


              • #8
                Sorry, I did not see the September 2019 message.

                I don't know if xtdpdml can do what you want or not. I have never tried it.

                You could try specifying the staywide option in xtdpdml. The data then stay in wide format. The full range of sem post-estimation commands should then be available to you, including estat teffects.

                xtdpdml also supports the vce option, although I've only tried a few options with it.

                You can also output generated code into a file. If the generated code is close but not quite to the code you want, you may be able to make some tweaks by hand.

                Again, I don't really know. But I have often found my programs can do things I had never thought of because they can take advantage of features built into Stata.

                A few other points: if y and x1 are 5 category variables, do you think it is appropriate to treat them as continuous? sem estimates linear models.

                There isn't going to be a single x1. Instead there will be an x1time1, x1time2, etc. Does that really give you want?

                xtdpdml is going to include lagged y as a regressor by default. If you don't want that, you should use the ylag(0) option.
                -------------------------------------------
                Richard Williams, Notre Dame Dept of Sociology
                Stata Version: 17.0 MP (2 processor)

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

                Comment


                • #9
                  Dear Richard,
                  Thank you very much for your response.
                  I will look closer into xtdpdml and get back to you if I have further questions.
                  All the best,
                  Stephanie

                  Comment


                  • #10
                    Dear Richard,

                    As you said staywide options enables to use post-estimation commands of SEM. I have a particular question on that. I have a panel data for 700 individuals throughout 12 months. Once I run xtdpml by using option staywide and esttab teffects I get direct, indirect, total effects for all lags. But this is not what I'm looking for. I am more interested in average effects as a whole rather than effects per all lags separately.

                    Do you have any suggestion about how to get average direct, indirect effects like a cross-sectional design?

                    Thanks in advance!

                    Best regards,
                    John

                    Comment

                    Working...
                    X