Announcement

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

  • The annoying "mean of xxx" in graph bar

    Dear Stata users,

    When drawing a graph bar in Stata, if I specify the ascategory option, the label of the variable on the bar chart becomes "mean of xxx." Since I generally don't use graph bar this way—or more often use -statplot- (SSC) as an alternative—I have almost never treated this as a problem. Perhaps because I haven't used graph bar for a long time, when I needed it today for work, I found that this annoying "mean of xxx" cannot be removed through any option setting. Did I overlook some syntax explanation in the help file, or is this simply how it is? Thank you.
    P.S. -statplot- can produce very beautiful graph, below is just examples to echo graph bar, and graph combine shares part of the blame.

    Code:
    sysuse nlsw88
    graph bar (mean) wage hours ttl_exp, over(race) ascat name(bar1, replace)
    graph bar (mean) wage hours ttl_exp, over(race) name(bar2, replace)
    statplot wage hours ttl_exp, over(race) recast(bar) xpose name(bar3, replace)
    statplot wage hours ttl_exp, over(race) recast(bar) name(bar4, replace)
    graph combine bar1 bar2 bar3 bar4
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	217.9 KB
ID:	1787945

  • #2
    Hi Chen Samulsion ,

    Try adding nolabel. In your example it also works with ascategory:

    Code:
    sysuse nlsw88, clear
    graph bar (mean) wage hours ttl_exp, over(race) ascategory ///
        nolabel name(no_prefix, replace)
    This gives wage, hours and ttl_exp, without "mean of". The option is documented under legending_options, which makes its relevance to the ascategory labels less obvious.

    If you would prefer the existing variable labels, you can specify them through yvaroptions(relabel()):

    Code:
    graph bar (mean) wage hours ttl_exp, over(race) ascategory ///
        yvaroptions(relabel(1 "`: variable label wage'" ///
            2 "`: variable label hours'" 3 "`: variable label ttl_exp'") ///
            label(angle(45))) ///
        ytitle("Mean") name(var_labels, replace)
    That gives "hourly wage", "usual hours worked" and "total work experience". The angle(45) suboption is just to give the longer text more room; you can omit it or adjust it. The statistic remains the mean in both cases.

    If the longer labels remain crowded, a horizontal version gives the full text more room:

    Code:
    graph hbar (mean) wage hours ttl_exp, over(race, gap(60)) ascategory ///
        yvaroptions(relabel(1 "`: variable label wage'" ///
            2 "`: variable label hours'" 3 "`: variable label ttl_exp'") ///
            label(labsize(medsmall))) ///
        ytitle("Mean") xsize(12) ysize(9) name(ga_horizontal, replace)
    These examples worked in Stata/MP 16.1. See help graph bar, especially legending_options and the suboptions for yvaroptions(). The first line replaces the data in memory, so save any current data before running it.

    Comment


    • #3
      Dear Choonjoo Lee, thank you so much. That's new to me—I never realized nolabel had that effect. I don't think I've ever used it, as far as I can remember. Same goes for yvaroptions. Thank you!

      Comment


      • #4
        The option is documented under legending_options, which makes its relevance to the ascategory labels less obvious.
        It never would have occurred to me that an option in the legending_options group could affect the "x-axis". Of course, I know graph bar does NOT have an x-axis, but I really don't know what term to use to refer to that "position" we want to change.

        Comment


        • #5
          I too often want to remove this wording, but if (as in this example) you are asking for a reduction to means, a default title mentioning means doesn't seem that objectionable.

          Comment


          • #6
            Dear Nick Cox, thank you. If we used a title on the graph like "Mean of the xx xx xx variables," then I don't think people would be so foolish as to also label every bar with "mean of xx," "mean of xx," and so on. I don't know why the Stata programmers designed the nolabel option, but at least here, I think this option is extremely valuable.

            Comment

            Working...
            X