First, providing a MCVE is always a good first step (and fairly easy given Stata's sysuse
and webuse
commands). Now, on to the question.
See help regress postestimation
and help predict
for the proper syntax for generating new variables with residuals, etc. The syntax is a bit different from the gen
command, as you will see below.
Note also that your drop if
condition is improperly formatted, and right now is interpreted as drop if st_res1 != 0 | st_res2 > 3.0
. (I also assume you want to drop standardized residuals < -3.0, but if this is incorrect, you can remove the abs()
function.)
sysuse auto , clear
replace mpg = 10000 in 1/2
replace mpg = 0.0001 in 70
reg mpg weight if foreign
predict rst_for , rstandard
reg mpg weight if !foreign
predict rst_dom , rstandard
drop if abs(rst_for) > 3.0 | abs(rst_dom) > 3.0
Postscript: Note that you may also consider adding if e(sample)
to your predict
commands, depending on whether you wish to extrapolate the results of the subsample regression to the entire sample and evaluate all residuals, or whether you only wish to drop observations based on in-sample standardized residuals.