|
|
|
||||
|
|
|||||
and say that you wanted to see the scatterplot and regression line between write and read. In Stata version 7 you might have done something like this.use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear
And you would get a graph that looks something like this.regress write read predict yhat graph write yhat read, twoway symbol(oi) connect(.l) jitter(2) sort
But if you execute the graph command in Stata version 8 or later you get this error message.
You get this error message because the syntax of the graph command has been completely revised (and substantially enhanced) since version 8 and the syntax that you would have used in version 7 is not compatible with the current syntax.writegraph_g.new yhat read, twoway symbol(oi) connect(.l) jitter(2) sort: class member function not found write is not a valid graph subcommand r(198);
and this produces a graph that looks just like you were using Stata version 7. Another trick is to use the version command to instruct Stata to run the graph command as though you were using version 7, as shown below.graph7 write yhat read, twoway symbol(oi) connect(.l) jitter(2) sort
and again this produces a graph that looks just like you were using Stata version 7. If you are going to run a series of graph commands, you can issue a version 7 command on its own line and then all subsequent commands (graph commands and other types of commands) run as though they were from Stata version 7. This continues until you quit Stata or issue another version command on its own line. This is illustrated below.version 7: graph write yhat read, twoway symbol(oi) connect(.l) jitter(2) sort
The strategy you choose will depend on the situation. These strategies work the same way in the Stata command window or in a Stata .do file.version 7 graph write yhat read, twoway symbol(oi) connect(.l) jitter(2) sort graph write graph read version 8 /* or 9 or 10 */
The graph twoway type includes the following graphs among others:graph twoway scatterplots, line plots, etc. graph matrix scatterplot matrices graph bar bar charts graph dot dot charts graph box box and whisker plots graph pie pie charts
Thus, a scatterplot can be done three different ways:scatter scatterplot line line plot connected connected-line plot area line plot with shading spike spike plot dot dot plot lowess LOWESS line plot lfit linear prediction plot qfit quadratic prediction plot lfitci linear prediction plot with CIs qfitci quadratic prediction plot with CIs function line plot of function histogram histogram plot kdensity kernel density plot
However, if you want to combine several twoway graphs in one plot, you will need to include the twoway type declaration. The following are examples of ways that you can produce the scatterplot and regression line that we tried in Stata 7 above.graph twoway scatter write read twoway scatter write read scatter write read
All of these constructions produce a graph that looks like this.graph twoway (scatter write read, jitter(2)) (lfit write read, sort ) twoway (scatter write read, jitter(2)) (lfit write read, sort ) graph twoway scatter write read, jitter(2) || lfit write read, sort twoway scatter write read, jitter(2) || lfit write read, sort
Note this will not work:
Note: The separate plots indicated by enclosing the specific command in parentheses "()" or by separating the commands with two vertical bars "||".(scatter write read) (lfit write read)
Note that, in both, symbol and connect the list of indicators is given without spaces. In newer versions of Stata you need to include a space between each of the items in the list. Further, you should change the option symbol to msymbol (for marker symbol). The equivalent Stata 8 or later command will look like this:graph write yhat read, twoway symbol(oi) connect(.l) jitter(2) sort
scatter write yhat read, msymbol(o i) connect(. l) jitter(2) sortThe above comments cover only a few of the many ways in which the current version of Stata graphics differ from the Stata 7 version. It is well worth you time to sit down and read the Stata Online Graphics Manual and see the Stata Topics: Graphics.
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services