Announcement

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

  • Cutoff in histogram

    Dear all,

    I am doing histograms and would like to emphasize with a line or mark the cutoff of 1% and 5 % in the histograms. I am assuming that this should be feasible but I have no idea how to start, any suggestions? I have attached the coding here below for the two histograms and I would like to add an option to identify 1% and 5 % cutoff in each histogram.


    histogram el_input_val_099 if inlist(treatment,0), bin(20) sort(descending) name(control,replace)
    histogram el_input_val_099 if inlist(treatment,1,2,3,4,5,6),bin(20) sort(descending) name(treatment,replace)
    gr combine control treatment, ycom xcom


    Thanks for the help!

  • #2
    Here are several options:

    Code:
    // open example data
    sysuse nlsw88, clear
    
    // collect the 1st and 5th percentiles
    // and store them in locals p1 and p5
    _pctile wage, percentile(1 5)
    local p1 = r(r1)
    local p5 = r(r2)
    
    // add vertical lines
    histogram wage, xline(`p1' `p5') name(gr1, replace)
    
    // add labels on the x-axis
    histogram wage, xmlab(`p1' "1{sup:st}" `p5' "5{sup:th}") name(gr2, replace)
    
    // combine the two
    histogram wage, xmlab(`p1' "1{sup:st}" `p5' "5{sup:th}") ///
                    xline(`p1' `p5') name(gr3, replace)
    
    // put the labels on the top axis                
    twoway histogram wage, xscale(range(0 41)) xline(`p1' `p5') ||               ///
           scatteri 0 0, msymbol(i) xaxis(2) xscale(range(0 41) axis(2))         ///
           xlab(none, axis(2)) xmlab(`p1' "1{sup:st}" `p5' "5{sup:th}", axis(2)) ///
           xtitle("percentiles", axis(2)) legend(off) name(gr4, replace)
    
    // label inside graph       
    twoway histogram wage, xline(`p1' `p5') || ///
           scatteri .145 `p1' (9) "1{sup:st}"  ///
                    .145 `p5' (3) "5{sup:th}", ///
           msymbol(i) legend(off)              ///
           name(gr5, replace)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment

    Working...
    X