Hi there, I am wondering if there is a way to call/use a macro defined outside of a program in a program. For example, if I run the following codes, it pops out an error message -r(1)-
But if I run the following codes, it works perfectly. Thus, I believe it's a problem of how to call outside defined macro in a program. Can anyone give me some suggestions?
Code:
use https://stats.idre.ucla.edu/stat/data/hsb2, clear local ivlist "write" local dvlist "socst" local medlist "math" foreach iv of local ivlist{ foreach med of local medlist{ foreach dv of local dvlist{ preserve capture program drop ind program ind, rclass gsem (`med' <- `iv') (`dv' <- `med' `iv') return scalar ind = _b[`med':`iv']*_b[`dv':`med'] end bootstrap r(ind), reps(5) seed(666): ind estat boot, bc restore } } }
Code:
use https://stats.idre.ucla.edu/stat/data/hsb2, clear preserve capture program drop ind program ind, rclass local ivlist "write" local dvlist "socst" local medlist "math" gsem (`med' <- `iv') (`dv' <- `med' `iv') return scalar ind = _b[`med':`iv']*_b[`dv':`med'] end bootstrap r(ind), reps(5000) seed(666): ind estat boot, bc restore
Comment