Announcement

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

  • Adding formatted values as text in a graph

    Hi everyone,

    I was wondering if there is a way to format the values we enter as text in a graph. Consider the following:
    Code:
    sysuse auto, clear
    quiet sum mpg, d
    local me = r(mean)
    local sk = r(skewness)
    histogram mpg, frac text(.395 30 "Mean: `me'" "Skewness: `sk'")
    It produces the following histogram



    As you can see the numbers are with all the decimals. There is no way I can use the typical formatting that we use with display, and I was wondering if the formatting could be done when assigning the values to the local macro, or in any other way.

    Thanks!!!!
    Alfonso Sanchez-Penalver

  • #2
    Actually, I found the following solution.
    Code:
    sysuse auto, clear
    quiet sum mpg, d
    local me: display %5.2f r(mean)
    local sk: display %6.4f r(skewness)
    histogram mpg, frac text(.395 30 "Mean: `me'" "Skewness: `sk'")
    It produces

    histex.png

    So basically to use display when assigning the values to the local macro, to format the value then. Is there any way to do it within the text option?

    Thanks!!!
    Alfonso Sanchez-Penalver

    Comment


    • #3
      Code:
      histogram mpg, frac text(.395 30 "Mean: `:di %5.2f `=`me'''" "Skewness: `:di %6.4f `=`sk'''")

      Comment

      Working...
      X