Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Special characters in Stata graphics


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Special characters in Stata graphics
Date   Tue, 12 Dec 2006 14:46:13 -0000

This is a very common request at users' meetings and for very 
good reason. However, more is possible now than is often 
realised. 

. search characters 

reveals a discussion of this point:

SJ-4-1  dm0006  . . . .  Stata tip 6: Inserting awkward characters in the plot
        Q1/04   SJ 4(1):95--96                                   (no commands)
        tips for using the char() function with graphics

Below is the gist of that Tip, shorn of special characters. But note
that it is available in the collection "Thirty-three Stata Tips" 
available from StataCorp, a snip at the price if I say so myself. 
(I get no royalties....) 

Obvious but true: solutions involving MS Word do not apply to 
all Stata users. 

--------------------------------------------------------------
Stata tip 6: Inserting awkward characters in the plot

Did you know about the function -char()-?  -char(n)- returns the
character corresponding to ASCII code n for 1 <= n <= 255.  Strictly,
there are several numbering schemes for so-called ASCII characters.
That used by Stata is the ANSI scheme: a web search for "ANSI character
set" will produce tables to refer to.  This function may sound like an
arcane programmer's tool, but it offers a way to use awkward text
characters, either those not available through your keyboard, or those
otherwise problematic in Stata.  A key proviso, however, is that you
must have such characters available in the font that you intend to use.
Fonts available tend to vary not only with platform but even down to
what is installed on your own system.  Some good fonts for graphics in
particular are Arial and Times New Roman. 

Let us see how this works by considering the problem of inserting
awkward characters in your Stata graphs, say as part of some plot or
axis title. Some examples of possibly useful characters are 

char(133) ellipsis
char(134) dagger
char(135) double dagger
char(169) copyright
char(176) degree symbol
char(177) plus or minus
char(178) superscript 2
char(179) superscript 3 
char(181) micro symbol
char(188) one-fourth
char(189) one-half
char(190) three-fourths
char(215) multiply 

There are many others that might be useful to you, including a large
selection of accented letters of the alphabet. You can use such
characters indirectly or directly. The indirect way is to place such
characters in a local macro and then to refer to that macro within the
same program or do file. 

So I use data on river discharge, for which the standard units are cubic
meters per second. I can get the cube power in a axis title like this: 

. local cube = char(179)
. scatter ... , xtitle("discharge, m`cube'/s")

Or I have used Hanning, a binomial filter of length 3: 

. local half = char(189)
. local quarter = char(188) 
. twoway connected ... , 
	title("Smoothing with weights `quarter':`half':`quarter'") 

The direct way is to get a macro evaluation on the fly. You can write
`=char(176)' and in one step get the degree symbol (for temperatures or
compass bearings). This feature was introduced in Stata 7, but not
documented until Stata 8.  See [P] macro. 

-char()- has many other uses besides graphs.  Suppose a string variable
contains fields separated by tabs. For example, -insheet- leaves tabs
unchanged. Knowing that a tab is -char(9)-, we can

. split data, p(`=char(9)') destring

Note that -p(char(9))- would not work.  The argument to the -parse()-
option is taken literally, but the function is evaluated on the fly as
part of macro substitution.

Note also that the SMCL directive {c #} may be used for some but not all
of these purposes. See [P] smcl. Thus 

. scatter ... , xtitle("discharge, m{c 179}/s")

would work, but using a SMCL directive will not work as desired with
-split-. 
-------------------------------------------------------


Nick 
[email protected] 

Paul Seed
 
> This has been a problem for several people.
> Toyoto Iwata <<mailto:[email protected]>[email protected]>
> on 25 Jun 2004 22:33:54 +0900
> asked for subscript 2 & superscript -1.
> I personally also have a need for
> superscript 2 , as in "BMI (kg/m2)" and
> Greek mu , as in "?mol/L".
> 
> & Nick Cox echoed the need.
> 
> 
> I have found a partial solution:
> In MS Word, choose "Insert" * "Symbol"  from the Edit menu.
> Then select font Arial and subset Latin-1.
> Select "superscript 2" from the display & insert into the text.
> Copy & paste into your Stata command as needed.
> The same technique works for
> "Greek mu" (subset Basic Greek or Latin-1)
> "superscript -1" ("-" : subset Spacing modifier letters;
>          "1" : subset Latin-1.)
> 
> Unfortunately, this only works for certain special characters.
> The only superscript numerals are 0 1 2 3, and letters "n" or "TM".
> There are no subscripts at all.

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index