I am trying to do a bootstrap exercise where I run a regression for each bootstrap and then compute a number of further exercises for each bootstrap and then run another regression. My output I would like is a bootstrap estimate of the std error for the last regression. I am struggling to understand the manual, but I think should be a fairly simple task. In other words, is it possible to run a bootstrap program where multiple lines of code are included in the bootstrap rather than just the one line that seems to be in all the manual examples.

I have mocked up a basic example here using the auto data. I want to run a regression for a subset of data, and then I want to predict the fitted value for the full data, and then run a second regression on those fitted values. (This is only a mock, so I am not interested in other ways to do this simple task. In practice I have another 20 lines of code that I would like to run for each bootstrap).

How do i get a bootstrap estimate of the second regression, knowing that i need to run a bootstrap for the first 3 lines of code as well.

Code:
sysuse auto, clear

bootstrap, reps(5): areg price trunk weight displ if headroom<3, a(foreign)
predict Xprice_tmp, d
egen Xprice                                            = mean(Xprice_tmp), by(foreign) 
reg headroom Xprice
Cheers,
Mike