Announcement

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

  • Graph axes with same range?

    I'm a new user in Stata and want both of the axes in a scatter plot to span the same range without needing to specify the ranges for each variable.

    For example: Treatment before (values range from 0 to 100) and after (values range from 0 to 80). I need both axes to display the range from 0 to 100 without needing to type "ylabel (0 100) xlabel (0 100)". Is there a general command for that (something like "ylabel xlabel (same)")?

  • #2
    No such command and, more to the point, no such option either, so far as I know.

    Insisting on the same specified limits is programmable, however. Let's suppose that you always want ysc(r(0 100)) xsc(r(0 100)) -- at least as a default. That's this, at least as a crude first stab that I really haven't banged hard upon:


    Code:
    program myscatter 
         version 9 
         syntax anything [, *] 
         scatter `anything'  , ysc(r(0 100)) xsc(r(0 100)) `options' 
    end
    With this program defined, you can go

    Code:
    sysuse auto, clear 
    myscatter mpg weight
    or whatever.

    Note that

    1. You can override your own defaults.

    2. Stata will ignore your own defaults if the data lie outside them, as the example above indicates brutally.

    On the whole, I have got to say, candidly, that this may be more complicated than you want to play with if you don't understand it already.

    There is a technique that I will try harder to sell. Suppose you find yourself writing out the same options again and again. Then you can always put the text in a macro and call it up. So, I might want again and again

    Code:
    ysc(r(0 100) xsc(r(0 100)) yla(, ang(h)) scheme(s1color)
    and if I go

    Code:
    local myopts ysc(r(0 100) xsc(r(0 100)) yla(, ang(h)) scheme(s1color)
    then I can call up

    Code:
    `myopts'
    within my next scatter-type command. This must be done (a) in the same session (b) where commands you type can "see" the macro definition, i.e. within the same interactive session, do-file, etc.

    Comment


    • #3
      Thank you Nick. Now I know that I can have the first code as default for at least my percent plots. Your answer also helped me to figure out new ways to write commands. I appreciate your help.

      Comment

      Working...
      X