Announcement

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

  • label value for yline() on y-axis

    Hi All,

    I would like to place a label of a yline() on the y-axis to indicate the actual value of the yline()

    Code:
    sysuse auto
    cusum foreign weight, yline(-3.26)
    So in this example, I would like the ylabel() to include the value "-3.26" which is the value of the yline()...

    Thanks in advance!

    Ariel

  • #2
    You can specify this explicitly using -ylab()- or use the -text()- option without interrupting the y-labels.

    Code:
    cusum foreign weight, yline(-3.26) ylab(-10 (2) -4 -3.26 -2 0)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	31.5 KB
ID:	1763961

    Comment


    • #3
      Thank you, Andrew! I should have known that you’d have the answer!

      I plan on programming this in a package, so I’d like to allow Stata to find the ylabels in its usual process (rather than having me to program the axis labels). Do you have a solution that does not require me to specify the ylabels (other than the ylabel for the yline, that is)?

      thanks!

      Ariel

      Comment


      • #4
        It is not easy to determine how Stata generates the y-axis labels. Stata calculates round numbers and places them efficiently along the axis. I would approach this by running the command twice: first, generating the cumulative sum variable, then using -addplot()- to place the -yline()- value on the RHS axis. This avoids the problem of overlapping labels in case the yline value coincides with, or is close to, the axis values determined by Stata. After generating the graph, you can drop the variable.

        Code:
        sysuse auto, clear
        qui cusum foreign weight, gen(cusumvar)
        cusum foreign weight, yline(-3.26) ///
        addplot(line cusumvar weight, lc(none) yaxis(2) ylab(-3.26, axis(2)) ///
        ytitle("", axis(2))) leg(off)
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	47.5 KB
ID:	1763996

        Comment


        • #5
          Thank you, Andrew. I’ll give this these ideas some more thought.

          Ariel

          Comment

          Working...
          X