Announcement

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

  • Scatterplot with weighted regression line using aaplot and lfit

    Dear Statalist,

    I'm trying to graph a scatterplot with a regressionline. Instead of a standard OLS estimation, I would like to fit a line using

    I use the aaplot module to get the graph autamtically annotated with the estimated regression coefficients and R^2.

    Trying to get a weighted regression line, I include the option [w=weights] in my lfit command:


    Code:
    aaplot y x, addplot(lfit y x [w=weights])

    However, the output does not look as desired, with only one regression line (from the weighted estimation) and the correct coefficients for this regression.

    Instead, the plot includes 2 lines (one in green and one in a light grey) and the estimated regression coefficients and R^2 appear to be from a standard unweighted regression (see png. below).

    Is there a possibility to get a scatterplot with only a regression line from a weighted regression using the aaplot command?


    Click image for larger version

Name:	growth_corr_public_net.png
Views:	1
Size:	81.4 KB
ID:	1609043

  • #2
    aaplot (from SSC, as you are asked to explain) by itself just produces the unweighted regression line and knows nothing about what you add to the same plot.

    As the help explains:

    aaplot is indicative, not definitive. ... Users [inclined to show other output] should feel free to clone aaplot and should feel compelled to use their own different program name.

    Comment


    • #3
      Thank you very much for your answer Nick!

      Does that mean I have to rely on twoway scatter to fit such a line in my plot?

      Code:
       twoway scatter y x, || lfit `y x [w=weights]

      Comment


      • #4
        You are getting all that any way. The key difference is that aaplot won't reach over and give you the coefficients etc for the weighted regression line..

        Comment


        • #5
          Ok, understood - thanks again!

          Comment


          • #6
            Somebody was in touch with me directly about adding weights. I suggested they just publish their version under a different name, but I have no idea of where, when or whether they might actually do that.

            Comment

            Working...
            X