Announcement

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

  • weights width stacked bar graph

    Hi,
    I am trying to figure out whether it is possible to reflect the weights of the categories of a categorical variable in a stacked graph bar in the x-axis. On the x-axis, the variable is categorised in 10 units intervals (hours). The y-axis compares overtime and hours in 2nd job against the basic hours (x-axis). The code I used to plot the graph is attached.

    graph bar (mean) avg_overtimehrs ///
    (mean) avg_2ndjobhrs, ///
    over(basichrs_10bin, label(angle(vertical) labsize(small))) ///
    stack ytitle(Avg. Overtime & hours 2nd job) ///
    ytitle(, size(small) margin(medsmall)) ///
    ylabel(0(5)32, labsize(small) angle(horizontal) valuelabel) ///
    ymtick(0(1)32, labsize(small)) ///
    legend(order(1 "Overtime hours" 2 "2nd job hours") ///
    rows(2) size(medsmall) color(black) nobox region(fcolor(none) lcolor(none))) ///
    scheme(s1mono) ///
    graphregion(fcolor(none) lcolor(none) ifcolor(none) ilcolor(none)) ///
    plotregion(fcolor(none) lcolor(black) ifcolor(none) ilcolor(none))

    Thanks
    Alberto

  • #2
    It is difficult to visualize the graph based on the command alone. From your description I imagine that spineplot might be useful. See http://www.stata-journal.com/article...article=gr0031.

    Comment


    • #3
      Thanks Friedrich. I attach the original graph. The thing is on categories (last 2 on the right), sample size is very small. So I wondered whether there is any way to weight those variables and plot in the graph. I assumed there must be a way to weight the categories in the x-axis and reflect those proportions in the width.

      Click image for larger version

Name:	Screen Shot 2017-04-27 at 12.49.33.png
Views:	1
Size:	80.7 KB
ID:	1385913

      Comment


      • #4
        graph bar supports weights, as is documented

        Comment


        • #5
          Thanks Nick, I think the weights supported in the documentation are for survey weights. In my case, I want to weight the x-axis by frequency proportions (percentages) in X and Y-variables.

          Comment


          • #6
            There is no need for speculation or uncertainty here: The help http://www.stata.com/help.cgi?graph_bar documents that a f and pweights are all supported. What else are you using guidance if not the help?

            Comment


            • #7
              Alberto wants to change the width of the bars so that they indicate the number of observations in each group. graph bar [weight] is not the solution for this problem because it only affects the height of the bar segments.

              Options for drawing bars of different width include spineplot (see post #2) or twoway bar. For the latter, see this Statalist discussion.

              Comment


              • #8
                Thanks Nick and Friedrich, I think spineplot helps for my purpose.

                Comment

                Working...
                X