{smcl} {* 22aug2004}{...} {hline} {center:{hi:Why {cmd:twoway}'s plottypes are convenient}} {hline} {p 4 4 4}{it} Draw a few simple {cmd:twoway} graphs by clicking the next 4 commands. {sf} . {stata sysuse uslifeexp , replace} . {stata keep if year <= 1940} . {stata twoway scatter le year} . {stata twoway line le year} {p 4 4 4}{it} Now, draw a simple {cmd:twoway} with two plots. {sf} . {stata twoway scatter le year || lfit le year} {p 4 4 4}{it} There are some options that make sense only to {cmd:lfit} and not to {cmd:scatter}. For example, we can ask {cmd:lfit} to produce residuals rather than predictions of the dependent variable by using the option {cmd:predopts(resid)}. A {cmd:predopts()} option would not make sense on a {cmd:scatter} plottype. So, having the plottype appear early in the command lets us parse plottypes differently and allows each plottype to have unique options. Let's, draw the fit with residuals by clicking below. {sf} . {stata do twoway0a:twoway scatter le year ||} {stata do twoway0a:lfit le year ||} {stata do twoway0a:lfit le year , predopts(resid)} {p 4 4 4}{it} {cmd:lfit} assumes that you are drawing a fitted line and so creates a {cmd:line} plottype. That is not a very good way of plotting residuals, but we can change to most other twoway plottypes by using the {cmd:recast()} option to "recast" the plot to another plottype. Let's make our residuals {cmd:dropline}s. (click below) {sf} . {stata do twoway0b:twoway scatter le year ||} {stata do twoway0b:lfit le year , ||} {stata do twoway0b:lfit le year , predopts(resid) recast(dropline)} {p 4 4 4}{it} The {cmd:recast()} option is available on almost all twoway plottypes and on most statistical graphics commands. {p 4 4 4}{it} The syntax of plottypes in the twoway command makes plottypes almost most complete commands in themselves. We can even apply an {cmd:if} or an {cmd:in} condition to a single plottype. We do that below on the 2nd linear fit ({cmd:lfit}), restricting its data to years prior to 1920. (click below) {sf} . {stata do twoway0c:twoway scatter le year ||} {stata do twoway0c:lfit le year ||} {stata do twoway0c:lfit le year if year < 1920} {hline} {center:{view cmds.smcl:<<} {view tindex.smcl:index} {view anatomy101.smcl:>>}}