Dear all,

I would like to implement a loop over a dependent variable in an rclass program.

This is the procedure I am following: https://stats.idre.ucla.edu/stata/fa...l-iv-in-stata/ - This code works fine.

However, when I use this exact code and implement the follwing loop for the dependent variable, the code leads Stata to break before the bootstrap command (return code 1).
Code:
foreach var of varlist dv1 dv2 {   
  capture drop program bootcm    
  program bootcm, rclass     

   sureg (math i.ses)(`var' math i.ses)     
   return scalar inds2    = [math]_b[2.ses]*[`var']_b[math]     
   return scalar inds3    = [math]_b[3.ses]*[`var']_b[math]     
   return scalar indtotal = [math]_b[2.ses]*[`var']_b[math] + ///                            
      [math]_b[3.ses]*[`var']_b[math]    
  end    

  bootstrap r(inds2) r(inds3) r(indtotal), reps(5000) nodots: bootcm   
}
Could you please help me in why this happens?

Thank you!
Jana