Announcement

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

  • marginsplot label configuration and confidence intervals

    Hello,
    I'm working on a marginsplot graph, but I'm unable to set the label as I would like.

    Consider the following example:

    Code:
    clear all
    webuse nhanes2d
    
    probit highbp height weight age female
    
    margins,dydx(weight) at(weight=(53.52(10)91.63) female=(0 1))
    
    marginsplot, scheme(s2color) graphregion(color(white)) ///
        legend(region(color(white))) legend(order(1 "Males" 2 "Females")) ///
        xtitle("Weight") title("")
    The above marginsplot results in the following image (Figure 1).

    Click image for larger version

Name:	grg1.png
Views:	1
Size:	55.5 KB
ID:	1663891

    Now, I would like this graph in grays, which means that the label can't be two lines using different colors.
    Thus, I've attempted the following (Figure 2):

    Code:
    marginsplot, scheme(s2color) recast(line) noci plot1opts(lcolor(black) lpattern(shortdash)) plot2opts(lcolor(black) lpattern(longdash)) ///
        legend(region(color(white))) legend(order(1 "Males" 2 "Females")) ///
        xtitle("Weight") title("")
    Resulting in:
    Click image for larger version

Name:	g2.png
Views:	1
Size:	52.8 KB
ID:	1663892

    Which would be what I intend, but the confidence intervals are missing, thus, a 3rd attempt (Figure 3):

    Code:
    marginsplot, scheme(s2color) recast(line) plot1opts(lcolor(black) lpattern(shortdash)) plot2opts(lcolor(black) lpattern(longdash)) ///
        legend(region(color(white))) legend(order(1 "Males" 2 "Females")) ///
        xtitle("Weight") title("")
    Click image for larger version

Name:	g3.png
Views:	1
Size:	55.5 KB
ID:	1663895

    Which doesn't work, because the confidence intervals are colored and the label below the X axis represents the confidence intervals instead of the marginal effects. My intended result would be for the confidence intervals to be used dashed lines like the marginal effects, or simply solid black lines, and the label of the graph to be as in Figure 2.

    I hope this wasn't confusing.

    Thanks very much for your time!
    Hélder Costa
    Last edited by Helder Costa; 10 May 2022, 11:44.

  • #2
    You need to use the -ci#opt()- as well:

    Code:
    margins,dydx(weight) at(weight=(53.52(10)91.63) female=(0 1))
    marginsplot, recast(line) plot1opts(lcolor(black) lpattern(shortdash))  /// 
        plot2opts(lcolor(black) lpattern(longdash)) /// 
        ci1opt(lcolor(black) lpattern(shortdash)) /// 
        ci2opt(lcolor(black) lpattern(longdash))
    Click image for larger version

Name:	marginalexample.png
Views:	1
Size:	39.2 KB
ID:	1663921

    Comment


    • #3
      Thank you Scott Merryman, that was exactly what I was looking for!

      Comment

      Working...
      X