Announcement

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

  • Overlay histogram help

    I used Excel to create this histogram. The bin width is 5. I have several histograms to make, so help with Stata code will be greatly appreciated. Just FYI, I posted this same question here but did not get a response:
    Click image for larger version

Name:	demo_graph3 .png
Views:	2
Size:	11.1 KB
ID:	1745781


    I made up demo data if anyone wants to help me to make the graph. The demo data is only 10% of the data used to produce the Excel graph above.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str9 Race byte Diastolic
    "Not Black" -25
    "Not Black" -25
    "Not Black" -23
    "Black"     -23
    "Black"     -23
    "Black"     -20
    "Black"     -20
    "Black"     -20
    "Black"     -15
    "Not Black" -15
    "Not Black" -15
    "Not Black"  15
    "Not Black" -14
    "Not Black" -14
    "Black"     -13
    "Black"     -22
    "Black"     -15
    "Black"     -15
    "Black"     -15
    "Black"     -22
    "Black"     -22
    "Black"     -22
    "Black"     -22
    "Black"     -22
    "Black"     -22
    "Not Black" -22
    "Not Black" -22
    "Not Black" -15
    "Not Black" -15
    "Not Black"  15
    "Not Black" -10
    "Black"     -10
    "Black"     -21
    "Not Black" -21
    "Not Black" -21
    "Not Black" -21
    "Not Black" -21
    "Not Black" -21
    "Not Black" -21
    "Black"     -21
    "Black"     -21
    "Black"     -21
    "Black"     -21
    "Black"     -21
    "Black"     -21
    "Black"     -21
    "Black"     -21
    "Black"     -21
    "Not Black" -21
    "Not Black" -21
    "Not Black" -21
    "Not Black" -21
    "Not Black" -21
    "Black"     -20
    "Black"     -20
    "Not Black" -20
    "Not Black" -20
    "Not Black" -20
    "Not Black" -20
    "Not Black" -20
    "Not Black" -20
    "Black"     -20
    "Black"     -20
    "Black"     -20
    "Black"     -20
    "Black"     -20
    "Black"     -20
    "Black"     -20
    "Black"     -20
    "Black"     -20
    "Black"     -20
    "Not Black" -20
    "Not Black" -20
    "Not Black" -20
    "Not Black" -20
    "Not Black" -20
    "Not Black" -20
    "Not Black" -20
    "Black"       0
    "Black"       0
    "Black"       5
    "Black"       5
    "Black"     -19
    "Black"     -19
    "Black"     -19
    "Not Black" -19
    "Not Black" -19
    "Not Black" -19
    "Not Black" -19
    "Not Black" -19
    "Not Black" -19
    "Not Black" -19
    "Not Black" -19
    "Not Black"   0
    "Not Black"   0
    "Not Black"   0
    "Not Black"   5
    "Not Black"   5
    "Not Black"   5
    end










  • #2
    Side-by-side bars are what they are. Programmable, but here is a loosely similar idea, literally overlay, The fake data are just to get us going, understood, but they are so contrived that it's hard to know what would work well for real data.

    This may help nevertheless.

    Code:
    local params start(-25) width(5)
    
    twoway histogram Dia if Race == "Black", `params' fcolor(stc1*0.4%30) lcolor(stc1) || histogram Dia if Race != "Black", `params' fcolor(stc2*0.4%30) lcolor(stc2) legend(order(1 "Black" 2 "Not Black"))

    Comment

    Working...
    X