Dear members of the list,

In order to save time and make my do-file shorter and clearer, I'd like to run a loop that would include a list of nested models, generating marginal effects and storing them after each model.The final goal is to save the subsequent table in an Excel file.

The list of models and coding is as follows:

PHP Code:
mlogit vardep X1baseoutcome(2)
estpost marginsdydx(*) predict(outcome(2))
estimates store m1title (Model 1)

mlogit vardep X1 X2baseoutcome(2)
estpost marginsdydx(*) predict(outcome(Other_studies))
estimates store m2title (Model 2)

mlogit vardep X1 X2 X3baseoutcome(2)
estpost marginsdydx(*) predict(outcome(Other_studies))
estimates store m3title (Model 3)

mlogit vardep X1 X2 X3 X4baseoutcome(2)
estpost marginsdydx(*) predict(outcome(Other_studies))
estimates store m4title (Model 4)

mlogit vardep X1 X2 X3 X4 X5baseoutcome(2)
estpost marginsdydx(*) predict(outcome(Other_studies))
estimates store m5title (Model 5)

esttab m1 m2 m3 m4 m5 using "[PATH]...\Expectativas_ocuma1.csv"///
    
cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons Constantstats(r2nobaselevels unstack noomitted replace 

It is easy to see that the lines after each model are common to all the models.Thus, it should be easy to make a loop summarising all this coding. But I do not know how to include the different models in the loop. Shall I use foreach, or different globals capturing each one the list of variables in each model?

Thanks for your attention

Kind regards

Luis Ortiz