Announcement

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

  • Overlapping bars or line in a bar chart

    Dear all,

    I want to compare the data for distribution of education levels in my sample with the distribution of the basic population in a single bar chart. The two variables of interest are
    1 "bild_grp" (education level) with 1=low 2=medium 3=high and
    2 "wo" (location) with 1=western Germany 2=eastern Germany.
    The distribution of my sample data is:
    West Ost
    low 30.43% 19.80%
    medium 36.91% 52.11%
    high 32.66% 28.09%
    The known distribution for the population is:
    West Ost
    low 43.46% 22.83%
    medium 25.52% 48.73%
    high 31.02% 28.44%
    The population data however is not part of my data set but just information from public statistics. I didnt find a way to create a variable and giving it that distribution over all observations, so I created six variables - one with each value for all observations.

    Now I am trying to find any way of visualizing the two distributions in one bar chart, either with the population data being shown as horizontal lines above the bars of my sample data, or being bars as well but 'behind'/overlapping the sample data bars. (The closest I found in this forum was #3 post on Belindas thread.)

    The following line gives me the chart for my sample data:
    graph bar if status==1, over(bild_grp) over(wo) asyvars title (Bildungsabschlüsse nach Ost/West) legend(on) percent

    I learned that adding the option yline(25) would draw a horizontal line at y=25, and wondered whether I could limit the area on the a axis for every y-value, but couldnt find a way doing so.


    Hoping that you can help me out, thanks!
    Adam

  • #2
    Code:
    clear all
    input bild_grp wo data perc
    1 1 1 30.43
    2 1 1 36.91
    3 1 1 32.66
    1 0 1 19.80
    2 0 1 52.11
    3 0 1 28.09
    1 1 0 43.46
    2 1 0 25.52
    3 1 0 31.02
    1 0 0 22.83
    2 0 0 48.73
    3 0 0 28.44
    end
    
    label define bild_grp 1 "low" ///
                          2 "medium" ///
                          3 "high"
    label value bild_grp bild_grp                      
    
    label define wo 1 "West" 0 "Ost"
    label value wo wo
    
    label define data 1 "sample" 0 "population"
    label value data data
    
    gen strperc = strofreal(perc,"%3.0f")
    
    gen y = bild_grp + .1 - .2*data
    twoway dropline perc y if data == 0,              ///
               by(wo, compact note("")) horizontal || ///
           dropline perc y if data == 1, horizontal   ///
               legend(order(1 "population"            ///
                            2 "sample") col(2))       ///
                ylab(1 "low" 2 "middle" 3 "high",     ///
                     nogrid tlength(0) angle(0) )     ///
                xlab(0(20)60)                         ///
                ytitle("") xtitle("percentage")    || ///
           scatter y perc, scheme(s1mono)             ///
                msymbol(i) mlabel(strperc) mlabpos(3)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	19.3 KB
ID:	1412433

    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Great, that'll do!
      Thanks for the quick help!

      Kind regards,
      Adam

      Comment

      Working...
      X