Monday, August 27, 2012

Putting Dollars in STATA Graphics Titles

This post is mostly so I remember how to do this.

There is a problem that I run into a lot when I am plotting in STATA.  The $ symbol is used by STATA to call up various macros.  When you try to add it as a currency symbol in a graph title it ends up disappearing. Take, for instance the following code and its associated graphical output:


twoway dot percapmil id, mlabel(description) mlabpos(12)
scheme(s1mono)
xlabel(0(1)5)
ylabel(, angle(0))
xtitle("")
ytitle("$1000 US Per Military Personnel")
title("Per Capita (Mil. Personell) Spending of US and Russian Customers", size(medium))
subtitle("1992-2000 and 2001-2002")


Notice the y-axis label is missing the dollar sign.  I really want to emphasize the fact that the y axis represents money spent by states for defense.  How can I add the dollar sign to the graph?  This requires using a STATA Markup Control Language (SMCL) workaround.  

The modified code looks like this (just taking the relevant line of code):

ytitle("{c $|}1000 US Per Military Personnel")

With this modification the graph looks the way that I want it to. 
It's a little bit inconvenient to have to add the extra code {c $|} just to get the symbol to show up like it should, but once you know what the workaround is you can get your work done instead of endlessly Googling.  Now back to work.

1 comment:

  1. Thanks for this tip - I found it through a Google search of my similar problem with Stata graphics.

    ReplyDelete