Announcement

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

  • Offsetting does not work to overlay two histograms

    I did it the same way before with a different dataset, now with this dataset the bars are all over the place. Why?

    Code:
    local color1 "navy"
    local color2 "cranberry"
    local color3 "gold"
    local color4 "forest_green"
    local offset = 0.1
    
    gen temp_self = self - `offset'
    gen temp_guess = guess + `offset'
    
    #delimit ;    
    twoway
        (hist temp_self if treat==1, frac lcolor(`color1') fcolor(`color1')) ||
        (hist temp_guess if treat==1, frac fcolor(`color2') lcolor(`color2')),
        title("Panel A: 7% wage decrease due to recession", size(small))
        legend(label(1 "Own judgement") label(2 "Guessing others judgement") rows(1) pos(6))
        xlabel(1 "Sign. less" 2 "Slight. less" 3 "Same" 4 "Slight. more" 5 "Sign. more")
        plotregion(style(none)) graphregion(color(white)) bgcolor(white)
        name(recession, replace);
    #delimit cr
    The middle is completely overlaid. And if I fix the width to 0.1, then the most-left one is too distant. Why?


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(treat self guess)
    2 2 2
    3 3 3
    1 3 3
    4 4 4
    2 3 2
    3 4 3
    2 3 2
    4 3 3
    2 3 3
    3 3 4
    1 4 3
    3 4 4
    2 3 2
    4 3 2
    2 3 3
    4 4 4
    2 3 1
    3 4 3
    1 1 5
    4 4 4
    1 3 3
    3 3 4
    1 3 2
    4 3 4
    2 1 1
    4 3 3
    1 5 4
    3 5 4
    2 3 2
    4 3 4
    1 3 3
    4 4 4
    2 4 3
    3 5 3
    2 3 3
    4 3 3
    1 3 2
    4 3 4
    1 3 2
    4 3 2
    1 2 3
    3 4 4
    1 2 1
    4 4 5
    1 3 5
    4 4 5
    2 3 3
    4 3 3
    2 3 4
    4 3 4
    1 3 3
    3 3 3
    1 4 4
    3 3 3
    1 4 2
    3 5 4
    2 3 4
    4 3 3
    2 3 2
    4 4 4
    1 1 2
    4 1 2
    2 3 3
    4 3 3
    1 3 3
    3 3 3
    2 2 2
    4 4 4
    2 2 2
    3 3 3
    1 3 4
    3 3 5
    2 2 4
    4 4 3
    2 2 3
    4 4 4
    1 3 3
    4 3 3
    1 4 4
    3 2 3
    1 3 3
    3 4 4
    1 3 3
    3 4 4
    1 1 1
    4 1 1
    2 2 3
    4 4 5
    2 3 3
    3 3 4
    1 2 2
    4 3 3
    1 5 2
    3 5 4
    2 3 3
    4 4 4
    1 4 4
    3 4 4
    2 3 3
    4 3 3
    end


  • #2
    You have integer scores 1 2 3 4 5. So an offset of 0.1 leaves a lot of overlap if the bar width stays at 1. Further, the fill colour needs to use some transparency. I played around a bit but couldn't avoid an unsatisfactory outcome. And your graph shows treat == 1 only and leaves up in the air how you are going to add displays for the other 3 categories.

    Detail: others should be punctuated others' (or just possibly other's if only one other is entailed).

    I tried something different withtabplotfrom the Stata Journal. It's possible to avoid awkward abbreviations. Re-ordering predictors and showing specified percentages are among possible changes.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(treat self guess)
    2 2 2
    3 3 3
    1 3 3
    4 4 4
    2 3 2
    3 4 3
    2 3 2
    4 3 3
    2 3 3
    3 3 4
    1 4 3
    3 4 4
    2 3 2
    4 3 2
    2 3 3
    4 4 4
    2 3 1
    3 4 3
    1 1 5
    4 4 4
    1 3 3
    3 3 4
    1 3 2
    4 3 4
    2 1 1
    4 3 3
    1 5 4
    3 5 4
    2 3 2
    4 3 4
    1 3 3
    4 4 4
    2 4 3
    3 5 3
    2 3 3
    4 3 3
    1 3 2
    4 3 4
    1 3 2
    4 3 2
    1 2 3
    3 4 4
    1 2 1
    4 4 5
    1 3 5
    4 4 5
    2 3 3
    4 3 3
    2 3 4
    4 3 4
    1 3 3
    3 3 3
    1 4 4
    3 3 3
    1 4 2
    3 5 4
    2 3 4
    4 3 3
    2 3 2
    4 4 4
    1 1 2
    4 1 2
    2 3 3
    4 3 3
    1 3 3
    3 3 3
    2 2 2
    4 4 4
    2 2 2
    3 3 3
    1 3 4
    3 3 5
    2 2 4
    4 4 3
    2 2 3
    4 4 4
    1 3 3
    4 3 3
    1 4 4
    3 2 3
    1 3 3
    3 4 4
    1 3 3
    3 4 4
    1 1 1
    4 1 1
    2 2 3
    4 4 5
    2 3 3
    3 3 4
    1 2 2
    4 3 3
    1 5 2
    3 5 4
    2 3 3
    4 4 4
    1 4 4
    3 4 4
    2 3 3
    4 3 3
    end
    
    rename (self guess) Perception=
    gen id = _n
    reshape long Perception, i(id) j(which) string
    replace which = proper(which)
    
    tabplot Perception which, by(treat, row(1) note("")) showval yreverse xtitle("") sep(treat) ///
    ylabel(1 `" "Significantly" "less" "' 2 "Slightly less" 3 "Same" 4 "Slightly more" 5 `" "Significantly" "more" "')
    Click image for larger version

Name:	perception.png
Views:	1
Size:	49.0 KB
ID:	1736766

    Comment


    • #3
      Thanks! But I would have really liked to show it as a distribution. Maybe with bar graphs?

      Also, I am not sure I understood the reason. It seems really arbitrary how the bars have different offwidth for different categories. Did you get that as well? Seems very odd behavior..

      Comment


      • #4
        ??? #2 is a bar chart. If you want the bars to touch, you can arrange that. You just need to show 40 bars intelligibly.

        What do you most want to compare? That's the key question.

        Otherwise, I think you're saying that what you drew in #1 was a surprise to you. I drew a graph with your data. It didn't seem surprising to me, just fairly useless. Perhaps you're missing that the discrete option would improve the graph a little. With offsets of 0.25 and bar widths of 0.5 you would get no overlap at all, but no votes from me for that design.

        EDIT: 0.22 and 0.44 better still if you like that.

        Here is the graph from the code and data example from #1 except that I changed the fill colours to none.
        Click image for larger version

Name:	recession2.png
Views:	1
Size:	43.3 KB
ID:	1736884

        Last edited by Nick Cox; 12 Dec 2023, 09:58.

        Comment

        Working...
        X