-------------
Why twoway's plottypes are convenient
-------------


Draw a few simple twoway graphs by clicking the next 4 commands.


. sysuse uslifeexp , replace
. keep if year <= 1940

. twoway scatter le year
. twoway line le year


Now, draw a simple twoway with two plots.


. twoway scatter le year || lfit le year


There are some options that make sense only to lfit and not
to scatter.  For example, we can ask lfit to produce
residuals rather than predictions of the dependent variable by
using the option predopts(resid).  A predopts() option would
not make sense on a 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.


. twoway scatter le year ||
	 lfit le year    ||
	 lfit le year , predopts(resid)


lfit assumes that you are drawing a fitted line and so creates a
line plottype.  That is not a very good way of plotting residuals,
but we can change to most other twoway plottypes by using the
recast() option to "recast" the plot to another plottype.  Let's
make our residuals droplines. (click below)


. twoway scatter le year ||
	 lfit le year ,  ||
	 lfit le year , predopts(resid) recast(dropline)


The recast() option is available on almost all twoway plottypes and
on most statistical graphics commands.


The syntax of plottypes in the twoway command makes plottypes almost
most complete commands in themselves.  We can even apply an if or
an in condition to a single plottype.  We do that below on the 2nd
linear fit (lfit), restricting its data to years prior to 1920. (click below)


. twoway scatter le year ||
	 lfit le year	 ||
	 lfit le year if year < 1920


-------------
<<   index   >>