Announcement

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

  • Setting bin size for histogram

    I want to create a twoway histogram like the one here: https://stats.idre.ucla.edu/wp-conte.../02/histo3.png
    Click image for larger version

Name:	twoway.png
Views:	1
Size:	24.8 KB
ID:	1415859



    I am comparing certified and non-certified teachers on a construct I have called "relationships." My code looks like this:

    twoway (histogram relationship if altcert==1, frequency start(2) bin(3) color(green)) ///
    (histogram relationship if altcert==0, frequency start(2) bin(3) ///
    fcolor(none) lcolor(black)), legend(order(1 "alt cert" 2 "traditional" ))

    The result is that I get a histogram that looks like this: https://imgur.com/a/lhTgn
    Click image for larger version

Name:	twoway1.PNG
Views:	1
Size:	28.0 KB
ID:	1415861


    I want 3 bins that are the same width for both groups. The first one being 2.00-2.74, the second 2.75-2.99, the third being 3-4.
    Attached Files
    Last edited by Ian Kingsbury; 24 Oct 2017, 09:35.

  • #2
    If you want unequal bin widths, you have to leave histogram behind. You need to calculate density yourself and then draw a graph with twoway bar. See also

    SJ-15-1 gr0063 . . . . . Stata tip 122: Variable bar widths in two-way graphs
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B. Jann
    Q1/15 SJ 15(1):316--318 (no commands)
    highlights the bartype(spanning) option of the twoway bar
    command, an undocumented feature that can be used to produce
    bars of different widths

    and its references.

    Otherwise, I presume you're obliged to do this for reasons beyond your control!

    Comment

    Working...
    X