Announcement

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

  • Does anyone know a clever way to add R2 to "graph twoway lfit"?

    I am using the below code to fit a linear regression line, Private_Hospital is a binary variable

    graph twoway lfit Private_Hospital_1 Differential_Distance

    I would like to show the R2 on the graph if possible, does anyone know how to do this?

    i have looked at the help file and no luck so far

  • #2
    See the option -text()- in the documentation to insert it within the plot region.

    Code:
    sysuse auto, clear
    set scheme s1mono
    qui reg mpg weight
    tw (scatter mpg weight) (lfit mpg weight), leg(off) title("R{sup:2}= `=string(`e(r2)', "%3.2f")'")
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	26.2 KB
ID:	1675251

    Comment


    • #3
      Thank you so much, do you know how I can make the R2 to three decimal places?

      Comment


      • #4
        Change "%3.2f" to "%4.3f". See

        Code:
        help format

        Comment


        • #5
          See also aaplot from SSC.

          Comment


          • #6
            https://www.statalist.org/forums/for...updated-on-ssc

            Comment

            Working...
            X