clear set scheme s2color * Before we get started. twoway (scatteri 4 0 "Updating Stata (update all)", mlabsize(huge) pstyle(p1)) /// (scatteri 3 0 "Seminar based on introduction from", mlabsize(huge) pstyle(p1)) /// (scatteri 2.5 0 "A Visual Guide to Stata Graphics", mlabsize(huge) pstyle(p2) msymbol(i)) /// (scatteri 1.5 0 "net from and net install to get data files", mlabsize(huge) pstyle(p1)) /// (scatteri .5 0 "Door prize at end", mlabsize(huge) pstyle(p1)), /// note("See http://www.ats.ucla.edu/stat/stata/ to get additional information for the seminar", ring(0)) /// title("Before we get started") /// xlabel(-.05 1) ylabel(-1 5) /// xscale(off) yscale(off) /// legend(off) * Here is how you can get the data files, schemes, and programs * associated with the seminar. net from http://www.stata-press.com/data/vgsg net install vgsg, replace net get vgsg, replace * Overview twoway (scatteri 6 0 "Kinds of graphs Stata can make", mlabsize(huge) pstyle(p1)) /// (scatteri 5 0 "Schemes for controlling look of graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 4 0 "Structure of graph commands", mlabsize(huge) pstyle(p1)) /// (scatteri 3 0 "graph options", mlabsize(huge) pstyle(p1)) /// (scatteri 2 0 "Building complex graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 1 0 "Additional examples", mlabsize(huge) pstyle(p1)), /// title("Overview") /// xlabel(-.05 1) ylabel(-1 7) /// xscale(off) yscale(off) /// legend(off) /// note("Stata graphics are fun and easy" "Stata graphics are powerful", ring(0)) * Kinds of graph Stata can make twoway (scatteri 6 0 "Kinds of graphs Stata can make", mlabsize(huge) pstyle(p2)) /// (scatteri 5 0 "Schemes for controlling look of graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 4 0 "Structure of graph commands", mlabsize(huge) pstyle(p1)) /// (scatteri 3 0 "graph options", mlabsize(huge) pstyle(p1)) /// (scatteri 2 0 "Building complex graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 1 0 "Additional examples", mlabsize(huge) pstyle(p1)), /// xlabel(-.05 1) ylabel(-1 7) /// xscale(off) yscale(off) /// legend(off) /// note("We will look at the wide variety of graph types Stata has." /// "We will also toss in some options for fun and variety.", ring(0)) twoway scatteri 6 0 "graph twoway" 5 0 "graph matrix" 4 0 "graph bar" /// 3 0 "graph box" 2 0 "graph dot" 1 0 "graph pie", /// mlabsize(huge) /// title("Stata has six families of graphs") /// xlabel(-.05 1) ylabel(-1 7) /// xscale(off) yscale(off) /// legend(off) /// note("twoway includes scatter, line, fit, fit with confidence intervals, area, bar, range, and distribution plots", ring(0)) * Stata has a wide variety of graph types. This section introduces the * kinds of graphs Stata produces. * We have combined them into six families of related * plots: scatterplots and fit plots, line plots, area plots, bar plots, * range plots, and distribution plots. We will start by illustrating * scatterplots and fit plots. * Let's use the "allstates" data file use allstates list stateab division region propval100 rent700 popden in 1/20 * Here is a basic scatterplot. The variable * "propval100" is placed on the "y" * axis, and "popden" is placed on the * "x" axis. graph twoway scatter propval100 popden, title("Home price by population density") * We can start this command just with "twoway", and Stata * understands that this is shorthand for "graph twoway". twoway scatter propval100 popden, title("Home price" "by population density") * We can make a linear fit line ("lfit") predicting * "propval100" from "popden". twoway lfit propval100 popden, title("Home price") subtitle("by population density") * Stata allows you to overlay "twoway" graphs. In this * case, we make a classic plot showing a scatterplot overlayed * with a fit line using the "scatter" and "lfit" commands. twoway (scatter propval100 popden) (lfit propval100 popden), xtitle(Population Density) * Here we overlay a scatterplot with * a linear fit line ("lfit") and a quadratic fit line ("qfit"). twoway (scatter propval100 popden) (lfit propval100 popden) /// (qfit propval100 popden), xtitle(Population density) ytitle(Home cost) legend(off) * Stata has other kinds of fit methods in addition * to linear and quadratic fit. This example includes a median spline * ("mspline"), fractional polynomial fit ("fpfit"), median band ("mband"), * and lowess ("lowess"). twoway (scatter propval100 popden) (mspline propval100 popden) /// (fpfit propval100 popden) (mband propval100 popden) /// (lowess propval100 popden), xlabel(0 1000 to 10000) ylabel(0 10 to 100) * We also overlay the linear fit * and confidence interval with a scatterplot. twoway (scatter propval100 popden) (lfitci propval100 popden) * Let's reverse the order of the overlaying. twoway (lfitci propval100 popden) (scatter propval100 popden), legend(off) * Let's switch to the spjanfeb2001 data file use spjanfeb2001, clear list date tradeday open high low close in 1/20 * This dropline graph shows the closing prices of the S&P 500 by * trading day for the first 40 days of 2001. twoway dropline close tradeday, note("Trading day is day number of trading") * Here we use a "spike" graph to show the same graph as the previous graph. * It is like the "dropline" plot, but no markers are put on the top. twoway spike close tradeday, ylabel(1200 1225 to 1400) * The "dot" plot, like the "scatter" command, shows markers for each data * point but also adds a dotted line for each of the "x" values. twoway dot close tradeday, ylabel(1200 1225 to 1400, angle(0)) * The "line" command is used in this example to make a simple line graph. twoway line close tradeday, sort clwidth(thick) * The "twoway connected" graph is similar to "twoway line", except a * symbol is shown for each data point. twoway connected close tradeday, sort clpattern(dash) * Let's now use the sp2001 data file use sp2001, clear list date tradeday open high low close in 1/20 * The "tsline" (time series line) command makes * a line graph where the "x" variable is a date variable that * has previous been declared using "tsset". * This example shows the closing price of the S&P 500 by * trading date. tsset date, daily twoway tsline close, sort clcolor(red) * This command uses "tsrline" "time series range line" * to make a line graph showing the high and low * price of the S&P 500 by trading date. twoway tsrline high low, sort blcolor(red) * An "area" plot is similar to a "line" plot, but * the area under the line is shaded. use spjanfeb2001, clear twoway area close tradeday, sort bfcolor(green) * Here is an example of a twoway bar plot. twoway bar close tradeday, bcolor(teal) * This example illustrates the use of "rarea" "range area" to graph * the high and low price with the area filled in. If you used "rline" * "range line", then the area would not be filled in. twoway rarea high low tradeday, sort bfcolor(ltblue) * Here is a "rconnected" graph. If you instead used "rscatter" "range scatter", * the points would not be connected. twoway rconnected high low tradeday, sort msymbol(Dh) * Here we use "rcap" (range cap) to graph the high and low price * with a spike and a cap at each value of the "x" variable. * If you used "rspike" instead, spikes would be displayed * but no caps. Or if you used "rcapsym", the caps would be * symbols and you could modify the symbol. twoway rcap high low tradeday, sort msize(small) * Here we use the "rbar" to graph the high and low price with bars * at each value of the "x" variable. twoway rbar high low tradeday, sort bfcolor(yellow) * The "twoway histogram" command can be used to * show the distribution of a single variable. * It is often useful when overlayed with other * "twoway" plots; otherwise, the "histogram" * command would be preferable. use allstates, clear twoway histogram popk, freq * The "twoway kdensity" shows a kernel-density plot and is * useful for examining the distribution of a single variable. * It can be overlayed with other "twoway" plots, but otherwise, * the "kdensity" command would be preferable. twoway kdensity popk * The "twoway function" command allows * you to graph an arbitrary function over * a range of values you specify. twoway function fred=normden(x), range(-4 4) * You can use the "graph matrix" command to show a scatterplot matrix. graph matrix propval100 rent700 popden, half msymbol(Oh) * The "graph hbar" command is often used for showing the values * of a continuous variable broken down by one ore more * categorical variables. graph hbar popk, over(division) * You can show the previous graph as a box plot using the * "graph hbox" command. graph hbox popk, over(division) * The previous plot could also be shown as a dot plot using "graph dot". graph dot popk, over(division) * We can sort the dot plot like this graph dot popk, over(division, sort(1)) * The graph pie command can be used for showing pie charts. graph pie popk, over(region) * Let's now have a look at schemes in Stata. twoway (scatteri 6 0 "Kinds of graphs Stata can make", mlabsize(huge) pstyle(p1)) /// (scatteri 5 0 "Schemes for controlling look of graphs", mlabsize(huge) pstyle(p2)) /// (scatteri 4 0 "Structure of graph commands", mlabsize(huge) pstyle(p1)) /// (scatteri 3 0 "graph options", mlabsize(huge) pstyle(p1)) /// (scatteri 2 0 "Building complex graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 1 0 "Additional examples", mlabsize(huge) pstyle(p1)), /// xlabel(-.05 1) ylabel(-1 7) /// xscale(off) yscale(off) /// legend(off) /// note("Schemes are a powerful way to control the look of your graph." /// "You can make your own schemes!", ring(0)) * Here is a graph using the default scheme, s2color. use allstates, clear graph twoway scatter propval100 rent700 ownhome * Here is a graph using the s2mono scheme. graph twoway scatter propval100 rent700 ownhome, scheme(s2mono) * Here is a graph using the s1color scheme. graph twoway scatter propval100 rent700 ownhome, scheme(s1color) * Here is a graph using the s1mono scheme. graph twoway scatter propval100 rent700 ownhome, scheme(s1mono) * Here is a graph using the s1mono scheme. graph twoway scatter propval100 rent700 ownhome, scheme(economist) * Let's now use the nlsw data file use nlsw, clear list occ7 wage in 1/20 * This horizontal bar chart shows an example of the "vg_palec" scheme. It * is based on the "s2color" scheme but makes the colors of the * bars/boxes/markers paler by decreasing the intensity of the colors. * As you can see in this example, one use of this scheme is * to make the colors of the bars pale enough to include text labels * inside of bars. graph hbar wage, over(occ7, label(nolabels)) blabel(group,position(base)) /// scheme(vg_palec) * This uses the "vg_palem" scheme, the monochrome version of * "vg_palem". graph hbar wage, over(occ7, label(nolabels)) blabel(group,position(base)) /// scheme(vg_palem) * This scatterplot illustrates the "vg_outc" scheme. It * is based on the "s2color" scheme but makes the fill color of the * bars/boxes/markers white. There also is a "vg_outm" scheme, a monochrome * version of the scheme. use allstates, clear scatter propval100 rent700 ownhome, scheme(vg_outc) * This is an example of the "vg_samec" scheme, based * on "s2color", and makes all of the makers, lines, bars, etc., * the same color, shape and pattern. This scheme has * a monochrome equivalent called "vg_samem" that is not * illustrated. twoway (scatter ownhome borninstate) /// (scatter ownhome borninstate if stateab=="DC", mlabel(stateab)), /// legend(off) scheme(vg_samec) * This horizontal bar chart shows an example of the * "vg_lgndc" scheme. It is based on the "s2color" * scheme but changes the default attributes of the legend, namely * showing the legend in one column to the left of the plot region, * with the key and symbols placed atop each other. graph hbar commute, over(division) asyvar scheme(vg_lgndc) * What is a scheme? which scheme-vg_lgndc.scheme type c:\ado\plus\s\scheme-vg_lgndc.scheme * Options * Learning to create effective Stata graphs is ultimately about * using options to customize the look of a graph until you are * pleased with it. Here we cover general rules and syntax * for Stata graphics commands, starting with their general structure, * followed by illustrations showing how options work in the same way * across different kinds of commands. twoway (scatteri 6 0 "Kinds of graphs Stata can make", mlabsize(huge) pstyle(p1)) /// (scatteri 5 0 "Schemes for controlling look of graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 4 0 "Structure of graph commands", mlabsize(huge) pstyle(p2)) /// (scatteri 3 0 "graph options", mlabsize(huge) pstyle(p1)) /// (scatteri 2 0 "Building complex graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 1 0 "Additional examples", mlabsize(huge) pstyle(p1)), /// xlabel(-.05 1) ylabel(-1 7) /// xscale(off) yscale(off) /// legend(off) /// note("The structure of Stata graph commands is not obvious from looking at examples." /// "Understanding the structure of graph commands makes it easier to write correct commands.", ring(0)) * Consider this basic scatterplot. To add a title * to this graph, you can use the "title()" option as illustrated * in the next example. use allstates, clear graph twoway scatter propval100 rent700 * Just as with any Stata command, the "title()" option comes after a comma, * and in this case, it contains a quoted string that becomes the title of * the graph. graph twoway scatter propval100 rent700, /// title("This is a title for the graph") * Starting with Stata version 8, options can have options of their own. * Let's put a box around the title of the graph. We can use * "title(, box)", placing "box" as an option within "title()". If the * default for the current scheme were to include a box, then we could * have used the "nobox" option to suppress it. graph twoway scatter propval100 rent700, /// title("This is a title for the graph", box) * Let's take the last graph and modify the title to make it small. We * can add another option to the "title()" option by adding the * "size(small)" option. Here we see that one of the options is a * keyword (e.g., "box") and that one allows us to supply a value * (e.g., "size(small)"). graph twoway scatter propval100 rent700, /// title("This is a title for the graph", box size(small)) * Say that we want the symbols to be displayed as squares. We can add * another option called "msymbol(S)" to indicate that we want the marker * symbol to be displayed as a square ("S" for square). This is a common * way to build up a Stata graph by adding one option at a time. graph twoway scatter propval100 rent700, /// title("This is a title for the graph", box size(small)) msymbol(S) * Another way to show the graph above is like this. graph twoway (scatter propval100 rent700, msymbol(S)), /// title("This is a title for the graph", box size(small)) /// * Let's return back to this simple scatterplot. Say that we want the * labels for the "x" axis to change from * 0 10 20 30 40 to 0 5 10 15 20 25 30 35 40. graph twoway scatter propval100 rent700 * Here we add the "xlabel()" option to label the "x" axis from 0 to 40, * incrementing by 5. But say that we want the labels to be displayed bigger. graph twoway scatter propval100 rent700, xlabel(0(5)40) * Here we add the "labsize()" option to increase the size of the labels * for the "x" axis. But, say that we were happy with the original * numbering (0 10 20 30 40) but wanted the labels to be huge. * How would we do that? graph twoway scatter propval100 rent700, xlabel(0(5)40, labsize(huge)) * The "xlabel()" option we use here indicates that we are content with * the numbers chosen for the label of the "x" axis because we have nothing * before the comma. After the comma, we add the "labsize()" option to * increase the size of the labels for the "x" axis. graph twoway scatter propval100 rent700, xlabel( , labsize(huge)) * Let's consider some examples using the * "legend()" option to show that * some options do not require or permit * the use of commas within them. Also, this * allows us to show a case where you might * properly specify an option over and over again. * Here we show two "y" variables, "propval100" and "rent700", graphed * against population density, "popden". Note that Stata has created a * legend, helping us see which symbols correspond to which variables. * We can use the "legend()" option to customize it. graph twoway scatter propval100 rent700 popden * Using the "legend(cols(1))" option, we make the legend display in a * single column. Note that we did not use a comma because, with the * legend option, there is no natural default argument. If we had * included a comma within the "legend()" option, Stata would have * reported this as an error. graph twoway scatter propval100 rent700 popden, legend(cols(1)) * This example adds another option within the "legend()" * option, the "label()" option, which changes the label for the first * variable. graph twoway scatter propval100 rent700 popden, /// legend(label(1 "Property Value") cols(1) ) * Here we add another "label()" option for the "legend()" option, but * in this case, we change the label for the second variable. Note that * in this case, we can use the "label()" option repeatedly to change * the label for the different variables. graph twoway scatter propval100 rent700 popden, /// legend(cols(1) order(2 1 )) * Finally, let's consider an example that shows how to use the * "graph twoway" command to overlay two plots, showing how each graph * can have its own options, and * how there can be overall options. * Consider this graph that shows a scatterplot predicting property value * from population density and shows a linear fit between these two * variables. Say that we wanted to change the symbol displayed in the * scatterplot and the thickness of the line for the linear fit. graph twoway (scatter propval100 popden) /// (lfit propval100 popden) * Note that we add the "msymbol()" option to the "scatter" command to * change the symbol to a square, and we add the "clwidth()" option to * the "lfit" command to make the line very thick. This shows that * when you overlay two plots, each plot can have its own options * that operate on its respective parts of the graph. However, some * parts of the graph are shared, for example, the title. graph twoway (scatter propval100 popden, msymbol(S)) /// (lfit propval100 popden, clwidth(vthick)) * Note that we add the "title()" option to the very end of the command * placed after a comma. That final comma signals that options concerning * the overall graph are to follow, in this case the "title()" option. graph twoway (scatter propval100 popden, msymbol(Oh)) /// (lfit propval100 popden, clwidth(vthick)), /// title("This is the title of the graph") twoway (scatteri 6 0 "Kinds of graphs Stata can make", mlabsize(huge) pstyle(p1)) /// (scatteri 5 0 "Schemes for controlling look of graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 4 0 "Structure of graph commands", mlabsize(huge) pstyle(p1)) /// (scatteri 3 0 "graph options", mlabsize(huge) pstyle(p2)) /// (scatteri 2 0 "Building complex graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 1 0 "Additional examples", mlabsize(huge) pstyle(p1)), /// xlabel(-.05 1) ylabel(-1 7) /// xscale(off) yscale(off) /// legend(off) /// note("Options work in the same way across different types of graphs." /// "For example, legends are controlled in the same way for scatterplots, box plots etc.", ring(0)) * If you want to customize the * display of a legend, you do it using the same options, whether you * are using a bar graph, a box plot, a scatterplot, or any other kind * of Stata graph. Let's look at a couple of examples. * Consider this "twoway scatter" command. We have added a "legend()" * option to make the legend display in the one o'clock position on * the graph, putting the legend in the top right corner. graph twoway scatter propval100 rent700 popden, legend(pos(1)) * Here we use the "graph bar" command, which is a completely different * command from the previous one. But, even though the graphs are different, * the "legend()" option we supply is the same and has the same effect. graph bar propval100 rent700, over(nsw) legend(pos(1)) * However, contrast this example with the previous two. The "graph matrix" * command does not support the "legend()" option because this graph * does not need or produce legends. Note that, even though we included * this additional irrelevant option, Stata ignored it and produced an * appropriate graph, anyway. graph matrix propval100 rent700 popden, legend(pos(1)) * Building Graphs * This section illustrates the process of building up complex * Stata graphs. twoway (scatteri 6 0 "Kinds of graphs Stata can make", mlabsize(huge) pstyle(p1)) /// (scatteri 5 0 "Schemes for controlling look of graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 4 0 "Structure of graph commands", mlabsize(huge) pstyle(p1)) /// (scatteri 3 0 "graph options", mlabsize(huge) pstyle(p1)) /// (scatteri 2 0 "Building complex graphs", mlabsize(huge) pstyle(p2)) /// (scatteri 1 0 "Additional examples", mlabsize(huge) pstyle(p1)), /// xlabel(-.05 1) ylabel(-1 7) /// xscale(off) yscale(off) /// legend(off) /// note("You can build complex graphs one step at a time." /// "We will focus on the process of building complex graphs, not the content", ring(0)) * Say that we want to create this graph. Please ignore the first graph * command and just see the "graph display" command. Trying to create * this graph might seem overwhelming at first to determine all of the * options needed to make this graph. To ease our task, we will build it * up one bit at a time, refining the graph and fixing any problems we find. use allstates, clear set scheme vg_past graph bar propval100, over(nsw) over(division, label(angle(45))) nofill /// ytitle("% homes over $100K") ylabel(0(10)80, angle(0)) b1title(Region) /// legend(rows(1) pos(1) ring(0)) blabel(bar, format(%4.2f)) asyvars graph display * We start by seeing that this is a bar chart. We take our first step * towards making this graph by making a bar chart showing "propval100" * and adding "over(nsw) over(division)" to break the means down by "nsw" * and "division". graph bar propval100, over(nsw) over(division) * The previous graph is not quite what we want because we see every * level of "region" shown with every level of "nsw", but for example, * the "Pacific" region only appears in the "West". Adding the "nofill" * option shows just the combinations of "nsw" and "division" that exist * in the data file. Next, we will look at the colors of the bars. graph bar propval100, over(nsw) over(division) nofill * The last graph is getting closer, but we want the bars for "North", * "South", and "West" to be different colors and labeled with a legend. * Adding the "asyvars" option will accomplish this for us. * Next, we will look at changing the title for the "y" axis. graph bar propval100, over(nsw) over(division) nofill asyvars * Now, we want to put a title on the "y" axis. We use "ytitle()" for * putting a title on the "y" axis. Here we put a title on the "y" axis, * but now we want to change the labels for the "y" axis to go from * 0 to 80 incrementing by 10. graph bar propval100, over(nsw) over(division) nofill asyvars /// ytitle("% homes over $100K") * In addition to changing the labels, we also want to change the * angle of the labels, and in that section we see that we can use the * "angle()" option to change the angle of the labels. Now that we have * the "y" axis labeled as we wish, let's next look at the title for * the "x" axis. graph bar propval100, over(nsw) over(division) nofill asyvars /// ytitle("% homes over $100K") ylabel(0(10)80, angle(0)) * After having used the "ytitle()" option to label the "y" axis, we might * be tempted to use the "xtitle()" option to label the "x" axis, but this * zxis is a categorical variable. To put a title below the graph, we use * the "b1title()" option. Now, let's turn our attention to formatting * the legend. graph bar propval100, over(nsw) over(division) nofill asyvars /// ytitle("% homes over $100K") ylabel(0(10)80, angle(0)) b1title(Region) * Here we want to use the "legend()" option to make the legend have one * row in the top right corner within the plot area. graph bar propval100, over(nsw) over(division) nofill asyvars /// ytitle("% homes over $100K") ylabel(0(10)80, angle(0)) b1title(Region) /// legend(rows(1) pos(1) ring(0)) * We want each bar to be labeled with the height of the bar. We can label * the bars with their height, using "blabel(bar)" option. graph bar propval100, over(nsw) over(division) nofill asyvars /// ytitle("% homes over $100K") ylabel(0(10)80, angle(0)) b1title(Region) /// legend(rows(1) pos(1) ring(0)) blabel(bar) * We want the labels for each bar to end in 2 decimal places. We can add * the "format()" option to format these numbers as we wish. graph bar propval100, over(nsw) over(division) nofill asyvars /// ytitle("% homes over $100K") ylabel(0(10)80, angle(0)) b1title(Region) /// legend(rows(1) pos(1) ring(0)) blabel(bar, format(%4.2f)) * Finally, we can add the "label(angle(45))" option to the "over()" option * to specify that labels for that variable be shown at a 45-degree angle * so they do not overlap each other. graph bar propval100, over(nsw) over(division, label(angle(45))) nofill /// ytitle("% homes over $100K") ylabel(0(10)80, angle(0)) b1title(Region) /// legend(rows(1) pos(1) ring(0)) blabel(bar, format(%4.2f)) asyvars * So what kinds of things can you do with Stata graphs? twoway (scatteri 6 0 "Kinds of graphs Stata can make", mlabsize(huge) pstyle(p1)) /// (scatteri 5 0 "Schemes for controlling look of graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 4 0 "Structure of graph commands", mlabsize(huge) pstyle(p1)) /// (scatteri 3 0 "graph options", mlabsize(huge) pstyle(p1)) /// (scatteri 2 0 "Building complex graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 1 0 "Additional examples", mlabsize(huge) pstyle(p2)), /// xlabel(-.05 1) ylabel(-1 7) /// xscale(off) yscale(off) /// legend(off) /// note("Let's look at some more graphs you can make using Stata graphs." "We will focus on the graphs, not the commands", ring(0)) * Consider this graph with a scatterplot and diagonal line. set scheme vg_s2c use allstates, clear graph twoway (scatter urban pcturban80) (function y=x, range(30 100)), /// xtitle(Percent Urban 1980) ytitle(Percent Urban 1990) /// legend(order(2 "Line where % Urban 1980 = % Urban 1990") pos(6) ring(0)) * In this example we place a title in an open position in the graph. graph twoway scatter ownhome borninstate, /// by(nsw, hole(1) title("%Own home by" "%born in St." "by region", /// pos(11) ring(0) width(65) height(35) justification(center) /// alignment(middle)) note("")) * Consider this index plot with labels showing possible outliers. use allstates, clear regress ownhome propval100 workers2 urban predict rs, rstudent predict cd, cooks predict l, leverage generate id = _n twoway (scatter rs id, text( -3 27 "Possible Outliers", size(vlarge))) /// (scatteri -3 18 -4.8 10, recast(line)) /// (scatteri -3 18 -3 3, recast(line)), legend(off) xtitle(observation number) /// ytitle(standardized residual) * Here is a graph of leverage versus residuals with the * markers sized and labeled with cooks distance. twoway (scatter rs l [aw=cd], msymbol(Oh)) /// (scatter rs l if cd >= .1, msymbol(i) mlabel(stateab) mlabpos(0)) /// (scatter rs l if cd >= .1, msymbol(i) mlabel(cd) mlabpos(6)), legend(off) * Here is a population pyramid set scheme s2color clear use pop2000mf gen malmil = -maletotal/1000000 gen femmil = femtotal/1000000 gen zero = 0 twoway (bar malmil agegrp, horizontal) (bar femmil agegrp, horizontal) /// (scatter agegrp zero, mlabel(agegrp) mlabcolor(black) msymbol(i)), /// yscale(off) ylabel(, nogrid) xtitle("Population in millions") /// xlabel(-12 "12" -8 "8" -4 "4" 4 8 12) legend(order(1 "Male" 2 "Female")) * Wrapping up twoway (scatteri 4 0 "Saving graphs", mlabsize(huge) pstyle(p1)) /// (scatteri 3.5 .1 "Copy and paste", mlabsize(huge) pstyle(p1)) /// (scatteri 3.0 .1 "graph export test.eps", mlabsize(huge) pstyle(p1)) /// (scatteri 2 0 "Web for more information", mlabsize(huge) pstyle(p1)) /// (scatteri 1 0 "Door prize", mlabsize(huge) pstyle(p1)), /// title("Wrapping up") /// xlabel(-.05 1) ylabel(-1 5) /// xscale(off) yscale(off) /// legend(off) * Door prize local seed 1234 local n 10 display int(uniform()*`n')+1