Hello Statalist,
I need to bootstrap marginal effects from the two-part model as suggested in Belotti et al. 2015 (https://journals.sagepub.com/doi/pdf...867X1501500102). I have 40 equations (sub-sample groups) altogether, and instead of running each equation, I want to use do-loop to bootstrap the marginal effects of each estimate. I have tried to do this using the foreach loop, but stata breaks the loop when it encounters the end command. Would you mind offering some advice so that I do not have to define the program and bootstrap for each estimate?
foreach sex in male female {
foreach agegroup in age1824 age2544 age4564 age6574 age75over {
foreach region in midw south neast west {
capture program drop dydx_boot`sex'`agegroup'`region'
program define dydx_boot`sex'`agegroup'`region', eclass
svy: twopm totexp $varinterest $indepvar if `sex' ==1 & `agegroup' == 1 & `region' == 1, firstpart(logit) secondpart(glm, family(gamma) link(log))
margins, dydx($varinterest) predict(duan) nose post
end
}
}
}
foreach sex in male female {
foreach agegroup in age1824 age2544 age4564 age6574 age75over {
foreach region in midw south neast west {
bootstrap _b, seed(12345) reps(1000): dydx_boot`sex'`agegroup'`region'
}
}
}
Thank you so much for your thoughts and expertise!
Best,
Ramesh
I need to bootstrap marginal effects from the two-part model as suggested in Belotti et al. 2015 (https://journals.sagepub.com/doi/pdf...867X1501500102). I have 40 equations (sub-sample groups) altogether, and instead of running each equation, I want to use do-loop to bootstrap the marginal effects of each estimate. I have tried to do this using the foreach loop, but stata breaks the loop when it encounters the end command. Would you mind offering some advice so that I do not have to define the program and bootstrap for each estimate?
foreach sex in male female {
foreach agegroup in age1824 age2544 age4564 age6574 age75over {
foreach region in midw south neast west {
capture program drop dydx_boot`sex'`agegroup'`region'
program define dydx_boot`sex'`agegroup'`region', eclass
svy: twopm totexp $varinterest $indepvar if `sex' ==1 & `agegroup' == 1 & `region' == 1, firstpart(logit) secondpart(glm, family(gamma) link(log))
margins, dydx($varinterest) predict(duan) nose post
end
}
}
}
foreach sex in male female {
foreach agegroup in age1824 age2544 age4564 age6574 age75over {
foreach region in midw south neast west {
bootstrap _b, seed(12345) reps(1000): dydx_boot`sex'`agegroup'`region'
}
}
}
Thank you so much for your thoughts and expertise!
Best,
Ramesh
Comment