Announcement

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

  • How to make scales the same size on a twowayscatter

    I am working with 2 dimensional data, that I wish to graph against a 45 degree line.

    What I have typed is:

    [CODE}

    twoway scatter xvariable yvariable

    [/CODE]

    1. This, howoever, generates different scales for the x and y variable, depending on the range of the data. How do I make the scales the same? (not only the numbers, but also the size of the intervals(.
    2. How would I graph a 45 degree line against it?

    Any help is greatly appreciated.
    Last edited by Chinmay Sharma; 09 Apr 2016, 07:58.

  • #2
    I'm not entirely sure what you want, but look at the aspectration() option under twoway graph. To plot a 45 degree line, then use the twoway function graph. The range() option determines the start and end point on the x-axis.

    Code:
    twoway scatter xvariable yvariable, aspectratio(1) || twoway function x y, range(-1, 1)
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Chinmay Sharma could be be a bit more specific with regards to what you mean by the scales? Are you asking about the measurement scales of the data, the scale of the axis, etc... You can use Carole J. Wilson's suggestion with a minor modification:

      Code:
      // Load example data
      sysuse auto.dta, clear
      
      // Rename a couple variables to match the posting
      rename (price mpg)(yvariable xvariable)
      
      // Generates summary statistics for the variable xvariable
      qui: su xvariable
      
      // Stores the minimum value of xvariable
      sca xmin = r(min)
      
      // Stores the maximum value of xvariable
      sca xmax = r(max)
      
      // Do the same for the yvariable
      qui: su yvariable
      sca ymin = r(min)
      sca ymax = r(max)
      
      // Get the minimum value of the two variables
      loc rmin `= min(xmin, ymin)'
      
      // Get the maximum value of the two variables
      loc rmax `= max(xmax, ymax)'
      
      // Creates a graph with a 45 degree line with the same scales for the two 
      // variables
      tw scatter yvariable xvariable, ysca(range(`rmin'(1000)`rmax'))              ///   
      xsca(range(`rmin'(1000)`rmax')) || function y=x, range(`rmin' `rmax')         ///   
      name(example1, replace)
      
      // Since the literal translation of your question illustrated above doesn't  
      // appear to be useful in many situations, I'll assume the intention was related 
      // to the measurement scale of the variables
      
      // This will standardize (z-score transformation) the yvariable 
      egen yvar = std(yvariable), m(0) std(1)
      
      // And this will do the same for the xvariable 
      egen xvar = std(xvariable), m(0) std(1)
      
      // Even though the same means and SD were specified above, if you want to 
      // enforce the same scale on the graph, it would be good to explicitly set those 
      // values in the command
      tw scatter yvar xvar, ysca(range(-5(.5)5)) xsca(range(-5(.5)5)) ||              ///   
      function y=x, range(-5 5) name(example2, replace)

      Comment

      Working...
      X