Announcement

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

  • Overlapping histograms

    Hi everyone,

    I asked a Likert scale type of question to about 1,000 people, asking them to choose a value between 1 and 5, with 1 being "strongly oppose" and 5 being "strongly favor". I asked the same question twice, before and after a treatment. I would like to plot an overlapping histogram of the distribution across the 5 possible answer for before and after.

    I saw Nick suggesting something similar here (#4), but my data is different since I have two observations for each person (instead of the example with domestic/foreign).

    Any suggestion?

    Thanks!

  • #2
    No variable names here or data example, but presumably the only difference is the use of if qualifiers.


    Code:
    clear
    set obs 1000
    set seed 2803  
    gen id = ceil(_n/2)
    gen time = 2 - mod(_n, 2)
    gen answer = 1 + rbinomial(4, cond(time == 1, 0.5, 0.8))
    
    tab answer time
    
    twoway histogram answer if time == 1, freq discrete barw(0.9) lcolor(red) fcolor(red*0.2%50) || ///
    histogram answer if time == 2, freq discrete barw(0.9) lcolor(blue) fcolor(blue*0.2%50) ///
    legend(order(1 "first" 2 "second") pos(11) ring(0) col(1))

    Comment


    • #3
      Amazing, thanks Nick!

      Comment

      Working...
      X