|
Size: 3238
Comment: WIP still
|
← Revision 3 as of 2025-10-24 18:00:01 ⇥
Size: 3551
Comment: Rewrite
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| = Stata sem = | = Stata SEM = |
| Line 3: | Line 3: |
| The '''`sem`''' command fits a [[Statistics/StructuralEquationModeling|SEM]]. | '''`sem`''' fits a [[Statistics/StructuralEquationModeling|SEM]]. '''`-gsem-`''' is also described here. |
| Line 11: | Line 11: |
| == Usage == | == Example == |
| Line 71: | Line 71: |
| A more complex example: | ---- |
| Line 73: | Line 73: |
| {{{ . sem (X -> x1 x2 x3) (Z -> z1 z2 z3) (Y -> y1 y2 y3) (Y <- X Z), noanchor variance(X@1 Z@1 e.Y@1) noconstant }}} |
|
| Line 77: | Line 74: |
| Note that assumptions about variances must be specified on the '''`variance`''' option. In this case, the variances of latent variables (i.e., `var(X)` and `var(Z)`) and the variance of the outcome variable's errors (i.e. `var(e.Y)`) are all assumed to be uniform. | == Usage == In some ways, '''`-sem-`''' and '''`-gsem-`''' are interchangeable. The following are common to both: * [[Stata/Sem/PathSpecification|Path specification]] The following are important differences between the two. * [[Stata/Sem/CovarianceStructure|Covariance structure]] * [[Stata/Sem/Groups|Groups]] * [[Stata/Sem/Multilevel|Multilevel]] ---- == Comparison to Other Implementations == Note that [[R/Lavaan|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. |
| Line 85: | Line 101: |
| [[Stata/Gsem|gsem]] | [[https://www.stata.com/manuals/sem.pdf#semsem|Stata manual for -sem-]] |
| Line 87: | Line 103: |
| [[https://www.stata.com/manuals/sem.pdf#semsem|Stata manual for sem]] | [[https://www.stata.com/manuals/sem.pdf#semgsem|Stata manual for -gsem-]] |
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.
