-------------------------------------------------------------------------------
help for regplot
-------------------------------------------------------------------------------

Plots of regress or similar fit

regplot [, plottype(plottype) fitopts(graph_options) separate(varname) scatter_options plot(plot) ]

regplot varname [, plottype(plottype) fitopts(graph_options) separate(varname) scatter_options plot(plot) ]

Description

regplot plots fitted or predicted values from an immediately previous regress or similar command. By default the data for the response are also plotted.

Remarks

With the first syntax, no varname is specified. regplot shows the response and predicted values on the y axis and the predictor named first in the regress or similar command on the x axis. Thus with this syntax the plot shown is sensitive to the order in which predictors are specified in the estimation command.

With the second syntax, a varname is supplied, which may name any numeric variable. This is used as the variable on the x axis. This permits changing graphs without reissuing the estimation command.

Thus in practice regplot is most useful when the fitted values are a smooth function of the variable shown on the x axis, or a set of such functions given also one or more dummy variables as predictors. However, other applications also arise, such as plotting observed and predicted values from a time series model versus time.

By default, regplot shows the fitted values using {help:twoway mspline}. The plottype() option may be used to specify another twoway plottype.

In more technical detail: regplot plots

1. both a single dependent or response variable as specified in e(depvar) and whatever single variable is calculated by the default of predict on the y axis, which makes sense whenever those variables are on the same scale;

2. either the varname specified or what names the first column of e(b) on the x axis, which makes sense whenever graph can understand that as specifying the x axis.

If your estimation results do not meet these specifications, you are likely to get either bizarre results or an error message. Note in particular that varname must be specified after nl.

Time series operators are allowed.

The plot is restricted to the estimation sample.

This command provides graphics after model fitting. Its aims thus differ from those of twoway lfit, twoway qfit, twoway fpfit, etc., which fit models on the fly and are restricted to the application of particular modelling commands.

Options

plottype() specifies an alternative to mspline as a twoway plottype for showing the fitted model values.

fitopts() specifies graph options tuning the display of fitted values.

separate() specifies that values of fitted and observed responses be plotted as separate groups corresponding to the distinct values of the variable specified.

scatter_options are options allowed with twoway scatter.

As usual, by(varname) specifies that predictions are to be shown separately for different categories of varname. This will often be appropriate when the categories of varname are associated with one or more dummy or indicator variables, but see also the separate() option.

plot(plot) provides a way to add other plots to the generated graph; see plot_option.

Examples

. sysuse auto

continuous variables only:

. regress mpg weight . regplot . gen weightsq = weight^2 . regress mpg weight weightsq . regplot

(N.B. weight shown on x axis in both cases)

categorical variable also:

. regress mpg weight foreign . regplot, by(foreign) . regplot, sep(foreign) . regress mpg weight weightsq foreign . regplot, by(foreign) . regplot, sep(foreign)

. gen fw = foreign * weight . regress mpg weight foreign fw . regplot, by(foreign) . regplot, sep(foreign)

commands other than regress:

. logit foreign weight . regplot

. glm mpg weight foreign, link(log) . regplot, by(foreign)

fit an AR(1) plus trend model to time series:

. regress ERvol L.ERvol date . regplot date

Author

Nicholas J. Cox, University of Durham, U.K. n.j.cox@durham.ac.uk

Acknowledgements

Ken Higbee and Kit Baum provided very helpful comments on an earlier version.

Also see