Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: finicky graph parsing

From   Scott Merryman <>
Subject   Re: st: finicky graph parsing
Date   Wed, 3 Nov 2010 08:14:00 -0500

I would also point out, as another example of poor style, that spaces
are not needed to separate the elements in graph syntax:

sysuse auto ,clear
 twoway (scatter mpg price,c(l)s(i)clw(thick)clc(blue)) ///
(scatter mpg price,c(l)s(i)clc(red)clw(thick)xtitle("actual
change")ytitle("probability")legend(order(1 "same" 2 "different")

It appears that the -_parse- command adds spaces around the elements
when it pulls out the common graph options, removes superfluous
commas, and moves the -if foreign- statement to its proper location:

local 0  twoway (scatter mpg price,c(l)clw(thick)clc(blue), if foreign) ///
(scatter mpg price,c(l)s(i)clc(red)clw(thick) ,,,,,xtitle(actual change) ///
 ytitle(probability)legend(order(1 "same" 2 "different") cols(2)))

gettoken do 0 : 0, parse(" ,")

local my_opts noDRAW NAME(string) SCHeme(passthru) COPYSCHeme noREFSCHeme ///
 XSIZe(passthru) YSIZe(passthru) FXSIZe(passthru) FYSIZe(passthru)  ///
 BY(string asis) SAVing(string asis) PLAY(string asis)

local graph_opts TItle(string) SUBtitle(string) CAPtion(string)
NOTE(string) ///
 LEGend(string) T1title(string) T2title(string) B1title(string)
B2title(string) ///
 L1title(string) L2title(string) R1title(string) R2title(string)
XLabels(string) ///
 YLabels(string) TLabels(string) XTICks(string) YTICks(string) ///
 TTICks(string) XMLabels(string) YMLabels(string) TMLabels(string) ///
 XMTicks(string) YMTicks(string) TMTicks(string) XOptions(string) ///
 YOptions(string) XTitle(string) YTitle(string) TTitle(string)

_parse expand cmd glob: 0,common(`my_opts' `graph_opts')

macro list _glob_op _cmd_1 _cmd_2

. macro list _glob_op _cmd_1 _cmd_2
_glob_op:       xtitle(actual change) ytitle(probability)
legend(order(1 "same" 2 "different") cols(2))
_cmd_1:         scatter mpg price if foreign, c(l) clw(thick) clc(blue)
_cmd_2:         scatter mpg price, c(l) s(i) clc(red) clw(thick) ,


On Tue, Nov 2, 2010 at 3:15 PM, Nick Cox <> wrote:
> Well, yes and no. Michael will know these exceptions:
> 1. Multiple commas moving back and forth between options and the preamble are perfectly legal. Not good style, perhaps, but legal.
> . sysuse auto
> . scatter mpg weight, ms(Oh), if foreign
> is legal, and works.
> 2. In addition, commas can be "embedded, within text".
> Nick
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index