Announcement

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

  • scatterplot of regression including interaction

    Hi all, thanks for reading. I understand how to graph a scatter plot between two variables using 'twoway'. However, how do I generate a scatter plot including an interaction term and covariates? I searched here and didn't see a solution yet. I'm new to the forum, so I may have missed it: apologies if so.

    regress flossesused age gender i.ethnicity pastflossweek c.cond2##c.ce2
    margins, at(ce2=(.45 1) cond2=(0 1))
    marginsplot

    That's the code I'm using now, simplified for this post. The graph doesn't yield scatter, even if I call 'marginsplot recast(scatter)': in that case, it just gives the point estimates of the margins and doesn't show scatter or a fitted line.

  • #2
    I'm not sure what you mean by "a scatter plot including an interaction term and covariates", but perhaps the option -addplot(scatter y x)- is what you are looking for.

    Assuming you want to show the predicted relationship between ce2 and flossesused over the range of ce2 (.45 to 1) for cond2 = 0 and 1 and include the scatterplot of ce2 and flossesused, you could go like this:

    regress flossesused age gender i.ethnicity pastflossweek c.cond2##c.ce2
    margins, at(ce2=(.45 1) cond2=(0 1))
    marginsplot, noci recast(line) addplot(flossesused ce2)


    You could also consider using contour plots.

    Best,
    Kim

    Comment


    • #3
      Dear Kim, thanks for your suggestions. I found success with this code:

      marginsplot, noci recast(line) addplot(scatter flossesused ce2)

      In your code section 'scatter' was dropped. This is resolved. Thanks!

      Comment

      Working...
      X