Announcement

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

  • Variable names instead of variable labels in twoway graph legend

    If a variable has a label, twoway graph by default uses that label in the legend, which is sensible in most cases. In my data set, labels are very long, while variable names themselves are informative enough. I would thus prefer to just display the variable names in the legend. I could not find a simple option of achieving this without changing all the labels separately; is there any?
    https://www.kripfganz.de/stata/

  • #2
    I don't know of such an option but I can see easily why it might be wanted. I played with the idea of a wrapper program to do this but can't think of anything easier in practice than e.g.

    Code:
    scatter mpg weight, ytitle(mpg) xtitle(weight)
    and specific examples in say a do-file could be automated to do that, at least partially.

    Comment


    • #3
      There appears to be an option that does the job for my purpose: yvarlabel(""), documented in help advanced options:
      Code:
      scatter mpg weight, yvarlabel("") xvarlabel("")
      However, the behavior of the options yvarlabel() and xvarlabel() seems to be inconsistent. With yvarlabel(""), I indeed get the variable name as the title on the y-axis. But with xvarlabel(""), the title on the x-axis disappears entirely. The latter appears to be a bug, given what is stated in the help file:
      If you specified xvarlabel(""), for instance, the variable label would be treated as if it were nonexistent, and thus the variable name would be used to title the x axis.
      https://www.kripfganz.de/stata/

      Comment


      • #4
        Thanks for reminding me about those options. I have a dim memory of being puzzled by quite what they did and then shrugging my shoulders and moving on.

        Depends on the context, but I would much rather explain -- to students, colleagues and others -- that the general idea is just to change the axis titles to what you want if you don't like the default. After all, on the fly the variable label might be absurdly long but the variable name too cryptic and there may be a compromise that is acceptable.

        As an extreme if opposite case I favour zapping x axis titles like "year" and "date" as being usually needless information. If the reader needs "date" or "year" to understand 2001/2020 or whatever as axis labels, all is lost before you start.

        People using certain software I won't name seem oddly and widely accepting of a default of using their equivalent of variable names on graph axes, although no doubt it is not a rule. The Stata default of using variable labels you can choose has been a feature from early versions.
        Last edited by Nick Cox; 01 Feb 2023, 06:01.

        Comment


        • #5
          Would it be an idea to use label language for this?
          To create a language named short and then change the variable labels for this language only?

          Comment


          • #6
            Using label language could be a good idea. I think when people want this it is often on the fly to avoid a really awful graph. Other way round,.it is uppermost in my mind when assigning variable labels that they will appear on graph axes, so keeping them concise as well as informative is an imperative.

            Comment


            • #7
              I am trying to do this exact thing. When I tried
              Code:
              yvarlabel ("")
              unfortunately still the variable name and not variable label is displayed.

              Comment


              • #8
                I realize this is a simpler option:
                Code:
                ylabel()

                Comment

                Working...
                X