use "https://github.com/agrogan1/multilevel-thinking/raw/main/simulate-and-analyze-multilevel-data/simulated_multilevel_data.dta", clear
Tables for sem
in Stata
1 Introduction
A quick demo of making tables with sem
in Stata.
2 Get Data
Data from Multilevel Thinking
3 Run sem
Model
Outcome is a function of physical punishment, parental warmth and the intervention. Physical punishment is potentially an outcome of the intervention.
///
sem (outcome <- physical_punishment warmth intervention) // sem model
(physical_punishment <- intervention)
est store M1 // store estimates from this model
Endogenous variables
Observed: outcome physical_punishment
Exogenous variables
Observed: warmth intervention
Fitting target model:
Iteration 0: Log likelihood = -23247.767
Iteration 1: Log likelihood = -23247.767
Structural equation model Number of obs = 3,000
Estimation method: ml
Log likelihood = -23247.767
------------------------------------------------------------------------------------------
| OIM
| Coefficient std. err. z P>|z| [95% conf. interval]
-------------------------+----------------------------------------------------------------
Structural |
outcome |
physical_punishment | -.9422686 .0831977 -11.33 0.000 -1.105333 -.7792041
warmth | .8360494 .0599923 13.94 0.000 .7184666 .9536322
intervention | .6706488 .2266906 2.96 0.003 .2263434 1.114954
_cons | 51.49974 .3380981 152.32 0.000 50.83708 52.1624
-----------------------+----------------------------------------------------------------
physical_punishment |
intervention | -.0513873 .0497018 -1.03 0.301 -.1488011 .0460265
_cons | 2.503555 .0345895 72.38 0.000 2.435761 2.571349
-------------------------+----------------------------------------------------------------
var(e.outcome)| 38.43413 .992365 36.53753 40.42919
var(e.physical_punishm~t)| 1.850885 .0477897 1.75955 1.946962
------------------------------------------------------------------------------------------
LR test of model vs. saturated: chi2(1) = 0.04 Prob > chi2 = 0.8347
4 Make Table With etable
As long as the variables have variable labels, etable
(with a few options) will automatically make a nice regression table.
///
etable, estimates(M1) /// using these estimates
/// show significance stars & note
showstars showstarsnote // show equations showeq
1
---------------------------------------------
beneficial outcome
physical punishment in past week -0.942 **
(0.083)
parental warmth in past week 0.836 **
(0.060)
recieved intervention 0.671 **
(0.227)
Intercept 51.500 **
(0.338)
physical punishment in past week
recieved intervention -0.051
(0.050)
Intercept 2.504 **
(0.035)
/
var(e.outcome) 38.434
(0.992)
var(e.physical_punishment) 1.851
(0.048)
Number of observations 3000
---------------------------------------------
** p<.01, * p<.05