Announcement

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

  • Bar chrat for categorical variables

    Hello,

    I'm using STATA 12

    I successfully used the catplot command to compare the percentage of patients with obesity in females & males ( graph is attached)
    the command was:
    catplot gender obese, percent (gender) asyvars recast (bar)

    I want the graph to include the percentage in total ( male, female, total). I've also included in the attachment the way I want the graph to look.

    Any hints on how to do that?
    Attached Files

  • #2
    Maybe you can generate another variable total = male + female to use in the plot, rather than looking for an option that would generate it for you?

    Comment


    • #3
      I'm travelling right now and can not give full support to -catplot- (SSC) but you can call up the options of -graph bar- to show totals.

      Comment


      • #4
        Originally posted by Nick Cox View Post
        I'm travelling right now and can not give full support to -catplot- (SSC) but you can call up the options of -graph bar- to show totals.
        Thank you Nick, unfortunately I couldn't figure out how to do it by graph bar.I want the outcome to look like the following graph ( with percentage in each categories an total)

        Comment


        • #5
          Originally posted by Dave Airey View Post
          Maybe you can generate another variable total = male + female to use in the plot, rather than looking for an option that would generate it for you?
          Thank you Dave, I tried doing that but it didn't work

          Comment


          • #6
            Here is one way to add the total to the graph, I do it by duplicating the data and treat the new add observations as the total group. Just be aware to drop the added observations after producing the chart.

            Code:
            sysuse auto, clear
            su price
            g high_p=price>r(mean)
            g id=_n
            expand 2
            bys id: g d2=_n
            replace foreign=2 if d2==2
            la de origin 2 "Total", add
            
            
            catplot high_p foreign, percent (foreign) asyvars recast (bar)

            Comment


            • #7
              I gather that, if you generete a variable with the percentage, than you can generate it also "by" gender. The overall percentage would become your "total". The graphic could than be created with direct bar graph commands.
              Best regards,

              Marcos

              Comment


              • #8
                Originally posted by Oded Mcdossi View Post
                Here is one way to add the total to the graph, I do it by duplicating the data and treat the new add observations as the total group. Just be aware to drop the added observations after producing the chart.

                Code:
                sysuse auto, clear
                su price
                g high_p=price>r(mean)
                g id=_n
                expand 2
                bys id: g d2=_n
                replace foreign=2 if d2==2
                la de origin 2 "Total", add
                
                
                catplot high_p foreign, percent (foreign) asyvars recast (bar)
                Thank you very much Oded, it worked

                Comment

                Working...
                X