Announcement

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

  • gsem/nlcom: Transformation from unstandardized coefficients to odds ratios?

    Hi,

    I need your help. I seek to do a mediation analysis via the gsem command in Stata 14. What I try to manage is to get Stata to output odds ratios instead of unstandardized coefficients. This easily works for my main model via estat eform, but not for the “manually”, post-estimated direct, indirect and total effects.


    The syntax of the main model is:

    gsem (isced -> ph, family(bernoulli) link(logit)) (isced -> mh, family(bernoulli) link(logit)) (isced -> schm_wö30d, family(bernoulli) link(logit)) (isced -> schlber_wö30d, family(bernoulli) link(logit)) (ph -> schm_wö30d, family(bernoulli) link(logit)) (ph -> schlber_wö30d, family(bernoulli) link(logit)) (mh -> schm_wö30d, family(bernoulli) link(logit)) (mh -> schlber_wö30d, family(bernoulli) link(logit)) [pweight = gewichtung], nocapslatent

    [Explanation: isced=educational level (ordinal, 3 groups: low, medium, high); ph=physical health (binary: 0, 1); mh=mental health (binary: 0, 1); schm_wö30d=weekly anagesics use (binary: 0, 1), schlber_wö30d=weekly sedatives use (binary: 0, 1)]

    In order to test if ph and/or mh has a mediating effect on the relation between isced and schm_wö30d or schlber_wö30d, I “manually” calculated direct, indirect and total effects via nlcom, as you can see in the following:

    ***ph -> schm_wö30d***
    *direct effect
    nlcom _b[schm_wö30d:isced]

    *indirect effect
    nlcom _b[schm_wö30d:ph]*_b[ph:isced]

    *total effect
    nlcom _b[schm_wö30d:isced]+_b[schm_wö30d:ph]*_b[ph:isced]+_b[schm_wö30d:mh]*_b[mh:isced]


    ***ph -> schlber_wö30d***
    *direct effect
    nlcom _b[schlber_wö30d:isced]

    *indirect effect
    nlcom _b[schlber_wö30d:ph]*_b[ph:isced]

    *total effect
    nlcom _b[schlber_wö30d:isced]+_b[schlber_wö30d:ph]*_b[ph:isced]+_b[schlber_wö30d:mh]*_b[mh:isced]


    ***mh -> schm_wö30d***
    *direct effect
    nlcom _b[schm_wö30d:isced]

    *indirect effect
    nlcom _b[schm_wö30d:mh]*_b[mh:isced]

    *total effect
    nlcom _b[schm_wö30d:isced]+_b[schm_wö30d:mh]*_b[mh:isced]+_b[schm_wö30d:ph]*_b[ph:isced]


    ***mh -> schlber_wö30d***
    *direct effect
    nlcom _b[schlber_wö30d:isced]

    *indirect effect
    nlcom _b[schlber_wö30d:mh]*_b[mh:isced]

    *total effect
    nlcom _b[schlber_wö30d:isced]+_b[schlber_wö30d:mh]*_b[mh:isced]+_b[schlber_wö30d:ph]*_b[ph:isced]


    According to the estat eform command, I now seek to transform the coefficients which I produced via nlcom from unstandardized coefficients to odds ratios.

    I tried to solve this via injecting exp(…) into the nlcom command (e.g. nlcom exp(_b[schm_wö30d:ph]*_b[ph:isced])), but unfortunately this seems to be the wrong way (p-values and ci’s of direct effects differ from those in the main model)…

    Is there a way to correctly transform the coefficients from unstandardized to odds ratios (or to output OR’s directly)?

    Or is there a better way to do this mediation analysis in Stata, e.g. via the svy-prefix?

    Many many thanks in advance for your help!

  • #2
    No, I think you were on the right track putting exp() into the -nlcom- command. I think your expectations about the CIs and p-values are wrong. If you change a coefficient of, say, 0.5 (95% CI 0.4 to 0.6) to exp(0.5) = 1.65, then, of course, the 95% CI is now going to be exp(0.4) = 1.49, to exp(0.6) = 1.82. The original CI of 0.4 to 0.6 wouldn't even contain the estimated exponentiated value. As for the p-values, the p-value in the output of nlcom tests the hypothesis that the calculated statistic equals zero. When you exponentiate, then it is meaningless to test whether the result equals zero as exponentials can never take on a zero value. The meaningful null test would be whether the exponentiated result equals 1, but that is not calculated in -nlcom-.

    If you really need those p-values, then you should run -nlcom- both with and without the exp(). The p-value for the unexponentiated version is equvalent to a test of the hypothesis that the exponentiated version equals 1, so you can use the p-value from the unexponentiated version.
    Last edited by Clyde Schechter; 29 Mar 2016, 10:34.

    Comment


    • #3
      Thank you so much for your comment, this definitely helps!

      Comment


      • #4
        Hi Julian and Clyde,

        I am trying to do the exact same thing and my main model worked fine following the code Julian posted, but when I then try to calculate the direct and indirect effects still following his code, I get an error message.

        Basically I am trying to identify the effects of liberal-authoritarian values (scale), left-right economic values (scale), having a degree (dummy) on vote choice (categorical), where degree would be my mediator.

        Here's all the codes:

        Main model:
        Code:
        gsem (lr1 -> degree2, family(bernoulli) link(logit)) (lr1 -> vote, family(multinomial) link(logit)) (libauth -> degree2, family(bernoulli) link(logit)) (libauth -> vote, family(multinomial) link(logit)) (degree2 -> vote, family(multinomial) link(logit))
        Attempt at nlcom:
        Code:
        nlcom _b[vote:libauth]
        Error message:
        Code:
        equation vote not found
        I don't think you've specified an equation in your code so I don't understand what's happening. Am I missing something you haven't reported, or does nlcom not work if my outcome is categorical...?

        Hope you can help me!

        Best wishes,

        Laura

        Comment


        • #5
          Dear Laura,
          I am working around a similar problem and was just wondering if it's even possible to calculate indirect effect when the paths are not estimated using the same link (but apparently it is).

          Laura, I tried to replicate your problem with my data, but it works just fine. Would you be so kind as to share the estimation results from your model?

          Best wishes,
          Leonie

          Comment


          • #6
            Originally posted by Laura Serra View Post
            Hi Julian and Clyde,

            I am trying to do the exact same thing and my main model worked fine following the code Julian posted, but when I then try to calculate the direct and indirect effects still following his code, I get an error message.

            Basically I am trying to identify the effects of liberal-authoritarian values (scale), left-right economic values (scale), having a degree (dummy) on vote choice (categorical), where degree would be my mediator.

            Here's all the codes:

            Main model:
            Code:
            gsem (lr1 -> degree2, family(bernoulli) link(logit)) (lr1 -> vote, family(multinomial) link(logit)) (libauth -> degree2, family(bernoulli) link(logit)) (libauth -> vote, family(multinomial) link(logit)) (degree2 -> vote, family(multinomial) link(logit))
            Attempt at nlcom:
            Code:
            nlcom _b[vote:libauth]
            Error message:
            Code:
            equation vote not found
            I don't think you've specified an equation in your code so I don't understand what's happening. Am I missing something you haven't reported, or does nlcom not work if my outcome is categorical...?

            Hope you can help me!

            Best wishes,

            Laura
            Dear Laura,
            I have the same "not found" problem as you posted. Have you found any solution on it?

            Comment


            • #7
              You do not show your code, so it is not possible to give specific advice for your situation. In the case of the code in the message you quote, the name being used in the -nlcom- command is backwards. It should be _b[libauth:vote]. Perhaps you are making a similar error.

              More generally, with any of Stata's estimation commands, it can be difficult to know exactly how to refer to a coefficient. The way to find out it, after running the original estimation, run the command again with the -coefl- option. For example, run -gsem, coefl- in the instance you quote. The results table will be replayed with the coefficients themselves, but instead of the uncertainty measures and test statistics, you will get a listing of the names to use to refer to the coefficients subsequently.

              Comment


              • #8
                Originally posted by Clyde Schechter View Post
                You do not show your code, so it is not possible to give specific advice for your situation. In the case of the code in the message you quote, the name being used in the -nlcom- command is backwards. It should be _b[libauth:vote]. Perhaps you are making a similar error.

                More generally, with any of Stata's estimation commands, it can be difficult to know exactly how to refer to a coefficient. The way to find out it, after running the original estimation, run the command again with the -coefl- option. For example, run -gsem, coefl- in the instance you quote. The results table will be replayed with the coefficients themselves, but instead of the uncertainty measures and test statistics, you will get a listing of the names to use to refer to the coefficients subsequently.
                Hi Schechter,
                Thank you very much for your reply!
                I have tried to check if my codes also have such issue about backwards, but seems that's not the point


                I will add my variables and codes:
                The independent variable is: eisced, categorical variable
                The dependent variabel is: ifredu, continuous variable
                The mediate variable is: equity, categorical variable.
                The control variable is: CV, catrgorical variable

                I would like to do:
                Code:
                 gsem (i.eisced  i.CV -> equityrec , family(multinomial)link(logit)) ///
                             (i.equity i.CV ->ifredu) ///
                             (i.eisced i.equity i.CV -> ifredu) [pw=pweight], nocapslatent vce(robust)
                
                            *direct effect
                            nlcom _b[eisced: ifredu]
                            *indirect effect
                            nlcom _b[eisced:equity] * _b[equity:ifredu]
                The error message said: equation eisced not found

                I'm doubting if I have wrote the whole GSEM codes wrong, or have any misunderstand about the -nlcom- when using it in testing (in-)direct effects... ((
                Thank you a lot again!
                Last edited by Chenru Hou; 02 Aug 2021, 06:10.

                Comment


                • #9
                  how do you know that "seems not the point" - your nlcom code does appear to have things backward; you can check by using the "coeflegend" option in your gsem command (or replay as that's all you really need); see
                  Code:
                  help gsem_reporting_options
                  help nlcom

                  Comment


                  • #10
                    Originally posted by Rich Goldstein View Post
                    how do you know that "seems not the point" - your nlcom code does appear to have things backward; you can check by using the "coeflegend" option in your gsem command (or replay as that's all you really need); see
                    Code:
                    help gsem_reporting_options
                    help nlcom
                    Thank you Goldstein! I have found my mistake with -coeflegend-

                    The mistake is: since my IV&MV are categorical variable, they are no more [IV: DV], rather have to be used following each category separately when using -nlcom-; that is, the results of -coeflegend- presents it is [1.IV: 1.DV] [1.IV:2.DV] and so on.

                    Comment

                    Working...
                    X