Announcement

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

  • How to calculate interaction effect with categorical outcomes (mlogit)

    Hi all,

    I am doing moderation analyses, with mlogit SES (1. low, 2. Med, 3. high) education gender gender*education. Where both my predictor (education) and moderator (gender) are binary variables, and my outcome variable is categorical variable.

    I can't use adjust, by () exp for mlogit (only works for logit regression).

    What else can I do to calculate the interaction effect of gender?

    Thank you!

  • #2
    The term "interaction effect of gender" sounds like a contradiction in terms. I presume you mean the marginal effects of gender at each level of education. Redo your -mlogit- command using factor-variable notation (if you didn't do it that way in the first place) and then use -margins-. See -help fvvarlist- and -help margins-.

    Code:
    mlogit SES i.education##i.gender // AND PERHAPS SOME COVARIATES
    margins education, dydx(gender)
    will give you the marginal effect of gender on the probability of SES at each level of education.

    Alternatively, perhaps you just want to test the hypothesis that gender modifies the effect of education. In that case, it's
    Code:
    testparm i.education#i.gender

    Comment


    • #3
      Dear Clyde,

      Thanks for much for your help! When I put the codes, it says "factor 'education' not found in list of covariates?"

      I wonder what is the issue.

      Thank you!
      Maggie

      Comment


      • #4
        Please show the code you used (both the -mlogit- and -margins- commands) to get this. I suspect you did not use factor variable notation correctly. Also, which version of Stata are you using?
        Last edited by Clyde Schechter; 04 Nov 2018, 18:15.

        Comment


        • #5
          Hi Clyde,

          Here is my code for my research. Health_4 is my outcome (4-group categorical outcome), ptsd_2 and vvgroup_2 are my two predictors (binary), and serveuse_2 (binary) is the moderator, and srsp_ptsd is the interaction term of ptsd_2*serveuse_2

          I am interested in the interaction effect of service use * PTSD on health_4

          My codes are:

          local control "age i.higheduc i.employ defserve"

          svy:gsem (ptsd_2 <- vvgroup_2)(i.health_4 <- ptsd_2 vvgroup_2 serveuse_2 srsp_vvgp srsp_ptsd `control') , mlogit

          margins sm_ptsd_categories, dydx(sp_servsup_used)


          Thank you!
          Maggie

          Comment


          • #6
            Do you realize that what you are showing in #5 isn't even remotely like what you asked about in #1? Why do you do that? Why did you not ask the actual question in the first place? All you did was waste your time and mine figuring out how to do something that's not what you want to do.

            First of all, you are not using the -mlogit- command, you are using the -mlogit- option to -gsem-. So the coding is different. And there isn't enough information here to respond to your original question. For example, if there is a gender variable in this model, it isn't at all obvious which one it might be. I suppose I would guess that i.higheduc is your education variable. But there is no interaction term specified between it and anything else. So I really can't understand what your code is doing and how it relates to your narrative in #1.

            That said, schematically, the code you want will look something like this:

            Code:
            svy: gsem (...) (outcome_variable <- i.gender##i.education perhaps_other_variables)), mlogit
            margins education, dydx(gender)
            In the above, everything in italics will need to be replaced by actual Stata code involving the relevant actual variables you have. And where I have written gender and education you must use the actual names of your gender and education variables, whatever those might be.


            Comment


            • #7
              Also, as discussed in another recent post, -adjust- has been superseded. It's much better to just use the -margins- command. And it's much better to use proper factor variable notation rather than manually generating interaction terms. So, you could just have typed something like (I'm using pseudocode here):

              Code:
              mlogit health_4 i.ptsd_2##i.serveuse_2 bunch_of_other_vars
              What you have is a rather more complicated specification. I am not brilliant enough to comprehend it, so I'll stick to the above example.
              Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

              When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

              Comment


              • #8
                Sorry Clyde, didn't mean to waste your time! I was using #1 as a more straightforward example, until I need to show my actual codes.

                Using the factor variable notation solved the problem!

                local control "age i.higheduc i.employ defserve"

                svy:gsem (ptsd_2 <- vvgroup_2)(i.health_4 <- i.ptsd_2##i. serveuse_2 vvgroup_2 'control') , mlogit

                margins ptsd_2, dydx(serveuse_2)

                Click image for larger version

Name:	Screen Shot 2018-11-05 at 3.18.57 pm.png
Views:	1
Size:	90.1 KB
ID:	1468923

                I suppose I can interpret the marginal effect (for predicting outcome group 1) as -.0306922/ -.1799236 = 0.17058463.

                Thank you both!

                Maggie

                Comment


                • #9
                  I suppose I can interpret the marginal effect (for predicting outcome group 1) as -.0306922/ -.1799236 = 0.17058463.
                  I don't know what you mean by this.

                  Because you are using an interaction model, there is no such thing as "the marginal effect" of serveuse2: there is one marginal effect of serveuse2 that applies when PTSD is experienced, and a different one that applies when PTSD is not experienced. The -0.0306922 and -0.1799236 are by themselves the marginal effects of serveuse2 conditional on whether or not PTSD is experienced. The difference between them may be a statistic of interest as well in some contexts, but it has no general name, and is not a marginal effect of anything.

                  In the future, please do not use screenshots to show Stata output. They are often unreadable. This one was readable on my setup, but only just barely so. The most effective way to show Stata output is the same as the most effective way to show Stata code: copy/paste it directly from your Results window or log file directly into the Forum editor between code delimiters. If you are not familiar with code delimiters, please read the Forum FAQ, with special emphasis on #12 where they are explained.

                  Comment


                  • #10
                    Ok, if I want to interpret the interaction effect of service use and PTSD (PTSD --> outcome dependent on service use), can I do the following?

                    I want to get the marginal effects of PTSD conditional on whether or not the service is used.

                    margins sp_servsup_used, dydx(sm_ptsd_categories)

                    ------------------------------------------------------------------------------------------
                    | Delta-method
                    | dy/dx Std. Err. t P>|t| [95% Conf. Interval]
                    -------------------------+----------------------------------------------------------------
                    0.sm_ptsd_categories | (base outcome)
                    -------------------------+----------------------------------------------------------------
                    1.sm_ptsd_categories |
                    _predict#sp_servsup_used |
                    1#Not used | -.195359 .0488887 -4.00 0.000 -.2912438 -.0994742
                    1#Used | -.0461276 .0588443 -0.78 0.433 -.1615382 .069283
                    2#Not used | .0759107 .0431304 1.76 0.079 -.0086804 .1605018
                    2#Used | -.0828562 .0553395 -1.50 0.135 -.191393 .0256806
                    3#Not used | .0393833 .0247372 1.59 0.112 -.0091335 .0879
                    3#Used | .0085086 .0196501 0.43 0.665 -.0300309 .0470481
                    4#Not used | .080065 .0349376 2.29 0.022 .0115424 .1485877
                    4#Used | .1204752 .0465438 2.59 0.010 .0291894 .2117611
                    ------------------------------------------------------------------------------------------

                    Can I say "the effect of PTSD on physical health (group1) is smaller among people who used service (-0.0461276) than people who did not use service (-0.195359)"?

                    Thank you!

                    Comment


                    • #11
                      Well, mathematically it is the opposite of that: -0.046... is larger (less negative) than -0.195...

                      What I think you mean is that the effects were in both cases negative and in the case of those who used service it was smaller in magnitude.

                      Comment


                      • #12
                        Originally posted by Maggie Yu View Post
                        Ok, if I want to interpret the interaction effect of service use and PTSD (PTSD --> outcome dependent on service use), can I do the following?

                        I want to get the marginal effects of PTSD conditional on whether or not the service is used.

                        margins sp_servsup_used, dydx(sm_ptsd_categories)

                        ------------------------------------------------------------------------------------------
                        | Delta-method
                        | dy/dx Std. Err. t P>|t| [95% Conf. Interval]
                        -------------------------+----------------------------------------------------------------
                        0.sm_ptsd_categories | (base outcome)
                        -------------------------+----------------------------------------------------------------
                        1.sm_ptsd_categories |
                        _predict#sp_servsup_used |
                        1#Not used | -.195359 .0488887 -4.00 0.000 -.2912438 -.0994742
                        1#Used | -.0461276 .0588443 -0.78 0.433 -.1615382 .069283
                        2#Not used | .0759107 .0431304 1.76 0.079 -.0086804 .1605018
                        2#Used | -.0828562 .0553395 -1.50 0.135 -.191393 .0256806
                        3#Not used | .0393833 .0247372 1.59 0.112 -.0091335 .0879
                        3#Used | .0085086 .0196501 0.43 0.665 -.0300309 .0470481
                        4#Not used | .080065 .0349376 2.29 0.022 .0115424 .1485877
                        4#Used | .1204752 .0465438 2.59 0.010 .0291894 .2117611
                        ------------------------------------------------------------------------------------------

                        Can I say "the effect of PTSD on physical health (group1) is smaller among people who used service (-0.0461276) than people who did not use service (-0.195359)"?

                        Thank you!
                        See how Clyde and I have put all our code in code delimiters? It turns out that you can also type your results within code delimiters, and they tend to format such that they're more easily readable on computers (doesn't work so well when I browse on my iPhone, but you can't have it all). And unfortunately, you can't retroactively copy someone else's results and try to paste them inside delimiters; it doesn't format as well. This post shows a very good example of how that works.

                        Now that we've introduced you to margins, try just typing

                        Code:
                        marginsplot
                        It should present your results graphically, and now the relative magnitudes should be a lot clearer.
                        Last edited by Weiwen Ng; 05 Nov 2018, 07:55.
                        Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

                        When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

                        Comment


                        • #13
                          Thanks a lot for helping me with margins!

                          Last question, for my continuous outcomes (e.g., overall physical health), I can't use interaction term in svy:sem. Is there a way to use margins here or do I have to try something else?

                          Code:
                           svy:sem (physum <- i.sp_servsup_used##i.sm_ptsd_categories) 
                                    margins sp_servsup_used#sm_ptsd_categories
                          Code:
                          .           svy:sem (sp_physum_sf <- i.sp_servsup_used##i.sm_ptsd_categories) 
                          (running sem on estimation sample)
                          interaction operators not allowed
                          an error occurred when svy executed sem

                          Comment


                          • #14
                            You can use -gsem- instead of -sem-.

                            Comment


                            • #15
                              Just to be clear, -sem- does not allow factor variables for unknown reasons. It's practically the first line in this page of the SEM manual (which, admittedly, is extremely long, and I bet few people have read the full manual). However, just like a GLM of the Gaussian family with an identity link is equivalent to OLS, -gsem- can fit a linear model. With standard factor variable syntax.

                              However, if the command you typed in the forum is exactly what you ran, then there's no more second equation where you estimate the effect of something on some independent variable. Why not just use -svy: regress ...- ?
                              Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

                              When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

                              Comment

                              Working...
                              X