Announcement

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

  • Scatter plot with *adjusted* line of best fit

    Hi there,

    I am trying to create a scatter plot of IV and DV, where the line of best fit is adjusted for one (binary) covariate (IV2).

    My regression model is simple ( regress DV IV1 IV2 ), and I suspect the answer might be simple too, but so far no luck..

    Would anyone be able to help?

    Thanks,
    Lise

  • #2
    A scatter plot is a two-dimensional figure. With a binary 0/1 x variable and a continuous y variable, you will have markers at x=0 and x=1. I am not sure what you have in mind and how your regression with two variables is relevant to your question.

    Comment


    • #3
      I don't know what you mean by adjustment, but one flavour would be just that in your case

      Code:
      \regress DV IV1 i.IV2
      defines two regression lines, one for each state of IV2.

      I'd caution against the abbreviations DV and IV as just tribal jargon. Why it's unlikely that anyone here will interpret DV as Deo volente it's entirely possible that some people here regard IV as meaning instrumental variable.

      regplot from the Stata Journal can handle this. The article at https://www.stata-journal.com/articl...article=gr0009 explains the principle but install the software from gr0009_1. You can get a clickable link from

      Code:
      search regplot
      SJ-10-1 gr0009_1 . . . . Software update for model diagnostic graph commands
      . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
      (help anovaplot, indexplot, modeldiag, ofrtplot, ovfplot,
      qfrplot, racplot, rdplot, regplot, rhetplot, rvfplot2,
      rvlrplot, rvpplot2 if installed)
      Q1/10 SJ 10(1):164
      provides new command rbinplot for plotting means or medians
      of residuals by bins; provides new options for smoothing
      using restricted cubic splines; updates anova examples

      SJ-4-4 gr0009 . . . . . . . . . . Speaking Stata: Graphing model diagnostics
      . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
      (help anovaplot, indexplot, modeldiag, ofrtplot, ovfplot,
      qfrplot, racplot, rdplot, regplot, rhetplot, rvfplot2,
      rvlrplot, rvpplot2 if installed)
      Q4/04 SJ 4(4):449--475
      plotting diagnostic information calculated from residuals
      and fitted values from regression models with continuous
      responses

      You give no data example, contrary to our request, but this is an example you can run once you have installed regplot.

      Code:
      sysuse auto, clear 
      gen gpm = 100/mpg
      regress gpm weight i.foreign
      label var gpm "Gallons per 1000 miles"
      regplot, sep(foreign) fitopts(lc(orange blue)) ms(Oh +) mc(orange blue) legend(pos(11) ring(0) col(1) order(4 3))
      Click image for larger version

Name:	regplot_gpm_weight_foreign.png
Views:	1
Size:	37.2 KB
ID:	1466419


      Comment


      • #4
        Ah brilliant - thank you very much !! I will refer to the guidelines for posting new questions next time. Again, thanks!

        Comment


        • #5
          The backslash in the first code statement in #3 was a typo and should please be ignored.

          Comment

          Working...
          X