Dear Stata Users,
I searched the forum for examples showing how to transform the output from the margins command into a table using the new collect command.
I didn't find anything, but after reading the help files and much experimentation, I found some code that works. Hopefully this will save someone else some time.
Other users may need to edit the winexec command so it points at excel.exe.
Jeremy
I searched the forum for examples showing how to transform the output from the margins command into a table using the new collect command.
I didn't find anything, but after reading the help files and much experimentation, I found some code that works. Hopefully this will save someone else some time.
Other users may need to edit the winexec command so it points at excel.exe.
Jeremy
Code:
use https://www.stata-press.com/data/r17/nlswork xtreg ln_w c.age c.age#c.age c.ttl_exp c.tenure i.not_smsa i.south i.race#c.tenure, fe *marginal effects by race collect clear collect: margins, dydx(tenure) over(race) collect stars _r_p 0.01 "**" 0.05 "*" 0.1 "+", shownote collect title "Marginal Effect of Tenure by Race" collect style cell result[_r_se _r_b], nformat(%8.7f) collect layout (race[1 2 3]) (result[_r_b _r_se _r_p stars]) collect export table1.xlsx, replace winexec "C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE" table1.xlsx *contrasts of marginal effects by race collect clear collect: margins, dydx(tenure) over(r.race) contrast(effects) collect stars _r_p 0.01 "**" 0.05 "*" 0.1 "+", shownote collect title "Marginal Effect of Tenure compared to whites" collect style cell result[_r_se _r_b], nformat(%8.7f) *collect label levels race 2 "Black vs. White" 3 "Other vs White", modify // edit row labels collect layout (race[2 3]) (result[_r_b _r_se _r_p stars]) collect export table2.xlsx, replace winexec "C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE" table2.xlsx
Comment