Stata Tidbits

These tidbits contain bits and pieces of information I hope you find helpful to use Stata more effectively. You can receive notifications of new tidbits as they are added (via email) by clicking on the subscribe box at the left. (Every email has an unsubscribe link, making it a snap to unsubscribe.)
« Graph symbols and fonts in Stata 11: Part 2 | Robust regression vs. robust standard errors, Part 2 »
Tuesday
Feb232010

Graph symbols and fonts in Stata 11: Part 1

In Stata 11, graphs can display the full greek alphabet (upper and lower case), math symbols, as well as using boldface and italics. This tidbit will illustrate these new features, and next week we will illustrate how to display text using different fonts. But, for this week, let's start by showing how to display greek letters within a graph. Consider the graph below.

. use allstates, clear
(Data on 50 States)

. graph twoway (scatter propval100 popk) (lfit propval100 popk), ///
> title(Property values by population)

We might want to include the regression equation for this graph as a subtitle. We can do so as shown below. Note how including {&alpha} in the subtitle is replaced with lower case alpha (α). Likewise, {&beta} is replaced with lower case beta (β) and {&epsilon} is replaced with lower case epsilon ε.

. graph twoway (scatter propval100 popk) (lfit propval100 popk), ///
> title(Property values by population) ///
> subtitle(y = {&alpha} + {&beta}*pop + {&epsilon})

Although not customary, we could replace the greek letters with their upper case counterparts by making the first letter uppercase, e.g. replacing {&alpha} with {&Alpha}, as shown below.

. graph twoway (scatter propval100 popk) (lfit propval100 popk), ///
> title(Property values by population) ///
> subtitle(y = {&Alpha} + {&Beta}*pop + {&Epsilon})

You can also insert mathematical symbols. In the caption of the graph, I have inserted some nonsense to illustrate three symbols, {&le} (for less than or equal to), {&function} (is a function of), and {&ne} (not equal to).

. graph twoway (scatter propval100 popk) (lfit propval100 popk), ///
> title(Property values by population) ///
> subtitle(y = {&alpha} + {&beta}*pop + {&epsilon}) ///
> caption("p {&le} 0.150, y = {&function}(x), 1 {&ne} 2")

In the example below, the property values are shown as a linear and quadratic function of population. The regression equation is shown using B0, B1, B2 notation (compared to alpha and beta notation used above). This is an opportunity to show how to use subscripts and superscripts. Note that {sub:0} displays a zero subscripted, and {sup:2} displays squared (the number two superscripted).

. graph twoway (scatter propval100 popk) (qfit propval100 popk), ///
> title(Property values by population) ///
> subtitle(y = {&Beta}{sub:0} + {&Beta}{sub:1}*Pop + {&Beta}{sub:2}*Pop{sup:2})

Suppose we want to display text as bold face or as italics. We can do this in a way that is similar to the way that we subscripted and superscripted text as shown above. In the example below, part of the text in the caption is displayed in boldface, and part of the note is displayed in italics.

. graph twoway (scatter propval100 popk) (qfit propval100 popk), ///
> title(Property values by population) ///
> subtitle(y = {&beta}{sub:0} + {&beta}{sub:1}*Pop + {&beta}{sub:2}*Pop{sup:2}) ///
> note(Source of data: {it:The fake data factory}) ///
> caption(Type of model: {bf:Quadratic linear regression})

We can even display symbols in boldface and italics. In the example below, the first beta is displayed in bold because I specified {bf:{&beta}}. The second beta is displayed using italics because I specified {it:{&beta}}.

. graph twoway (scatter propval100 popk) (qfit propval100 popk), ///
> title(Property values by population) ///
> subtitle(y = {bf:{&beta}}{sub:0} + {it:{&beta}}{sub:1}*Pop + {&beta}{sub:2}*Pop{sup:2})

This concludes this tidbit for this week. For more information, you can see help graph text.

Next week we will look at how you can specify different fonts using Stata 11. You can download the example data files from this tidbit (as well as all of the other tidbits) as shown below. These will download all of the example data files into the current folder on your computer. (If you have done this before, then you may need to specify net get stowdata, replace to overwrite the existing files.

net from http://www.MichaelNormanMitchell.com/storage/stowdata
net get stowdata

If you have thoughts on this Stata Tidbit of the Week, you can post a comment. You can also send me an email at MichaelNormanMitchell and then the at sign and gmail dot com. If you are receiving this tidbit via email, you can find the web version at http://www.michaelnormanmitchell.com/ .

 

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.
Editor Permission Required
You must have editing permission for this entry in order to post comments.