Announcement

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

  • Clustered bar chart

    Hello!

    I am trying to create a graph like the one below:
    Click image for larger version

Name:	IMG_8035.jpg
Views:	2
Size:	411.5 KB
ID:	1406771

    I have already created percentage summary variables using

    by change_anaemia, sort: egen pc_stunt= mean(100*stunted)

    But I am unable to cluster the bars according to the variables on the x-axis (malaria, stunting).

    I would really appreciate any help!

    Isobel




    Attached Files

  • #2
    You're now running two threads. See also https://www.statalist.org/forums/for...ered-bar-graph

    Please keep just one thread going and cross-reference in the thread you abandon.

    One comment in the other thread carries across to here. Suggested code is much more likely to be provided if you give a decent data example. For example, I have some experience with graphs of this kind but having to imagine what your data look like is too much like hard work.

    Comment


    • #3
      Hi Nick,

      Thank you for your reply. Below is an example of my data. I am using mainly binary variables.

      Change_anaemia : binary; 1= improved 0=no change
      Malaria : binary; 1=Malaria 0=no malaria
      Stunted : Binary; 1 = stunted, 0=not stunted


      My aim is to create a bar graph showing the percent of children are stunted/have malaria etc. in each of the two categories in the change_anaemia variable.

      It was suggested to me that I create percentage summary variables by using 'by change_anaemia, sort: egen pc_stunt= mean(100*stunted)' which I have done, but I have not yet been able to create a graph like the photo above



      Isobel
      Last edited by Isobel Stanley; 17 Aug 2017, 09:00.

      Comment


      • #4
        Thanks for your example.

        Disclaimer: I am no medic or medical statistician, so may mangle this in small or large details.

        1. Please close down your other thread as requested before anybody wastes any more time on that.

        2. Please use dataex (SSC) for decent data examples. This is all documented in the FAQ all members are asked to read before posting.

        3. Does stunted (#3) mean the same as stunting (#1)? I guess so, but it's a small puzzle.

        4. It's implied that having malaria and being stunted are not disjoint. That being so, you have plots for two controls side by side, They aren't separate categories of a single control, which is the usual set-up. Positively, you can look at cross-combinations too.

        5. You can do what I think you want, but it is a little tricky. You could produce separate graphs and then use graph combine.

        I'd rather use a single command, which is designplot from the Stata Journal, which you must install first. In fact, I am going to use two such graphs, one for your response and one for your counts. That is written up in http://www.stata-journal.com/article...article=gr0061 (requires subscription or purchase until 2017Q4, which is a few months away). There is no charge for downloading the code or reading the help file, which is fairly detailed.

        As I understand it, you have two controls and one response, all binary. That being so, here is sample code with completely fake data. Lots of graph choices could be varied. I find dot charts showing position on a scale natural, or at least congenial, for means and bar charts natural, or at least conventional, for counts.

        Code:
        clear
        set obs 100
        set seed 2803
        
        gen Malaria = rbeta(1, 3) > 0.1
        label def Malaria 1 "malaria" 0 "no malaria"
        label val Malaria Malaria
        
        gen stunted = rbeta(3, 1) > 0.9
        label def stunted 1 "stunting" 0 "no stunting"
        label val stunted stunted
        
        gen change_anaemia = runiform() > 0.7
        
        groups Malaria stunted change , sep(0)
        
        local opts yla(0 "0" 0.25 "25" 0.5 "50" 0.75 "75" 1 "100")  t1title(% change)
        
        designplot change Malaria stunted, `opts' name(g1, replace)
        
        designplot change Malaria stunted , recast(hbar) stat(count) ///
        name(g2, replace) blabel(total, pos(outside)) ysc(r(0, 110)) t1title(Frequencies)
        
        graph combine g2 g1
        
        * know that I used the Graph Editor to hide one set of axis labels
        Click image for larger version

Name:	designplot4.png
Views:	1
Size:	24.0 KB
ID:	1406815
        https://www.statalist.org/forums/forum/general-stata-discussion/general/4932-designplot-now-available-from-ssc-something-also-for-fans-of-descriptive-tables gives an overview of this command.
        Last edited by Nick Cox; 17 Aug 2017, 10:04.

        Comment

        Working...
        X