Announcement

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

  • Drawing a diagonal line in Stata Graphics

    Hi All,

    I am new in Stata and I am using Stata 13. Using system installed dataset auto.dta, I want to draw a diagonal line from an intercept of 4000 and a slope of -45 degrees. How do I do this?

    I have researched several sites and the closest code that I got is this:

    sysuse auto, clear
    set obs 75
    replace price = 0 in 75
    tw scatter weight price || line price price, sort

    This solution however does not solve my problem.
    Last edited by Dexter Pante; 03 Dec 2015, 06:17.

  • #2
    At least two ways of doing this.

    One is to use twoway function, giving it the equation of the line to be plotted. See its help and if more is needed http://www.stata-journal.com/sjpdf.h...iclenum=gr0010

    Another is to use twoway scatteri giving it two pairs of coordinates and recasting the graph to line.

    In each case you would follow the same syntax as with your line call, namely follow a || with function or scatteri
    .

    Comment


    • #3
      Please note that twoway scatteri yields a smoother line than twoway function. Compare the lines in the two graphs below. The line drawn with twoway function is not completely straight. The explanation for the difference can be found in this Statalist post.
      Code:
      clear
      input float(x y)
        0   0
      100 100
      end
      twoway scatteri 0 0 100 100, connect(l) clwidth(thin) msymbol(i) aspect(1) name(g1, replace)
      twoway function y=x, range(0 100) lwidth(thin) aspect(1) name(g2, replace)

      Comment

      Working...
      X