The standard output from sem
and gsem
(as well as generalized linear model commands such as ologit
and mlogit
) present the results for multiple equation models in one long column. Each equation is stacked, one underneath the next. Sometimes it facilitates our presentation to display the equations side by side, particularly if there are common independent variables that predict different responses.
We can approach this task with either Stata's estimates store
and estimates table
commands, or through Ben Jann's esttab
command. The first approach requires a little more set up coding by the user, while the second approach requires the user to install the estout
package.
Both commands include options to modify the numeric format, as well as include or suppress a variety of statistics.
For saving tables to include in other documents, esttab
incorporates several useful options.
First we'll set up an example, where a latent variable X
is measured by four binary indicators. We will assume the indicators have probit distributions. So we have four response variables predicted by a common independent variable.
Notice the standard results are presented in one long column.
. webuse gsem_1fmm
(single-factor pass/fail measurement model)
. quietly gsem (x1 x2 x3 x4 <- X), probit
. gsem
Generalized structural equation model Number of obs = 123
Response : x1
Family : Bernoulli
Link : probit
Response : x2
Family : Bernoulli
Link : probit
Response : x3
Family : Bernoulli
Link : probit
Response : x4
Family : Bernoulli
Link : probit
Log likelihood = -261.30263
( 1) [x1]X = 1
------------------------------------------------------------------------------
| Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
x1 |
X | 1 (constrained)
_cons | -.3666763 .1896773 -1.93 0.053 -.738437 .0050844
-------------+----------------------------------------------------------------
x2 |
X | 1.33293 .4686743 2.84 0.004 .4143455 2.251515
_cons | -.4470271 .2372344 -1.88 0.060 -.911998 .0179438
-------------+----------------------------------------------------------------
x3 |
X | .6040478 .1908343 3.17 0.002 .2300195 .9780761
_cons | -.2276709 .1439342 -1.58 0.114 -.5097767 .0544349
-------------+----------------------------------------------------------------
x4 |
X | 9.453342 5.151819 1.83 0.067 -.6440375 19.55072
_cons | -4.801027 2.518038 -1.91 0.057 -9.736291 .1342372
-------------+----------------------------------------------------------------
var(X)| 2.173451 1.044885 .847101 5.576536
------------------------------------------------------------------------------
In order to rearrange our equations side by side using Stata's estimates table
we are going to treat our results as if they came from four separate models, and then specify how they are to be matched (aligned) using the equation
option. We also specify a keep
option - otherwise estimates table
will display a lot of redundant information.
The estimates stores are strategically named for each response variable.
. estimates store x1
. estimates store x2
. estimates store x3
. estimates store x4
. estimates table x1 x2 x3 x4, eq(1:2:3:4) keep(X _cons)
------------------------------------------------------------------
Variable | x1 x2 x3 x4
-------------+----------------------------------------------------
X | 1 1.3329303 .60404779 9.4533423
_cons | -.36667631 -.44702712 -.22767088 -4.801027
------------------------------------------------------------------
Now we’ll repeat the same model presentation using esttab
. Assuming you already have the estout
package installed, we simply construct a table from the current estimates (indicated by the " . ") using the unstack
option. For this particular model we also drop the latent variance, with the obscure-looking drop
option, and suppress the t statistics.
. esttab ., unstack drop(/:) not
----------------------------------------------------------------------------
(1)
x1
x1 x2 x3 x4
----------------------------------------------------------------------------
X 1 1.333** 0.604** 9.453
_cons -0.367 -0.447 -0.228 -4.801
----------------------------------------------------------------------------
N 123
----------------------------------------------------------------------------
* p<0.05, ** p<0.01, *** p<0.001
If you want to save your results in a form that makes a nice table for inclusion in another document, esttab
can save tables in a number of formats.
Unstacking can produce really wide tables, so figuring out what sort of table you can use in a document may be a challenge. In this example I save to an html
table so I can include it in this document. If my goal was to put it in a Word document, I might try saving as rtf
or csv
.
For this example I suppress all the cutpoints in the final table.
Note the keyword for saving a file is using
, which is not typical Stata.
. use "http://www.stata-press.com/data/r15/gsem_cfa", clear
(Fictional math abilities data)
. quietly gsem (MathAb -> q1-q8, logit) ///
> (MathAtt -> att1-att5, ologit)
. gsem, noheader
( 1) [q1]MathAb = 1
( 2) [att1]MathAtt = 1
------------------------------------------------------------------------------
| Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
q1 |
MathAb | 1 (constrained)
_cons | .0446118 .1272964 0.35 0.726 -.2048845 .2941082
-------------+----------------------------------------------------------------
q2 |
MathAb | .3446081 .1050264 3.28 0.001 .1387601 .5504562
_cons | -.4572215 .0979965 -4.67 0.000 -.6492911 -.265152
-------------+----------------------------------------------------------------
q3 |
MathAb | .5445245 .1386993 3.93 0.000 .272679 .8163701
_cons | .1591406 .1033116 1.54 0.123 -.0433464 .3616276
-------------+----------------------------------------------------------------
q4 |
MathAb | .2858874 .0948553 3.01 0.003 .0999743 .4718004
_cons | -.3196648 .0947684 -3.37 0.001 -.5054075 -.1339222
-------------+----------------------------------------------------------------
q5 |
MathAb | .8174803 .1867024 4.38 0.000 .4515504 1.18341
_cons | -.04543 .116575 -0.39 0.697 -.2739127 .1830527
-------------+----------------------------------------------------------------
q6 |
MathAb | .6030448 .1471951 4.10 0.000 .3145478 .8915419
_cons | -.309992 .1070853 -2.89 0.004 -.5198753 -.1001086
-------------+----------------------------------------------------------------
q7 |
MathAb | .72084 .1713095 4.21 0.000 .3850796 1.056601
_cons | .1047265 .1116494 0.94 0.348 -.1141023 .3235552
-------------+----------------------------------------------------------------
q8 |
MathAb | .5814761 .1426727 4.08 0.000 .3018428 .8611094
_cons | -.0250442 .1045134 -0.24 0.811 -.2298868 .1797983
-------------+----------------------------------------------------------------
att1 |
MathAtt | 1 (constrained)
-------------+----------------------------------------------------------------
att2 |
MathAtt | .3788714 .0971223 3.90 0.000 .1885152 .5692276
-------------+----------------------------------------------------------------
att3 |
MathAtt | -1.592717 .3614859 -4.41 0.000 -2.301216 -.8842173
-------------+----------------------------------------------------------------
att4 |
MathAtt | -.8100107 .153064 -5.29 0.000 -1.11001 -.5100108
-------------+----------------------------------------------------------------
att5 |
MathAtt | .5225423 .1170141 4.47 0.000 .2931988 .7518858
-------------+----------------------------------------------------------------
/att1 |
cut1 | -1.10254 .1312272 -1.359741 -.8453396
cut2 | -.2495339 .1160385 -.4769651 -.0221027
cut3 | .2983261 .1164414 .0701052 .5265471
cut4 | 1.333053 .1391907 1.060244 1.605861
-------------+----------------------------------------------------------------
/att2 |
cut1 | -1.055791 .1062977 -1.264131 -.8474513
cut2 | -.1941211 .0941435 -.378639 -.0096032
cut3 | .3598488 .0952038 .1732528 .5464448
cut4 | 1.132624 .1082204 .9205156 1.344732
-------------+----------------------------------------------------------------
/att3 |
cut1 | -1.053519 .1733999 -1.393377 -.7136614
cut2 | -.0491073 .1442846 -.3318999 .2336853
cut3 | .5570671 .1538702 .2554871 .8586471
cut4 | 1.666859 .2135554 1.248298 2.08542
-------------+----------------------------------------------------------------
/att4 |
cut1 | -1.07378 .1214071 -1.311734 -.8358264
cut2 | -.2112462 .1076501 -.4222366 -.0002559
cut3 | .406347 .1094847 .191761 .620933
cut4 | 1.398185 .1313327 1.140778 1.655593
-------------+----------------------------------------------------------------
/att5 |
cut1 | -1.244051 .1148443 -1.469142 -1.018961
cut2 | -.336135 .0986678 -.5295203 -.1427498
cut3 | .2137776 .0978943 .0219084 .4056468
cut4 | .9286849 .107172 .7186316 1.138738
-------------+----------------------------------------------------------------
var(MathAb)| 2.300652 .7479513 1.216527 4.350909
var(MathAtt)| 1.520854 .4077674 .8992196 2.572228
-------------+----------------------------------------------------------------
cov(MathAb,|
MathAtt)| .8837681 .2204606 4.01 0.000 .4516733 1.315863
------------------------------------------------------------------------------
. esttab . using "test", unstack ///
> drop(/: /att1: /att2: /att3: /att4: /att5:) ///
> compress html replace not
(output written to test.html)
And the (really wide) table: (scrollbar at the bottom)
(1)
q1
q1 q2 q3 q4 q5 q6 q7 q8 att1 att2 att3 att4 att5
MathAb 1 0.345** 0.545*** 0.286** 0.817*** 0.603*** 0.721*** 0.581***
MathAtt 1 0.379*** -1.593*** -0.810*** 0.523***
_cons 0.0446 -0.457*** 0.159 -0.320*** -0.0454 -0.310** 0.105 -0.0250
N 500
* p < 0.05, ** p < 0.01, *** p < 0.001