Hello guys,

I have a monthly panel data for periods 1996m1 to 2018m12. Using the code below, I have estimated cross-sectional regressions for each period and saved the predicted values and residuals in variables xb and resid respectively.

Code:
rangestat (reg) flow mreturn1 netexpense noload mreturn_sd1 lsize_lag lage lagflow_19, interval(date 0 0)
drop reg_* se_*
gen double xb = b_mreturn1*mreturn1 + b_netexpense*netexpense + b_noload*noload + b_mreturn_sd1*mreturn_sd1 + b_lsize_lag*lsize_lag + b_lage*lage + b_lagflow_19*lagflow_19 + b_cons
gen double resid = flow - xb
I am now trying to figure out how to do a for loop so that for each month I can get a "simulated" flow variable, which is xb + bootstrapped resid (a randomly chosen residual from resid from the same cross-section). I need to do 1000 simulations and then run a reghdfe regression using this "simulated" flow variable:

Code:
reghdfe simulatedflow x1 x2 x3, a(date) vce(cluster date fund_id)
Is anyone aware of how to best use a for loop here?

Thanks