Announcement

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

  • Drawing a line (function) overlaid on a Scatter Plot

    Hi All,

    Sorry if this is a really basic question, but I've searched and looked at the help files, and I can't seem to figure this out. I would like to overlay a line (defined by a function) on a scatter plot in Stata 13.1. Here's a reproducible sample:

    Code:
    clear
    set more off
    
    input c y i
    46 60 14
    31 45 14
    61 75 14
    58 80 22
    43 65 22
    73 95 22
    70 100 30
    55 85 30
    85 115 30
    end
    
    graph twoway  (scatter c y)
    Now, for example, if I were trying to just fit the regression line I would use

    Code:
    graph twoway (scatter c y) (lfit c y)
    But if I try to do something with function to overlay a line defined by an equation:

    Code:
    graph twoway (scatter c y) (function y = 0.6*x+10)
    It doesn't actually give me the line defined by the function.

    Thank you in advance for your help!

    Vincent

  • #2
    For twoway function, the default range for the x axis is range(0 1).

    Try adding option range(y) to the function plot.
    The y in range(y) refers to a variable in the dataset, which turns
    out to be the x variable in your scatter plot.

    Code:
    graph twoway (scatter c y) (function y = 0.6*x+10, range(y))

    Comment

    Working...
    X