I am researching how outsourcing affects employees in terms of income, employment, and benefits and, next, how these effects are moderated by gender and education.
Now, I have made all my models and want to visualize them using margins. For the sake of brevity, I have used a loop:
Code:
*gender
foreach var of varlist income employment benefits {
xtreg `var' i.treatment##i.time##i.gender i.education covariates, fe cluster(id)
margins treatment, at(time=(1999 2000 2001 2002) gender = (0))
marginsplot, name(male_`var', replace) different options
margins treatment, at(time=(1999 2000 2001 2002) gender = (1))
marginsplot, name(female_`var', replace) different options
}
foreach var of varlist income employment benefits {
grc1leg male_`var' female_`var', ycommon name(gender_`var')
}
foreach var of varlist income employment benefits {
graph display gender_`var'
graph export gender_`var'.pdf, replace
}
**********************************************************
*education
foreach var of varlist income employment benefits {
xtreg `var' i.treatment##i.time##i.education i.gender covariates, fe cluster(id)
margins treatment, at(time=(1999 2000 2001 2002) education = (0))
marginsplot, name(edu0_`var', replace) different options
margins treatment, at(time=(1999 2000 2001 2002) education = (1))
marginsplot, name(edu1_`var', replace) different options
}
foreach var of varlist income employment benefits {
grc1leg edu0_`var' edu1_`var', ycommon name(edu_`var')
}
foreach var of varlist income employment benefits {
graph display edu_`var'
graph export edu_`var'.pdf, replace
}Is there a way to do this in the regression loop or afterwards? What I do not want is to stop using the loop and do everything manually. I hope somebody has a suggestion.
Best,
Gustav
0 Response to Looping to create marginsplots for different moderators but how to get the same y-axis?
Post a Comment