Announcement

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

  • HLM with mediation

    Hello, I am a doctoral student and working on analyzing my model as a new Stata user. My independent and control variables and mediator are at the country level, and my dependent variable is at the firm level. I ran the mixed effects model with the mediator and all covariates to estimate the direct effect of the IVs on the DV and ran a separate mixed effects model to estimate the effect of the IVs on the mediator. I loaded the mediation module, but when trying to run the mediation, Stata does not accept anything that is put in the treatment area drop down for the causal mediation analysis. Any ideas would be greatly appreciated.

  • #2
    I know of no way to estimate mediation models using Stata's multi-level modeling commands. However, such models can, instead be estimated using -gsem-. You do not describe your model in any detail, so I'll give you some generic advice here. Let us suppose your basic model was coded as -mixed y x1 x2 x3 || firm:-. Now you want to add a variable, m, which mediates the effect of x1 on y. You can do that in -gsem- with:
    Code:
    gsem (y <- m x1 x2 x3 RE1[firm]) (m <- x1 RE2[firm]), cov(RE1[firm]*RE2[firm]@0)

    Comment


    • #3
      I agree with Clyde that gsem is the clearest way of doing it using standard Stata. That said, UCLA OARS has a couple of resources for this that do not involve gsem. The first resource calls on the user-written program ml_mediation, which at the moment, you have to download the zip file from UCLA and install appropriately to your personal ado directory.* And in the second approach, they use some elaborate recoding to get what you want from a stacked mixed model.

      *All UCLA ado files can be downloaded from here.

      Comment


      • #4
        Nothing to do with how to estimate your model via Stata, but I think that this article by Klaus Fiedler et al. should be required reading for anyone doing mediation analysis.
        --
        Bruce Weaver
        Email: [email protected]
        Version: Stata/MP 18.5 (Windows)

        Comment


        • #5
          Good point, Bruce Weaver. I appreciate this argument, but a lot of non-mediation regression models are built around a single treatment/exposure that is not randomly assigned. My impression of this is to build a really good model for your mediator of choice (and outcome) and if you do that, I'm good with it. I know that it's one of many possible mediators and I don't assume that any one mediator analysis has definitively closed the issue. But for folks who don't think as deeply about these issues, please read the Fiedler et al. paper!

          Comment


          • #6
            Clyde, Erik, and Bruce-Thank you very much for taking the time to reply and for your advice. I will do some additional investigation to understand gsem and will read the Fielder article as well. For reference, here is a basic form of the coding I used:
            xtmixed DV IV1 IV2 IV3 IV4 IV5 IV6 IV7 M CV1 CV2 CV3 || firm_id:
            xtmixed M IV1 IV2 IV3 IV4 IV5 IV6 IV7 CV1 CV2 CV3 || firm_id:
            These two models ran. Then I tried the following after installating the mediation module using command ssc install mediation
            mediate (xtmixed DV IV1 IV2 IV3 IV4 IV5 IV6 IV7 M CV1 CV2 CV3 || firm_id /// (xtmixed M IV1 IV2 IV3 IV4 IV5 IV6 IV7 CV1 CV2 CV3 || firm_id
            Regards,
            Scott

            Comment


            • #7
              No problem, Scott Henry. Just to be clear, the command is ml_mediation. The first page I linked has the details on the syntax and how to use it appropriately.

              Also, you mention that your mediator is measured at the country level. Does that mean that all firms in the same country have the same value for the mediator? If so, you cannot use mixed to analyze the association between the key IV and the mediator. You would need to use either gsem, as Clyde noted, or ml_mediation, which will use xtreg, be for both the outcome and mediator model.

              Comment


              • #8
                Erik, ty once again. Yes, all firms have the same country-level value for the mediator. Ty for pointing out my error. To ensure I understand, you are stating the syntax needs to be:
                ml mediation (xtreg DV IV1 IV2 IV3 IV4 IV5 IV6 IV7 M CV1 CV2 CV3 || firm_id /// (xtreg M IV1 IV2 IV3 IV4 IV5 IV6 IV7 CV1 CV2 CV3 || firm_id.
                I'll read up on the linked details as well. Thx to Bruce too for recommending the Fielder article. Very helpful.

                Comment


                • #9
                  Originally posted by Scott Henry View Post
                  Thx to Bruce too for recommending the Fielder article. Very helpful.
                  YW. But note that it is Fiedler, not Fielder.
                  --
                  Bruce Weaver
                  Email: [email protected]
                  Version: Stata/MP 18.5 (Windows)

                  Comment


                  • #10
                    right!

                    Comment


                    • #11
                      Erik, I was able to download ml_mediation and then get it to run for one of my IVs. Question: can it analyze multiple IVs at one time, or does each have to be run separately? It would seem to be the latter based on the syntax and the documentation in the associated linked file. Ty, Scott.

                      Comment


                      • #12
                        You should be able to include multiple IVs:
                        Code:
                        ml_mediation, dv(DV) iv(IV1 IV2 IV3 IV4) mv(MV) l2id(ID)

                        Comment


                        • #13
                          THX! I tried dong multiple but I had different syntax. I'll give this a try. Much appreciated.

                          Comment


                          • #14
                            Following up on #3,
                            Code:
                            search ml_mediation
                            found Ender's ml_mediation package for me, and I was able to install it in the usual way with no need to download a zip file. Anyone wanting to install it can give this a try:
                            Code:
                            net install ml_mediation.pkg

                            --
                            Bruce Weaver
                            Email: [email protected]
                            Version: Stata/MP 18.5 (Windows)

                            Comment


                            • #15
                              Erik, unless I am doing something wrong, there is no way to do more than one IV concurrently, I started with all 7, and then removed one each time until only one was left. Any time there was more than one (i.e., 6 IVs, 5, 4, 3, 2), Stata provided an r(103) error message -- iv(): too many variables specified. This concerned me bc I had not run ml_mediation with the CVs yet. However, the same limitation does not exist with the CVs. I was able to include all of them with the following syntax - cv(CV1 CV2, CV3, CV4) as long as there was only 1 IV. I ran each IV independently without issue. Let me know if you have any other suggestions for what I may be missing. I haven't tried the bootstrapping yet to get standard errors or confidence intervals. -- Scott

                              Comment

                              Working...
                              X