Announcement

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

  • Overlay issue with "graph hbar......"

    Dear Statalist,
    I have 2 queries on using graph bar - i) I am trying to produce a graph that will also show the average estimate of the variable "totrep_inunit" across the overlay variable "nrgindex" categories - but Stata does not allow it i.e. I can not add any suboption (e.g. total) in the "over()" syntax. Please see code below:

    #delimit ;
    graph hbar (mean) totrep_inunit , nofill over(nrgindex, sort(1) descending label(labcolor(navy) valuelabel labsize(*.3)) axis(lcolor(emerald))) blabel(bar, color(navy) size(tiny) format(%3.0f))
    ylabel(`mylaby', ang(h)labsize(tiny) labcolor(navy) tlcolor(navy) tstyle(minor)) yscale(lcolor(emerald))
    ytitle("Average time (minutes)", size(vsmall) color(navy)) intensity(*0.7)
    title("Average reporting time per form", size(medsmall) color(navy) span)
    subtitle("`string' MONTHYLY reporting forms", size(small) color(maroon) span)
    note("Source: Time & Motion 2016", size(tiny) span) saving(time1) legend(size(vsmall));
    saving(time1, replace)

    Any ideas would be most welcomed - ii) I am also getting an error message with the "saving()" option as "file time1.gph could not be opened"....
    Thanks very much in advance.
    Best,
    Amani

  • #2
    One way to add the total to hbar is by expanding the data, see the example below. In the example I assumed that the name of the value label of nrgindex is the same as the variable name, if not, just change that part.

    Code:
    cd "`:environment USERPROFILE'\Desktop" //change the directory to one that you have permission to write, this will solve your second problem.
        g id=_n
        expand 2
        su nrgindex
        bys id: replace nrgindex=`=r(max)+1' if _n==_N
        label define nrgindex `=r(max)+1' "Total", add
    
    #delimit ;
    graph hbar (mean) totrep_inunit , nofill over(nrgindex, sort(1) descending label(labcolor(navy) valuelabel labsize(*.3)) axis(lcolor(emerald))) blabel(bar, color(navy) size(tiny) format(%3.0f))
    ylabel(`mylaby', ang(h)labsize(tiny) labcolor(navy) tlcolor(navy) tstyle(minor)) yscale(lcolor(emerald))
    ytitle("Average time (minutes)", size(vsmall) color(navy)) intensity(*0.7)
    title("Average reporting time per form", size(medsmall) color(navy) span)
    subtitle("`string' MONTHYLY reporting forms", size(small) color(maroon) span)
    note("Source: Time & Motion 2016", size(tiny) span)saving(time1, replace) legend(size(vsmall));
    
        bys id: drop if _n==_N

    Comment


    • #3
      Great thanks Oded, works like magic, just one change needed to the label define syntax, as follows "label define nrgindex `=r(max)+1' "Total", modify"
      I think the folks developing future versions of "graph bar..." may consider adding the "total" suboption to "over()" as is with "by()".....same logic I guess.
      Tons of thanks.
      Amani

      Comment


      • #4
        See also http://www.stata-journal.com/article...article=gr0058 (requires subscription access until Q1 2017).

        Comment


        • #5
          Amani Siyam , I agree with your advice to improve hbar, it seems like this option must be there. Anyway, these kind of graphs I prefer to do with towway graph. It is much more powerful and flexible tool.

          Comment

          Working...
          X