Announcement

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

  • Two-side bar chart over groups


    hello everyone,

    I've created the following graph in excel and I'd like to do it with Stata, however I'm struggling without success and I'd like to ask your help if possible.
    Here is my data:
    IMPORTANCE ASSOCIATION IMPORTANCE ASSOCIATION
    CHARACTERISTIC
    MALE MALE FEMALE FEMALE
    C1 80 61 88 50
    C2 80 67 70 41
    C3 60 60 70 50
    C4 56 45 65 21
    C5 71 75 60 73
    C6 50 33 66 19
    C7 71 80 56 80
    C8 44 51 53 45
    and here is the graph I want:
    Click image for larger version

Name:	Picture 1.png
Views:	2
Size:	20.8 KB
ID:	1563107

    I have tried the two-way command but I cannot create the spaces between the bars, they are consecutive, and also I tried the graph bar command, but without success again.
    Any advice would be much appreciated.

    Thank you inn advance.
    Best
    Attached Files
    Last edited by Lina Massou; 12 Jul 2020, 16:19.

  • #2
    Your solution in MS Excel appears to hinge on a fudge whereby the leftmost bars start at about 15 (exactly where is impossible to say, as I can't see any axis ticks except for 0). Also, I can't follow the logic of your colour scheme.

    Yet further, no reader I can imagine wants to see text like "C1" and "C2". You may have suppressed more informative text as irrelevant to your problem and/or sensitive in a public post. If so, fair enough, but your design won't be improved by longer text in the gully between the bars.

    Back-to-back bars are popular especially for showing age and sex structure in population pyramids, but precisely why I find difficult to say. I can only diagnose it as tradition being followed rather than good logic.

    There is some discussion and a pertinent reference within https://www.statalist.org/forums/for...oway-bar-graph

    If the comparison between males and females is interesting and important, don't oblige readers to try the very difficult task of comparing bars in quite different places.

    After 31 posts over 5 years you should know about our request to use data examples that are Stata code. The advice at https://www.statalist.org/forums/help#stata is key

    I took your data and tried something quite different.

    Code:
    clear 
    input str2 whatever imp_male ass_male imp_female ass_female
    C1    80    61    88    50
    C2    80    67    70    41
    C3    60    60    70    50
    C4    56    45    65    21
    C5    71    75    60    73
    C6    50    33    66    19
    C7    71    80    56    80
    C8    44    51    53    45
    end 
    
    reshape long imp_ ass_ , i(whatever) j(gender) string
    rename (imp_  ass_) (yimportance yassociation) 
    reshape long y, i(whatever gender) j(which) string
    
    set scheme s1color 
    
    local lopts linetype(line) lines(lc(gs12) lw(vthin))  
    
    graph dot (asis) y, over(gender) over(which) over(whatever) ///
    marker(1, ms(+) mc(orange)) marker(2, ms(Oh) mc(blue))      ///
    legend(pos(12)) ysc(alt) `lopts' name(G1, replace)
    
    bysort whatever which (gender) : gen difference = y[2] - y[1] if _n == 1 
    
    separate difference, by(difference >= 0)
    label var difference1 "male {&ge} female"
    label var difference0 "female > male"
    graph dot (asis) difference? if difference < ., over(which) over(whatever) name(G2, replace) ///
    marker(1, ms(+) mc(orange)) marker(2, ms(Oh) mc(blue)) `lopts' yli(0, lc(red) lw(vthin))
    The first graph just shows the data as you give them but in a different way that allows easier comparison. Naturally there is scope for more informative text than "C1", "C2", etc. and (as important in some ways) to sort the categories differently. The detail that O and + allow overlap or even occlusion is worth flagging.

    Click image for larger version

Name:	massou_G1.png
Views:	1
Size:	31.8 KB
ID:	1563175

    The second graph shows the differences directly.


    Click image for larger version

Name:	massou_G2.png
Views:	1
Size:	31.9 KB
ID:	1563176

    These graphs are just examples. What works best will hinge on what you most want to compare, association vs importance. characteristics or male and female.

    Comment


    • #3
      Dear Nick,

      Thank you very much for your reply. Apolοgies for the way that I provided the data, but I couldn't make it run in a Stata format - I'll practice myself harder and do it for my next post.
      As for the C1 labelling, yes, I used this way because of sensitivity to public post. The graphs that you produced are very interesting and useful, I'll try to convince the "boss" of this study about their advantages compared to the bar chart.
      Many thanks again.

      Best wishes,
      Lina

      Comment

      Working...
      X