Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: treatment of "$" in graphics text


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: treatment of "$" in graphics text
Date   Fri, 21 May 2004 11:39:36 +0100

Here's my story, which just expands one step on what you know: 

With the -display- there are just two levels we need to think about: 

1. Stata interprets what we type. Among other things, global 
macros are substituted by their contents. 

2. The -display- code tries to do what it's told. 

With 

display "price in $US"

Stata's inclination is to treat $US as a global macro, 
which usually doesn't exist, so it's substituted by 
a blank string. That we can fight in the two ways
you mention, and both work. 

With the -scatter- you are seeing the consequences 
of using an ado file which calls other ados. It's 
a Stata principle that behaviour should be the 
same whether something is done by part of
the executable or an ado or a do file, but that's 
not always possible, given other firm rules. 

With -scatter- 

scatter price weight, ytitle("price in \$US")

there are more than two levels we need to think about: 

1. Stata interprets what we type. "\$" gets
mapped to "$". So far, so good. 

2. The -scatter- code tries to do what it's told. 

3. But -scatter- is an .ado and code inside 
that, in this case, there is a call 

graph twoway scatter price weight, ytitle("price in $US") 

which will fail to do what you for the same reason 
as before. So, in order to get past the guard dogs, 
Agent Ryan, you need a sausage for every dog. Whether there 
is a clever way of nesting \$ I don't know, but I 
doubt it, and in any case that would be an impractical 
strategy, as you would have to know _exactly_ how many sausages 
were needed, or more prosaically how many times your code would 
get interpreted: with the new graphics' deeply nested
structure, not just of ados but also of class-based
stuff, goodness knows what the answer is. 

Incidentally, this didn't happen with the old graphics
as what you typed would get interpreted precisely once. 

Nick 
n.j.cox@durham.ac.uk 

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Philip Ryan
> Sent: 21 May 2004 07:37
> To: statalist@hsphsun2.harvard.edu
> Subject: st: treatment of "$" in graphics text
> 
> 
> Page 207 of the Users Guide [U21.3.9] instructs us on how to 
> deal with the 
> "$" character if we wish to display a dollar sign and _not_ 
> consider it the 
> marker for global macro expansion.  We can either use the "\" 
> character  or 
> some smcl code: {c S|} immediately prior to the "$".  These 
> devices work 
> for -display-.  But only the second, the smcl code, appears 
> to work in text 
> placed on a graphic, eg using  -title()-  -ytitle()-  -label()- etc.
> 
> I can't find a reference to this behaviour in the graphics 
> manual (or any 
> discussion in the archives).  Is there a reason for this 
> inconsistency/feature?
> 
> Try:
> 
> ====================
> display "price in $US"
> display "price in \$US"
> display "price in {c S|}US"
> sysuse auto
> scatter price weight, ytitle("price in $US")
> more
> scatter price weight, ytitle("price in \$US")
> more
> scatter price weight, ytitle("price in {c S|}US")
> ====================
> 
> (using Stata Windows 18-May-2004 and latest ados)
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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