Announcement

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

  • Multiple marginal effects in one marginsplot

    Hello Statalist, i'm having some trouble with creating a marginsplot with multiple marginal effects from four bivariate logistic regressions. The regressions all have the same dependent variable but different independent variables. All variables are dichotomous. My dataset is as follows:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(fuldmægtig kontorchef afdelingschef departementschef politisering)
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    0 0 0 0 0
    0 1 0 0 0
    0 0 1 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    0 1 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    end

    Thus, i want to run four logistic regression with "politisering" as the dependent variable and the four others as independent variables and visualise the results in a marginsplot. With only one regression i would run the following commands:

    logit politisering i.fuldmægtig
    margins i.fuldmægtig
    marginsplot

    However, running all fout models and then trying to create a marginsplot only include the last regression run.

    Does anyone know how to include the marginal effects of all four models into one marginsplot?

    Any advice is much appreciated!

  • #2
    Code:
    ssc install combomarginsplot
    help combomarginsplot

    Comment


    • #3
      Hello Andrew, thanks for your response! I managed to produce a combomarginsplot by running the following commands:


      logit politisering i.fuldmægtig
      margins fuldmægtig, saving(fil1)
      logit politisering i.afdelingschef
      margins afdelingschef, saving(fil2)
      logit politisering i.kontorchef
      margins kontorchef, saving(fil3)
      logit politisering i.departementschef
      margins departementschef, saving(fil4)
      combomarginsplot fil1 fil2 fil3 fil4


      However, the produced combomarginsplot is very messy. I have attatched the graph as a file. Any idea how i can make it look better?
      Attached Files

      Comment


      • #4
        Can you run the following after your combomarginsplot command and then copy and paste the resulting dataex output here?

        Code:
        use fil1, clear
        forval i=2/4{
            recode _term (1=`i')
            append using fil`i'
        }
        dataex

        Comment


        • #5
          Here's the output:

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input byte(_deriv _term _predict _at _atopt) float(_margin _se_margin _statistic) byte _pvalue float(_ci_lb _ci_ub) byte _m1
          . 2 . . .  .4493743 .016777912 26.783684 0  .4164902  .4822584 0
          . 2 . . . .25317514 .005621136  45.03985 0  .2421579 .26419237 1
          . 3 . . .  .2716382 .005443093  49.90512 0 .26096994  .2823065 0
          . 3 . . . .51891893 .036734406 14.126236 0  .4469208 .59091705 1
          . 4 . . .  .2642395 .005608838  47.11127 0 .25324637  .2752326 0
          . 4 . . .  .4055637 .018787624  21.58675 0  .3687406 .44238675 1
          . 1 . . . .27546838 .005404937  50.96607 0  .2648749 .28606185 0
          . 1 . . .  .9032257  .05310036 17.009785 0  .7991508 1.0073004 1
          end
          label values _term _term
          label def _term 1 "fuldmægtig", modify

          Comment


          • #6
            Thanks. It's possible to offset some CIs, but there is not much overlap, so I do not see a need for that. Run in a do-file.

            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input byte(_deriv _term _predict _at _atopt) float(_margin _se_margin _statistic) byte _pvalue float(_ci_lb _ci_ub) byte _m1
            . 2 . . .  .4493743 .016777912 26.783684 0  .4164902  .4822584 0
            . 2 . . . .25317514 .005621136  45.03985 0  .2421579 .26419237 1
            . 3 . . .  .2716382 .005443093  49.90512 0 .26096994  .2823065 0
            . 3 . . . .51891893 .036734406 14.126236 0  .4469208 .59091705 1
            . 4 . . .  .2642395 .005608838  47.11127 0 .25324637  .2752326 0
            . 4 . . .  .4055637 .018787624  21.58675 0  .3687406 .44238675 1
            . 1 . . . .27546838 .005404937  50.96607 0  .2648749 .28606185 0
            . 1 . . .  .9032257  .05310036 17.009785 0  .7991508 1.0073004 1
            end
            label values _term _term
            label def _term 1 "fuldmægtig", modify
            label def _term 2 "afdelingschef", modify
            label def _term 3 "kontorchef", modify
            label def _term 4 "departementschef", modify
            
            twoway (rcap _ci_lb _ci_ub _m1 if _term==1 , sort pstyle(ci) color(green)) ///
            (connected _margin  _m1 if _term==1, lpattern(solid) lcolor(green) mcolor(green)) ///
            (rcap _ci_lb _ci_ub _m1 if _term==2 , sort pstyle(ci) color(red) ) ///
            (connected _margin  _m1 if _term==2, lpattern(dash) lcolor(red) mcolor(red)) ///
             (rcap _ci_lb _ci_ub _m1 if _term==3 , sort pstyle(ci) color(black) ) ///
            (connected _margin  _m1 if _term==3, lpattern(-.-) lcolor(black) mcolor(black)) ///
            (rcap _ci_lb _ci_ub _m1 if _term==4 , sort pstyle(ci) color(blue) ) ///
            (connected _margin  _m1 if _term==4, lpattern(__) lcolor(blue) mcolor(blue) scheme(s1color) ///
             legend(order(2 "fuldmægtig" 4 "afdelingschef" 6 "kontorchef" 8 "departementschef")) xlab(0 1) ///
            title(Adjusted Predictions with 95% CIs) ytitle(Pr(Politisering)) xtitle(""))
            Click image for larger version

Name:	Graph.png
Views:	1
Size:	56.6 KB
ID:	1666373

            Comment


            • #7
              This is perfect! Thank you so much Andrew. I really appreciate your help

              Comment

              Working...
              X