Announcement

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

  • stacked bar graph using different totals to stata default

    Hello,

    I'm trying to make a stacked bar graph with the following variables:
    1) deciles (below it's the first column and the first decile, "1" is copied)
    2) children who are stunted - 0 indicates not stunted, 1 indicates stunting
    3) children with wasting - 0 indicates not wasted (no - I do not mean drunk...) 1 indicates wasted
    4 children who are underweight (1) or not (0)
    5) households with children (1) or without (0)

    I want to make a bar graph where deciles would be on the horizontal x axis (1-10) and y axis would indicate shares of stunted, or wasted or underweight children in reference to a number of households that have children within a given decile. I can produce a figure that would take the total number of households in the decile - but this is not what I want.

    My code is following, but it did not give right shares
    Code:
    graph bar (percent) only_stunted only_wasted underweight_and_rest if has_child_under_5==1, over(decile) stack
    To give an example, if in decile 1 we have 500 households and there are 250 households with children within this first decile, and 50 of them are stunting, then I want stata to show 50/250=20%. But with this code I have above it would show 50/500=10%. How do I fix it?

    The end result (produced in excel) should look like this:

    Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	29.1 KB
ID:	1501429


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float decile byte(only_stunted only_wasted underweight_and_rest has_child_under_5)
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    1 0 0 0 0
    end

  • #2
    Your data example isn't useful as there is no variance in any of the 5 variables. You can make up 10 observations and show what you need based on these observations.

    Comment


    • #3
      Ah sorry you're right- I sorted it by decile before and only part of the variation in the other variables showed up (I have 12 thousand observations...)
      Here is a "richer" example. I hope it helps to show what I need to do. Any help would be appreciated.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float decile byte(only_stunted only_wasted underweight_and_rest has_child_under_5)
      10 0 0 0 0
       7 0 0 0 0
       3 0 0 0 1
       2 0 0 0 0
       2 0 0 1 1
       3 0 0 0 0
       4 0 0 0 0
       2 0 0 0 0
       6 0 0 0 0
       2 0 0 0 0
       3 0 0 0 0
       7 1 0 0 1
       2 0 0 0 1
      10 0 0 0 0
       7 0 0 0 0
       8 0 0 0 0
       2 0 0 0 0
       3 0 0 0 0
       6 1 0 0 1
       1 0 0 0 0
       3 0 0 0 1
       1 0 0 0 0
       7 0 0 0 1
       4 0 0 0 0
       8 0 0 0 1
       3 0 0 0 0
       2 0 0 0 0
       2 0 0 0 0
       5 0 0 0 0
       1 1 0 0 1
       1 0 0 0 0
       2 0 0 0 0
       2 0 0 0 1
       3 0 0 0 1
       9 0 0 0 0
       7 0 0 0 0
       1 0 0 0 1
       1 0 0 0 0
       1 0 0 0 1
       4 1 0 0 1
       2 0 0 0 0
       3 0 0 0 0
       2 0 0 0 0
       7 0 0 0 0
       1 0 0 0 0
       1 1 0 0 1
       1 0 0 0 1
       6 0 0 0 0
       2 0 0 0 1
       3 1 0 0 1
       2 0 0 0 0
       1 0 0 0 0
       2 0 0 0 1
       1 1 0 0 1
       5 0 0 0 0
       7 0 0 0 0
       2 0 0 0 1
       4 0 0 0 0
       7 0 0 0 0
       1 0 0 0 0
      10 0 0 0 0
       7 0 0 0 0
       4 0 0 0 0
       1 0 0 0 0
       1 0 0 0 0
       3 0 0 0 0
       4 1 0 0 1
       4 0 0 0 1
       5 0 0 0 0
       5 1 0 0 1
       3 0 0 0 0
       7 0 0 0 0
       3 0 0 0 0
       2 0 0 0 0
       3 1 0 0 1
       3 0 0 0 0
       1 0 0 0 0
       6 1 0 0 1
       8 0 0 0 0
       1 1 0 0 1
       4 0 0 0 0
       1 0 0 1 1
       2 0 0 0 1
       4 0 0 0 0
       7 0 0 0 0
       1 0 0 0 1
       5 0 0 0 0
       2 0 0 0 1
       6 0 0 0 0
       5 0 0 0 1
       1 0 0 0 0
       3 0 0 0 1
       6 0 0 0 0
       2 0 0 0 0
       2 0 0 0 0
       1 0 0 0 0
       5 0 0 0 0
       2 0 0 0 0
       1 0 0 0 0
       6 0 1 0 1
      end

      Comment


      • #4
        I think that what you want are the means. You can change the y-axis labels to reflect percentages by multiplying by 100.

        Code:
        graph bar only_stunted only_wasted underweight_and_rest if has_child_under_5, over(decile) ///
        stack ylabel(0 "0" 0.2 "20" 0.4 "40" 0.6 "60" 0.8 "80" 1 "100") ytitle("Percent") ///
        legend(order(1 "Stunted" 2 "Wasted" 3 "Underweight and Other")) scheme(s1color)

        Comment

        Working...
        X