Plots of regress or similar fit
regplot7 [, graph_options separate(varname) ]
regplot7 varname [, graph_options separate(varname) ]
Description
regplot7 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. regplot7 shows the response and predicted values on the y axis and the covariate 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 covariates 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 regplot7 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 covariates. However, other applications also arise, such as plotting observed and predicted values from a time series model versus time.
In more technical detail: regplot7 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.
regplot7 is a renamed clone of regplot 1.2.0 which is for Stata 7. Stata 8 users should use regplot 2.0.0 or later.
Options
graph_options are options of graph, twoway.
The defaults include connect() of . for data and s for each subset of predicted values.
To suppress plotting of response data, specify i as the first symbol to be shown.
separate(varname) specifies that predictions are to be shown separately for different categories of varname. This will be most appropriate when the categories of varname are associated with one or more dummy or indicator variables.
Note that by(varname) may be employed as usual with regplot7 and it also may be combined with separate().
Examples
. use auto
continuous variables only:
. regress mpg weight
. regplot7
. gen weightsq = weight^2
. regress mpg weight weightsq
. regplot7
(N.B. weight shown on x axis in both cases)
categorical variable also:
. regress mpg weight foreign
. regplot7, sep(foreign) tr(1)
. regress mpg weight weightsq foreign
. regplot7, sep(foreign) tr(1)
. regplot7, by(foreign)
. regplot7, by(foreign) sep(foreign) tr(1) total
. gen fw = foreign * weight
. regress mpg weight foreign fw
. regplot7, sep(foreign) tr(1)
commands other than regress:
. logit foreign weight
. regplot7
. glm mpg weight foreign, link(log)
. regplot7, sep(foreign) tr(1)
fit an AR(1) plus trend model to time series:
. regress ERvol L.ERvol date
. regplot7 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.
Also see
On-line: help for regress, graph, regdiag, anovaplot (if installed), sparl (if installed) Manual: [U] 21 Programming Stata