Stata SEM
sem fits a SEM. -gsem- is also described here.
Example
Adapted from https://www.stata.com/features/overview/structural-equation-modeling/explanation/:
. webuse sem_1fmm
(Single-factor measurement model)
. rename x4 y
. sem (x1<-X) (x2<-X) (x3<-X) (y<-X)
Endogenous variables
Measurement: x1 x2 x3 y
Exogenous variables
Latent: X
Fitting target model:
Iteration 0: log likelihood = -8487.5905
Iteration 1: log likelihood = -8487.2358
Iteration 2: log likelihood = -8487.2337
Iteration 3: log likelihood = -8487.2337
Structural equation model Number of obs = 500
Estimation method: ml
Log likelihood = -8487.2337
( 1) [x1]X = 1
------------------------------------------------------------------------------
| OIM
| Coefficient std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
Measurement |
x1 |
X | 1 (constrained)
_cons | 99.518 .6412888 155.18 0.000 98.2611 100.7749
-----------+----------------------------------------------------------------
x2 |
X | 1.033249 .0723898 14.27 0.000 .8913676 1.17513
_cons | 99.954 .6341354 157.62 0.000 98.71112 101.1969
-----------+----------------------------------------------------------------
x3 |
X | 1.063876 .0729725 14.58 0.000 .9208526 1.2069
_cons | 99.052 .6372649 155.43 0.000 97.80298 100.301
-----------+----------------------------------------------------------------
y |
X | 7.276754 .4277638 17.01 0.000 6.438353 8.115156
_cons | 94.474 3.132547 30.16 0.000 88.33432 100.6137
-------------+----------------------------------------------------------------
var(e.x1)| 115.6865 7.790423 101.3823 132.0089
var(e.x2)| 105.0445 7.38755 91.51873 120.5692
var(e.x3)| 101.2572 7.17635 88.12499 116.3463
var(e.y)| 144.0406 145.2887 19.94838 1040.069
var(X)| 89.93921 11.07933 70.64676 114.5001
------------------------------------------------------------------------------
LR test of model vs. saturated: chi2(2) = 1.46 Prob > chi2 = 0.4827
Usage
In some ways, -sem- and -gsem- are interchangeable. The following are common to both:
The following are important differences between the two.
Comparison to Other Implementations
Note that lavaan estimates latent variances whereas -gsem- fits data to a model using maximum likelihood. While regression coefficients can be comparable, the methods are fundamentally not.
