Announcement

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

  • -marginsplot-, -addplot-, and the below option

    Stata/BE 17.0 for Mac (Intel 64-bit) Revision 13 Oct 2022

    I am trying to combine a marginplot and a frequency histogram. I seem to be getting close to what I want, but I seem to be struggling to use addplot's below option properly. This is my current code:

    Code:
    logit txflr_yn path1_crp
    local crp_n = e(N)
    local crp_psR2: dis %6.3f e(r2_p)
    local crp_pr: di %12.7f e(p)
    
    //  Run marginal effects estimation
    margins, at(path1_crp=(0(10)400))
    
    //  Marginsplot
    marginsplot,    xdimension(path1_crp) plotopts(msymbol(none))   ///
        ytitle("Pr(Treatment Non-Response)") ///
        xtitle("C-Reactive Protein (mg/L)") ///
        title("") ///
        note("N = `crp_n'" "Pseudo R{superscript:2} = `crp_psR2'" "p = `crp_pr'") ///
        name("logit_crp", replace) ///
        recastci(rarea) ciopts(color(%50) lpat(line)) ///
        addplot((histogram path1_crp if path1_crp <450, frequency width(10) fcolor(blue%30) lcolor(blue%30) xscale(range(0 450)) yaxis(2) yscale(alt axis(2))), below)
    This is the graph:

    Click image for larger version

Name:	Screen Shot 2022-11-17 at 3.17.16 pm.png
Views:	1
Size:	168.9 KB
ID:	1689800


    It's getting very close, but I really would prefer it if the marginplot was at the top. That would seem to be the purpose of the below option.

    I know that there is a module called MARHIS, but that doesn't give me as much control over the histogram.

    Please let me know if more information is needed than I have provided.
Working...
X