Export margins from Stata to Excel


This post show how to report margsin after a regression model. In case you are interested in reporting a nested table or several margin equations, please read this post.

To create a table of margins after any regression command, we should start by estimating the regression model. After that, where we run the margins command, we should prepend asdocx to the beginning of the line. Additionally, we can include other asdocx options after a comma, such as the dec() and replace options. In the following example, I will demonstrate how to create a detailed table of margins.

* Load some example data
webuse fullauto

* Create a factor variable for 
gen x = mod(_n,2)

* Estimate regression without using asdocx
ologit rep77 i.foreign i.x length mpg

* add asdocx to the margin command: replace, nest and tzok belong to asdocx
asdocx margins foreign x, replace save(ologi.xlsx) abb(.)
Predictive margins
Coef. St.Err. t-value p-value [95% Co Interval] Sig
1bn._predict#0bn.foreign 0.105 0.055 1.91 0.056 -0.003 0.213 *
1bn._predict#1.foreign 0.007 0.006 1.27 0.203 -0.004 0.018
1bn._predict#0bn.x 0.053 0.03 1.75 0.079 -0.006 0.112 *
1bn._predict#1.x 0.042 0.024 1.71 0.087 -0.006 0.089 *
2._predict#0bn.foreign 0.255 0.062 4.09 0 0.133 0.378 ***
2._predict#1.foreign 0.038 0.02 1.92 0.054 -0.001 0.077 *
2._predict#0bn.x 0.182 0.054 3.40 0.001 0.077 0.287 ***
2._predict#1.x 0.154 0.046 3.37 0.001 0.064 0.244 ***
3._predict#0bn.foreign 0.412 0.064 6.49 0 0.288 0.537 ***
3._predict#1.foreign 0.196 0.062 3.17 0.002 0.075 0.317 ***
3._predict#0bn.x 0.413 0.059 7.01 0 0.298 0.529 ***
3._predict#1.x 0.402 0.06 6.75 0 0.286 0.519 ***
4._predict#0bn.foreign 0.2 0.046 4.34 0 0.11 0.29 ***
4._predict#1.foreign 0.468 0.094 4.99 0 0.284 0.651 ***
4._predict#0bn.x 0.284 0.06 4.75 0 0.167 0.402 ***
4._predict#1.x 0.319 0.061 5.20 0 0.199 0.439 ***
5._predict#0bn.foreign 0.027 0.015 1.78 0.075 -0.003 0.057 *
5._predict#1.foreign 0.291 0.121 2.41 0.016 0.054 0.527 **
5._predict#0bn.x 0.068 0.028 2.38 0.017 0.012 0.123 **
5._predict#1.x 0.083 0.036 2.32 0.02 0.013 0.153 **
Mean dependent var 0.500 SD dependent var 0.504