能不能先把手册的命令大致看一下啊
Title
[R] stepwise -- Stepwise estimation
Syntax
stepwise [, options ] : command
options description
-----------------------------------------------------------------------------------------------------------
Model
* pr(#) significance level for removal from the model
* pe(#) significance level for addition to the model
Model2
forward perform forward-stepwise selection
hierarchical perform hierarchical selection
lockterm1 keep the first term
lr perform likelihood ratio-test instead of Wald test
-----------------------------------------------------------------------------------------------------------
* At least one of pr(#) or pe(#) must be specified.
by and xi are allowed; see prefix.
Weights are allowed if command allows them; see weight.
All postestimation commands behave as they would after command without the stepwise prefix; see the
postestimation manual entry for command.
Menu
Statistics > Other > Stepwise estimation
Description
stepwise performs stepwise estimation. Typing
. stepwise, pr(#): command
performs backward-selection estimation for command. The stepwise selection method is determined by the
following option combinations:
options description
-----------------------------------------------------------------------------------------------------------
pr(#) backward selection
pr(#) hierarchical backward hierarchical selection
pr(#) pe(#) backward stepwise
pe(#) forward selection
pe(#) hierarchical forward hierarchical selection
pr(#) pe(#) forward forward stepwise
-----------------------------------------------------------------------------------------------------------
command defines the estimation command to be executed. The following Stata commands are supported by
stepwise.
clogit, cloglog, glm, intreg, logistic, logit, nbreg, ologit, oprobit, poisson, probit, qreg, regress,
scobit, stcox, stcrreg, streg, tobit
stepwise expects command to have the following form:
command_name [depvar] term [term ...] [if] [in] [weight] [, command_options]
where term is either varname or (varlist) (a varlist in parentheses indicates that this group of variables
is to be included or excluded together). depvar is not present when command_name is streg, stcox, or
stcrreg; otherwise, depvar is assumed to be present. For intreg, depvar is actually two dependent variable
names (depvar1 and depvar2).
sw is a synonym for stepwise.
Options
+-------+
----+ Model +----------------------------------------------------------------------------------------------
pr(#) specifies the significance level for removal from the model; terms with p>=pr() are eligible for
removal.
pe(#) specifies the significance level for addition to the model; terms with p<pe() are eligible for
addition.
+--------+
----+ Model2 +---------------------------------------------------------------------------------------------
forward specifies the forward-stepwise method and may be specified only when both pr() and pe() are also
specified. Specifying both pr() and pe() without forward results in backward-stepwise selection.
Specifying only pr() results in backward selection, and specifying only pe() results in forward
selection.
hierarchical specifies hierarchical selection.
lockterm1 specifies that the first term be included in the model and not be subjected to the selection
criteria.
lr specifies the test of term significance be the likelihood-ratio test. The default is the less
computationally expensive Wald test; that is, the test is based on the estimated variance-covariance
matrix of the estimators.
Examples
Setup
. sysuse auto
. generate weight2 = weight^2
Backward selection
. stepwise, pr(.2): regress mpg weight weight2 displ gear turn headroom foreign price
Backward selection; consider engine displacement and gear ratio together
. stepwise, pr(.2): regress mpg weight weight2 (displ gear) turn headroom foreign price
Backward selection; force weight to be included in model
. stepwise, pr(.2) lockterm1: regress mpg weight weight2 displ gear turn headroom foreign price
Backward selection; force weight and weight2 to be included in model
. stepwise, pr(.2) lockterm1: regress mpg (weight weight2) displ gear turn headroom foreign price
Backward hierarchical selection
. stepwise, pr(.2) hierarchical: regress mpg weight weight2 displ gear turn headroom foreign
Forward selection
. stepwise, pe(.2): regress mpg weight weight2 displ gear turn headroom foreign price
Forward hierarchical selection
. stepwise, pe(.2) hierarchical: regress mpg weight weight2 displ gear turn headroom foreign price
Programming for stepwise
stepwise requires that command_name follow standard Stata syntax and allow the if qualifier. Furthermore,
command_name must have sw or swml as a program property; see [P] program properties. If command_name has
swml as a property, command_name must save the log-likelihood value in e(ll) and model degrees of freedom
in e(df_m).
Saved results
stepwise saves whatever is saved by the underlying estimation command.
Also, stepwise saves stepwise in e(stepwise).