Announcement

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

  • adding "%" to marker label

    for a line graph, I want to add marker labels showing the actual percentage at each point; this is straightforward (see code below); however, my client wants a percentage sign ("%") at the end of each such label and I don't see how to do that

    Code:
    twoway scatter pctacute dcyear if acute==1, msymbol(none) connect(l) xla(2002(1)2014) yti("Percent discharged to Acute Care") mlabel(pctacute) yla(0(.5)1.5)

  • #2
    You can just do this directly, e.g. yla(0 "0%" 0.5 "0.5%" 1 "1%" 1.5 "1.5%") as it's just fixable as text you show (absent something I once suggested to no effect, a percent display format).

    Alternatively,
    mylabels
    (SSC) has a suffix() option to ease this ... suggested by a Richard Goldstein question on Statalist. Here, such a solution would entail more typing, but it's a way of automating.

    Comment


    • #3
      thank you - and sorry for not finding my old question/answer <grin>

      note, however, that your answer refers to axis labels not marker labels; I will check whether I can generalize from your answer to marker labels
      Last edited by Rich Goldstein; 20 May 2016, 12:41.

      Comment


      • #4
        Now you're right. (No excuse, but the marker label call was hidden without a scroll.)

        A marker label variable can be a string variable, so create it first:

        Code:
        gen pctactute2 = string(pctacute, format(%2.1f)) + "%"
        or any other format.

        Comment


        • #5
          thanks - there is a typo in your command (format is not allowed), but a simple change, shown below, did it
          Code:
          gen pctacute2 = string(pctacute, "%2.1f") + "%"

          Comment


          • #6
            Yes; I feel like rewriting the whole thread. Sorry for misdirections.

            Comment


            • #7
              no apology necessary - you got me to the right place - thanks

              Comment


              • #8
                How to show percents (percentages) in various contexts should probably be written up for the Stata Journal. A little thing, but clearly a little thing that is often wanted.

                Comment


                • #9
                  I agree that an SJ piece would be useful

                  Comment

                  Working...
                  X