Announcement

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

  • Plotting Histogram

    Hi I am using Stata 15. wanted to plot a simple 3 bar histogram (one each for the three countries, side by side) connecting the top ends for the data shown . Any suggestion for the code pl?
    Attached Files

  • #2
    Please do read and act on https://www.statalist.org/forums/help#stata -- which explains how to give data examples (and how not to give them, namely as images that no-one can copy and paste usefully).

    It's not even obvious that you are showing how data appear in Stata, let alone precisely how you are holding these data in Stata.

    It would be common and unsurprising to see such data shown with some kind of bar chart (whether it's called a histogram is a matter of convention, whereby if one or more axes are categorical, we tend to call the plot a bar chart (or even a column chart) and not a histogram).

    Also, these are manifestly percents that add to 100, so some people would lean towards a stacked or divided or subdivided bar chart, a design that I consider over-sold and over-valued.

    One display that is worth considering is a dot chart. Another is a particular kind of bar chart I call a multiple bar chart or table bar chart (many other names have been used). For the second, you need to install tabplot from the Stata Journal.

    There are always things that can be tweaked. The colour choices can and perhaps should be tweaked. Next time round I would zap the unnecessary axis title "Country".

    I think the multiple bar chart works better here, and (from experience) I think it works much better than a more traditional side by side or stacked bar chart would.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(Age_group Argentina Portugal Spain)
    1 40.6 38.9 27.6
    2 44.4 37.6 37.2
    3   15 23.1 35.3
    end
    label values Age_group Age_group
    label def Age_group 1 "less than 25", modify
    label def Age_group 2 "25 to 50", modify
    label def Age_group 3 "more than 50", modify
    label var Age_group "Age group"
    
    set scheme s1color 
    graph dot (asis) Argentina Portugal Spain, over(Age_group) exclude0 ///
    marker(1, ms(Oh)) marker(2, ms(Sh)) marker(3, ms(Th)) ///
    linetype(line) lines(lc(gs8) lw(vthin)) ///
    legend(row(1)) t1title(% population (?)) name(G1, replace)
    
    rename (Argentina Portugal Spain) (percent=)
    reshape long percent, i(Age_group) j(Country) string 
    
    tabplot Age_group Country [iw=percent], showval(format(%2.1f)) yreverse separate(Age_group) ///
    bar3(fcolor(blue*0.6) lcolor(blue)) bar2(fcolor(blue*0.2) lcolor(blue)) bar1(fcolor(red*0.2) lcolor(red)) name(G2, replace)
    Click image for larger version

Name:	nothistogram_G1.png
Views:	1
Size:	14.8 KB
ID:	1690801
    Click image for larger version

Name:	nothistogram_G2.png
Views:	1
Size:	15.6 KB
ID:	1690802





    Comment

    Working...
    X