*! version 0.0.4 08mar2024

Syntax

classify # [ if ] , pstub(string asis) [
threshold(real) pmethod(string asis)
popts(string asis)]

Required
pstub a new variable name for predicted values

Optional
threshold positive outcome threshold; default is threshold(0.5)

pmethod predicted statistic from predict; default is pmethod(pr)

popts options passed to predict in addition to the method

Description

classify is part of the crossvalidate suite of tools to implement
cross-validation methods with Stata estimation commands. classify is used
internally by the predictit command to handle conversion of predicted
probabilities into integer valued class memberships. classify will work
with binomial and multinomial (including ordinal) classification models. For
multinomial models, the class membership with the highest predicted probability
is selected as the class predicted by the model.

Options

Required

pstub is used to define a new variable name/stub for the predicted values
from the validation/test set. When K-Fold cross-validation is used, this
option defines the name of the variable containing the predicted values from
each of the folds and will be used as a variable stub to store the results from
fitting the model to all of the training data.

Optional

threshold defines the probability cutoff used to determine a positive
classification for binary response models. This value functions the same way
as it does in the case of estat classification.

pmethod is passed internally to Stata's predict command to
generate the predicted values of the outcome for the out-of-sample data. The
default in classify is to generate the predicted probabilities of class
membership.

popts is passed internally to Stata's predict command to
generate the predicted values of the outcome for the out-of-sample data. For
multivariate outcome models, like sureg, this option can be used to
specify which of the equations should be used to predict the outcome of interest.
It can also be used to specify the nooffset option in single or
multi-equation models. Consult the predict documentation for the model
you are fitting for more details.

Examples

Binary Classification Example

Load example data

webuse lbw, clear

Fit a model to the data

logit low age smoke) c

Use classify to generate the predicted classes

classify 2 if e(sample), ps(pred)

Multinomial Classification Example

Load example data

webuse sysdsn1, clear

Fit a model to the data

mlogit insure age male i.site) c

Use classify to generate the predicted classes

classify 3 if e(sample), ps(pred)

Ordinal Classification Example

Load example data

webuse fullauto, clear

Fit a model to the data

ologit rep77 price foreign) c

Use classify to generate the predicted classes

classify 5 if e(sample), ps(pred)

Additional Information

If you have questions, comments, or find bugs, please submit an issue in the crossvalidate GitHub repository.

Contact

William R. Buchanan, Ph.D.

Sr. Research Scientist, SAG Corporation

SAG Corporation

wbuchanan at sagcorp [dot] com

Steven D. Brownell, Ph.D.

Economist, SAG Corporation

SAG Corporation

sbrownell at sagcorp [dot] com