I would like to run several regression via a foreach-loop, calculate marginal effects, store and compare them. So far I managed to calculate the loop. I am able to store normal estimates in a table. I can access one marginal effect at a time, since its in a matrix object. That's where I got stuck. Related posts are:
Thank you
- https://www.statalist.org/forums/for...sion-in-a-loop
- https://www.statalist.org/forums/for...s-from-margins
HTML Code:
*************************************************
* Load Panel Data
*************************************************
webuse nlswork, clear
xtset idcode
*************************************************
* Loop for different outcomes
local outcomes "ln_wage hours wks_work"
foreach o of local outcomes {
quietly xtreg `o' age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure c.tenure#c.tenure, fe
estimates store reg_`o'
}
estimates table reg_ln_wage reg_hours reg_wks_work
*************************************************
*************************************************
* Loop regressions and save marginal effects (difficult due to matrix object)
local outcomes "ln_wage hours wks_work"
foreach o of local outcomes {
quietly xtreg `o' age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure c.tenure#c.tenure, fe
margins, dydx(age)
matrix B`o' = r(b)
}
* to be continued
*************************************************

Comment