Announcement

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

  • Graph hbar for multiple binary variables

    Hi,

    I'm trying to build a graph of multiple binary variables like the one attached. I've tried the simple graph hbar but I'm interested in getting the % (and using the "percent" command adds them all to 100). I'm also struggling with the format. Thanks for any insight!

    Ines

    Attached Files

  • #2
    Please show us a data example and the exact code you're trying. https://www.statalist.org/forums/help#stata applies.

    (If the graph is your work, note that "dissabilities" is a typo.)

    EDIT: This may help. You need statplot from SSC by eric_a_booth and friend.

    Code:
    webuse nlswork, clear
    
    preserve 
    
    label var collgrad "college graduate" 
    label var not_smsa "not SMSA" 
    label var south "from South" 
    label var c_city "central city" 
    foreach v in collgrad not_smsa south c_city { 
        replace `v' = `v' * 100 
    }
    statplot collgrad not_smsa south c_city, ysc(alt r(. 45)) yla(none) ytitle(percent) blabel(bar, format(%2.1f)) 
    
    restore
    Click image for larger version

Name:	statplot3.png
Views:	1
Size:	13.3 KB
ID:	1425949
    Last edited by Nick Cox; 16 Jan 2018, 05:17.

    Comment


    • #3
      Nick,

      Thanks a lot for the prompt reply. I have data from about 100 development programs, including whether programs target people below $1.90, youth, people with disabilities, etc. For example:
      obj_pov obj_foodsec obj_incself obj_wage_empl lead
      1 1 1 0 Government
      1 1 0 1 NGO
      1 1 0 1 NGO
      0 1 0 0 NGO
      1 0 1 0 NGO
      1 1 1 0 NGO
      1 1 1 1 Government
      1 0 1 0 Government
      1 1 1 0 Government
      I started with the basic graph hbar: graph hbar obj_*, ascategory bargap(25) yla(0 0.2 "20" 0.4 "40" 0.6 "60" 0.8 "80" 1 "100")
      and then tried changing the default options but without success. I tried your suggestion and it worked, thanks! I was just wondering whether the same would be possible using the graph hbar function...?

      I also wanted to look at this by type of lead organization (reporting the number of programs not percentage), as shown below.

      Many thanks in advance!


      Inés
      Attached Files

      Comment


      • #4
        It's indeed possible with the graph hbar command (not function) but you need a reshaping of the dataset first, because that is what statplot does here.

        Comment


        • #5
          Thanks Nick and apologies for the rather basic questions and typos. I'm slowly getting back into using stata, after more than a decade!

          Comment


          • #6
            It seems you'll need the - stack - option as well.
            Best regards,

            Marcos

            Comment


            • #7
              Thanks Marcos, is that for the second graph I was talking about, i.e. where I want to look at number of programs targeting different groups by type of lead organization?

              Comment


              • #8
                Hello Ines, I meant the graph shown in #3.
                Best regards,

                Marcos

                Comment

                Working...
                X