*! version 1.0.1 01nov2022

Title

cooksd2 -- Cook's distance after regress or xtreg

Syntax

cooksd2
newvar
[, cvars(indepvars)
parms(newvar)
panel(varname)
noconstant]

Description

cooksd2 generates Cook's (1977) distance measures after regress or xtreg, which summarize the effect of deleting an observation, or an
entire subject, on the estimated regression coefficients. The procedure uses efficient updating formulas, based on Christensen et al. (1992) and
Banerjee and Frees (1997). For further details, see Vincent, D. (2022, September)

Options

cooksd2 newvar generates newvar containing the Cook's distance measures and their percentiles newvar_pr_F and newvar_pr_chi2 of
the F-, and chi-square distributions.

cvars(indepvars) restricts Cook's distance to the influence on the J-coefficients of the explanatory variables specified in
indepvars, including the constant. The default is to include all K-coefficients in the model, which is appropriate when each are of equal interest.

parms(newvar) adds the corresponding jackknifed regression coefficients to the dataset. These take the variable names with prefix newvar_b_. For
the panel data estimators, the standard deviations of the errors are also added, with the names newvar_sigma_e, newvar_sigma_u and
newvar_sigma_b for the between-effects estimator.

panel([varname]) evaluates the influence of an entire subject. After xtreg, this is the panelvar specified in xtset
and varname cannot be specified. After regress, any grouping of the data can be applied and varname specifies to which group
each observation belongs.

noconstant excludes the regression constant in the Cook's distance calculation. This is helpful when the influence on
the constant is unimportant.

Remarks

The Cook's distance of a data point or subject, can be compared to the percentiles of an F(J,N-K)-distribution, to determine what confidence region
for the unknown parameters, is attained by the distance between the full sample and leave-one-out estimates. Suppose, for example, that the Cook's distance Di
of the ith data point corresponds to the 50th percentile of the F-distribution. Then, the removal of this observation, moves the estimated
coefficients to the edge of a 50% confidence region for the unknown parameters based on the full sample estimates. Since the 50th-percentile of
the F(J,N-K) distribution is approximately 1 when J and N are large, some texts suggest that data points (or subjects) where Di>1 are influential,
whereas others use 4/N. In general, it is preferrable to look for large relative differences and not just whether the values exceed suggested cut-offs.

cooksd2 computes the Cook’s distance statistics and their percentiles of the F(J,N-K)-distribution. The percentiles that correspond to J*Di,
are also reported for the chi-square distribution with J-degrees of freedom. This is appropriate when confidence regions are based on the asymptotic
distributions.

Technical Note

When cvars(indepvars) is included, all of the parameters in the model are still updated when each observation (or subject) is removed, but only those
associated with the regressors in indepvars are used in the calculation of the Cook's distance statistic.

To obtain an efficient updating formula for the random effects estimator when the variance parameters change (i.e., omitting a row or subject), the transformed data for the ith
subject is based on both Ti and the average group size Tbar, rather than Ti only. Thus, when the panels are balanced, Ti=Tbar, and the jackknifed parameters
will be the same as those generated by jackknife, but when the panels are unbalanced, the coefficients will differ slightly.

Examples

Setup

. use http://www.stata-press.com/data/imeus/traffic,clear

. xtset state year

Ordinary least-squares regression

. reg fatal spircons unrate yngdrv c.spircons#c.yngdrv

Influence of each row

. cooksd2 cd_ols

Influence of each state

. cooksd2 cd_ols2, panel(state)

Influence of each year

. cooksd2 cd_ols3, panel(year)

Fixed-effects regression

. xtreg fatal spircons unrate yngdrv c.spircons#c.yngdrv, fe

Influence of each row and add jackknifed coefficients

. cooksd2 cd_fe, parms(fe)

Influence of each state

. cooksd2 cd_fe2, panel

Random-effects regression

. xtreg fatal spircons unrate yngdrv c.spircons#c.yngdrv, re

Influence of each row on all coefficients excluding the constant and add jackknifed coefficients

. cooksd2 cd_re, parms(re) nocons

Influence of each row on subsets of the coefficients including the constant

. cooksd2 cd_re2, cvars(spircons unrate)

Between-effects regression

. xtreg fatal spircons unrate yngdrv c.spircons#c.yngdrv, be

Influence of each row

. cooksd2 cd_be

Influence of each state

. cooksd2 cd_be2, panel

References

Banerjee, M., & Frees, E. W. (1997).
Influence diagnostics for linear longitudinal models. Journal of the American Statistical Association, 92(439), 999-1005.

Christensen, R., Pearson, L. M., & Johnson, W. (1992).
Case-deletion diagnostics for mixed models. Technometrics, 34(1), 38-45.

Cook, R. D. (1977).
Detection of influential observation in linear regression. Technometrics, 19(1), 15-18.

Vincent, D. (2022, September).
Cook’s distance measures for panel data models. In London Stata Conference 2022 (No. 03). Stata Users Group.

Author

This command was written by David Vincent (dvincent@dveconometrics.co.uk).
Comments and suggestions are welcome.