I am excited to share a new Stata package, dwlsmv, which implements weighted least squares mean- and variance-adjusted (WLSMV) estimation for binary and ordinal indicators. It fits single- and multiple-group confirmatory factor and structural equation models, and exploratory factor models with oblique geomin rotation.
The test statistic is the scaled-and-shifted (T3) mean- and variance-adjusted chi-square, the correction Mplus has used for WLSMV since version 6 (Asparouhov and Muthén, 2010). The "d" stands for the diagonal weight matrix used in estimation; the full asymptotic covariance matrix is still used for the robust standard errors and the test statistic (Muthén, du Toit, and Spisic, 1997).
The current release is v0.3.0. Stata 16 is the floor, and it has been tested on Stata 16.1, 18 and 19 on Windows (macOS and Linux are not yet tested). This is a Mata implementation and should work across platforms.
Installation:
Source, specification and derivations are available at https://github.com/bbachilles/dwlsmv. The code is licensed under GPL-3.0-or-later; the specification, derivations and documentation under CC BY 4.0.
This was built in close collaboration with and using Claude Code (code generated by Opus) with ChatGPT utilized as an independent sounding board in highly technical decision making (see follow-up post).
What v0.3.0 supports
dwlsmv is actively being developed and contributors are welcome! Planned development aims to address these:
References
Asparouhov, T., and B. Muthén. 2006. Robust chi square difference testing with mean and variance adjusted test statistics. Mplus Web Notes No. 10.
Asparouhov, T., and B. Muthén. 2010. Simple second order chi-square correction. Technical appendix, Mplus.
Muthén, B., S. H. C. du Toit, and D. Spisic. 1997. Robust inference using weighted least squares and quadratic estimating equations in latent variable modeling with categorical and continuous outcomes. Unpublished manuscript.
Wu, H., and R. Estabrook. 2016. Identification of confirmatory factor analysis models of different levels of invariance for ordered categorical outcomes. Psychometrika 81: 1014–1045.
The test statistic is the scaled-and-shifted (T3) mean- and variance-adjusted chi-square, the correction Mplus has used for WLSMV since version 6 (Asparouhov and Muthén, 2010). The "d" stands for the diagonal weight matrix used in estimation; the full asymptotic covariance matrix is still used for the robust standard errors and the test statistic (Muthén, du Toit, and Spisic, 1997).
The current release is v0.3.0. Stata 16 is the floor, and it has been tested on Stata 16.1, 18 and 19 on Windows (macOS and Linux are not yet tested). This is a Mata implementation and should work across platforms.
Installation:
Code:
net install dwlsmv, from("https://raw.githubusercontent.com/bbachilles/dwlsmv/v0.3.0/dist/")
net get dwlsmv // example data
help dwlsmv
This was built in close collaboration with and using Claude Code (code generated by Opus) with ChatGPT utilized as an independent sounding board in highly technical decision making (see follow-up post).
What v0.3.0 supports
- Single- and multiple-group factor models with binary and ordinal indicators, including regression paths between latent variables. Missing data are handled by listwise deletion.
- Cross-sectional measurement invariance (configural, thresholds, metric, scalar) following the Wu and Estabrook (2016) parameterization, using group() with metric(unitvariance). One deliberate restriction: invariance testing is not yet supported for factors measured only by binary indicators. Beyond metric invariance their identification is unresolved, so dwlsmv refuses these models rather than fitting them.
- Nested model comparison with the included difftest command: a mean- and variance-adjusted chi-square difference test (Asparouhov and Muthén, 2006) for single-group models and for nested invariance levels across groups. difftest checks that the models are nested and refuses the comparison when they are not, including models nested only through a reparameterization.
- EFA with oblique geomin rotated loadings and factor correlations (point estimates only).
- Fit indices: CFI, TLI and RMSEA, with changes in CFI and RMSEA between invariance levels.v0.3.0 necessarily has some limitations in its capability.
Code:
use dwlsmv_example, clear dwlsmv (F1 -> y1 y2 y3) (F2 -> y4 y5 y6) (F2 <- F1) // first loading of each factor fixed to 1 dwlsmv (F1 -> y1 y2 y3) (F2 -> y4 y5 y6) (F2 <- F1), metric(unitvariance) // factor variances fixed to 1 dwlsmv (F1 F2 -> y1-y6), efa(F1 F2) // EFA, oblique geomin
- Geomin rotated standard errors in EFA
- Observed covariates that are not part of measurement models. These require implementation of polyserial correlations, which was out of scope for v0.3.0.
- Unlimited parameter constraints. Currently only loading constraints for identifying the marker of a factor and those related to measurement invariance are supported,
- Second order or hierarchical factor structures, including latent "curve of factors" models.
- vce options, focused on vce(cluster clusterid)
- Exploratory structural equation modeling (ESEM)
References
Asparouhov, T., and B. Muthén. 2006. Robust chi square difference testing with mean and variance adjusted test statistics. Mplus Web Notes No. 10.
Asparouhov, T., and B. Muthén. 2010. Simple second order chi-square correction. Technical appendix, Mplus.
Muthén, B., S. H. C. du Toit, and D. Spisic. 1997. Robust inference using weighted least squares and quadratic estimating equations in latent variable modeling with categorical and continuous outcomes. Unpublished manuscript.
Wu, H., and R. Estabrook. 2016. Identification of confirmatory factor analysis models of different levels of invariance for ordered categorical outcomes. Psychometrika 81: 1014–1045.

Comment