Announcement

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

  • Graph bar: adding placeholder bars

    Dear Statalists

    I am using Stata 15.0. Here is the data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(BA7a BA7b) float(BA7a_copy BA7b_copy)
    3 3 3 3
    3 3 3 3
    3 3 3 3
    3 3 3 3
    3 3 3 3
    3 3 3 3
    3 3 3 3
    3 3 3 3
    3 3 3 3
    3 3 3 3
    2 3 2 3
    3 3 3 3
    3 3 3 3
    3 3 3 3
    3 3 3 3
    2 3 2 3
    3 3 3 3
    3 . 3 .
    3 3 3 3
    3 3 3 3
    end
    label values BA7a BA7a
    label values BA7b BA7b

    When i now run the following code:
    Code:
    graph bar (percent) BA7a_copy, over(BA7a) asyvars legend(size(small)) ytitle("Anteil der SchülerInnen",size(small)) name(Studiumidealistisch,replace) ylabel(1 20 40 60 80)
    graph bar (percent) BA7b_copy, asyvars over(BA7b) legend(size(small)) ytitle("Anteil der SchülerInnen", size(small)) name(Studiumrealistisch,replace) ylabel(1 20 40 60 80 100)
    Stata draws the graphs being attached (I combined them;colors are from a custom scheme being used). As you might assume already all variables were possible to have value=1 as well, which just doesn't apply for this subgroup of the dataset (while these variables' values spread from 1-3 in other subgroups). Now I want to compare the graphs of all subgroups. So so in every other group, there are three bars on each side, value=1 has a pink bar, value=2 a green bar and value=3 a lighter green bar. Just for this subgroup it's messed up. The absence of value=1 on the left side makes the colors stand for different values than usual. So it does on the right side, plus omitting the legend since only one value is left.

    So my question is: is there any way to display values with a percentage of 0, or adding placeholder bars or anything, so that the left side for example would look like

    empty space (maybe labelled with '0') green bar lighter green bar

    and the right side would look accordingly, with all values being listed in the legend (even the ones with no occurrence)?

    Thanks for your help in advance.

    Best
    Adam
    Attached Files

  • #2
    I'd back up and make this a problem for twoway bar, by() You will need a restructuring of your data to make that easy.

    graph bar isn't good at metaphysics or theology, namely showing what might exist but isn't visible in the data to hand.

    Also, the
    graph combine route is doomed in terms of easily getting consistent and minimal labelling and titling of axes.

    Comment


    • #3
      Using graph bar you could :
      Code:
      graph bar (percent) BA7b_copy, asyvars over(BA7b, reverse ) legend(size(small)) /// 
       ytitle("Anteil der SchülerInnen", size(small)) name(Studiumrealistisch,replace)  /// 
       ylabel(0 20 40 60 80 100) missing  legend(order(1 "3" 2 "2"))
      Or using twoway bar with a line at 0 for category 2:
      Code:
      collapse (count) BA7b, by(BA7b_co)
      replace BA7b_c = 2 if BA7b_c == .
      qui sum BA7b
      gen percent = (BA7b/r(sum))*100
      twoway bar percent BA7b_c , fintensity(*.5) xlabel(2 3) barw(.8)  /// 
       || scatteri 0 1.6 0 2.4, recast(line) color(538r)  /// 
       || , legend(order(1 "2" 2 "3"))

      Comment

      Working...
      X