Announcement

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

  • Bar Graph with If condition

    Dear All,
    I want to make a bar graph of a binary variable only showing one of its value's percentage within each category of wealth.
    graph bar ut_preg [pweight = wt] , over(wealth)stack blabel(bar, format(%4.2f)) ytitle(Percent) //
    Here ut_preg is the binary 0 - Planned and 1 - unplanned pregnancy and wealth is a categorical variable taking 5 values.

    How to make a graph of percentage?
    Attached Files

  • #2
    What you have labelled Percent is presumably a proportion. The values aren't really of the order of 0.1%, are they? The mean of a binary variable over (0. 1) will be a proportion.

    Otherwise, sorry, but I can't follow what you want instead.

    Comment


    • #3
      Hi Thanks for your response. yeah exactly these are proportions but what I want is percentage. I have used your catplot as well.
      catplot ut_preg wealth [iweight = wt] , ///
      percent(wealth) by(ut_preg) asyvars blabel(bar,format(%4.2f)) ytitle(Percent) by(, title(Percent of Pregnancy Status by Wealth Quintiles) note(Source: Author's Calculation using NFHS-5:2019-21))

      What i want is the right panel in a vertical bar graph?
      Moreover, I also want to know if it is possible to scale the right panel only?
      Attached Files

      Comment


      • #4
        What i need is actually the percentage of Unintended pregnancy (% of ut_preg ==1) within each wealth quantile.

        Comment


        • #5
          So, multiply by 100 first.

          Code:
          gen ut_preg2 = 100 * ut_preg
          graph bar ut_preg2 [pweight = wt] , over(wealth) blabel(bar, format(%4.2f)) ytitle(Percent)

          Comment

          Working...
          X