I am stuck on the below code, which was posted before and was successful for the OP but I can't seem to obtain the same success. The code seems to run through very quickly while creating no values. I tried playing around a bit, such as removing the sic_year_numerosity restriction, but I still get the same end result of no values being created. I am not sure whats happening.
gen y_hat=. // empty variable for predictions
gen y_res=. // empty variable for residuals
tempvar acc_tot_fitted acc_tot_res // temporary variables for each set of predictions
levelsof sic_2_digit, local(levels)
foreach x of local levels {
foreach z of numlist 1999/2014 {
capture reg y x1 x2 x3 if sic_2_digit==`x' & year==`z' & sic_year_numerosity>9
if !_rc {
predict `y_hat' // predictions are now in temporary variable
replace y_hat=`y_hat' if e(sample) // transfer predictions from temp variable
predict `y_res', residuals // residuals are now in temporary variable
replace y_res=`y_res' if e(sample) // transfer residuals from temp variable
drop `y_hat' `acc_tot_res' // drop temporary variables in preparation for next regression
}
}
}
gen y_hat=. // empty variable for predictions
gen y_res=. // empty variable for residuals
tempvar acc_tot_fitted acc_tot_res // temporary variables for each set of predictions
levelsof sic_2_digit, local(levels)
foreach x of local levels {
foreach z of numlist 1999/2014 {
capture reg y x1 x2 x3 if sic_2_digit==`x' & year==`z' & sic_year_numerosity>9
if !_rc {
predict `y_hat' // predictions are now in temporary variable
replace y_hat=`y_hat' if e(sample) // transfer predictions from temp variable
predict `y_res', residuals // residuals are now in temporary variable
replace y_res=`y_res' if e(sample) // transfer residuals from temp variable
drop `y_hat' `acc_tot_res' // drop temporary variables in preparation for next regression
}
}
}
Comment