Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: confused with syntax graphing points


From   sjsamuels@gmail.com
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: confused with syntax graphing points
Date   Wed, 11 Nov 2009 15:26:29 -0500

A complement to a do-file: When I have a complicated graph command
that I'll want to re-use within a large do-file,  I define pieces of
it in macros and string them together in another macro.  If I want to
use them in different programs, then I save this definition section
in a separate do-file, as Nick suggests.

For example:
**************************DEFINE PLOT**************************
global plotmax 180  // maximum for plot
local twoway "twoway scatter ydf* outcome if outcome<= $plotmax,"
local xlabel "xlabel(0(10)$plotmax) legend(off)"
local ylabel "ylabel(0 25 50 75 100, format(%4.0f))"
local yline  "yline(25 50 75)"
local connect "c(J J J J J J J J J J J J J J)"
local msymbol "msymbol(i i i i i i i i i i i i i i)"
local xtitle  "xtitle("Days since arrest")"
local plotcmd "`twoway' `xlabel'  `ylabel' `yline' `connect' `msymbol' `xtitle'"
***************************END DEFINITION***************************

Then a particular call might go:

`plotcmd' ///
 saving(`graphno',replace) ///
caption("Graph: `graphno'. Program: `pname'." "Data: `dsno'. Date:
`c(current_date)'.") ///
title("Percent enrolled in program by days since arrests" "Classified
by Crime Type & Charge Level")

(The locals `graphno', `pname', `dsno' are set beforehand.)

If necessary, occasionally,  you can change any option in the original
"plotcmd" by adding a revised version after invoking the original, for
example after the "title" line above.  Stata uses the last version  it
encounters.

-Steve


On Wed, Nov 11, 2009 at 1:30 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
>
> When a graph command gets complicated, I tend to copy it to the do-file editor and space it out so that I can see the structure. If it looks worth keeping, keep it as a do-file.

-- 
Steven Samuels
sjsamuels@gmail.com
18 Cantine's Island
Saugerties NY 12477
USA
845-246-0774
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index