Top of page
Skip to main content

Categorical variables in SEM: code predictors, model outcomes and handle ordinal items

A column coded 1, 2 and 3 might represent industries, ordered satisfaction categories or event counts. Treating these codes identically changes the model even when the software accepts every column as numeric.

A variable’s role and measurement meaning determine coding, link functions, thresholds and interpretation. Choosing CB-SEM or PLS-SEM does not make those decisions for you.

Start reading

Data type and coding require explicit decisions

  1. Continuous

    Numeric distances are meaningful

  2. Ordinal

    Ordered categories; consider spacing

  3. Binary

    Two groups with explicit reference coding

  4. Nominal

    Unordered categories

Conceptual diagram. Declare measurement levels and coding before choosing an estimator.

Source: Lê Minh · Conceptual illustration, not software output.

1. Identify the role before choosing a command

A nominal predictor explains differences between categories, a binary outcome asks about event probability, and an ordinal item measures a construct through ordered responses. These are different tasks rather than one data-type conversion problem (Kline, 2023).

Table 1. Route categorical variables by role
RoleExampleMain decision
Nominal predictorRegions A, B and CReference category and dummy or contrast coding
Binary outcomePurchase: 0/1Probability model and link
Ordinal outcomeDissatisfied, neutral, satisfiedOrdinal model and link assumptions
Ordinal indicatorFive ordered responses to an itemThreshold specification and estimator
Grouping variableOrganizations or occasionsMeasurement comparability before parameter comparisons

Industry code 3 is not three times industry code 1. Entering the code as continuous imposes a linear trend along an arbitrary ordering. Relabeling industries can then alter results without changing group membership.

2. Code nominal predictors explicitly

With an intercept and K groups, K−1 dummy variables are a conventional option. The lavaan tutorial describes this treatment for exogenous covariates. Other contrasts can be appropriate if their coefficient meanings are explained (The lavaan project, n.d.).

Table 2. Hypothetical coding with A as reference
GroupD_BD_C
A00
B10
C01

Y = α + b_BD_B + b_CD_C + γX + ε.

Here α is the expected outcome in A when X is zero. The coefficient b_B compares B with A at the same X; it does not compare B with C. That comparison requires the contrast b_B − b_C and its uncertainty, or an appropriate alternative coding.

Including all three dummy variables and an intercept creates linear dependence in the usual specification. Dummy coding also does not make an observational group difference causal.

3. Binary and ordinal outcomes

Logit and probit models connect predictors to binary event probability. In logit, exp(b) is a conditional odds ratio. A probit coefficient is on a latent-response scale and cannot be exponentiated into the same odds-ratio interpretation (Kline, 2023).

For a hypothetical logit coefficient of 0.70, exp(0.70) is approximately 2.01. Conditional odds for group B are about twice those for A. This is not a 101% increase in probability. Probability statements also require the baseline and a meaningful covariate configuration.

Ordinal models use thresholds between response categories. Report category ordering and assess the assumptions of the chosen link. Coding an ordinal predictor as 1, 2 and 3 likewise imposes a numerical trend that needs justification.

Software capabilities matter: the lavaan tutorial covers binary and ordinal endogenous variables, not every multinomial outcome. A CFA command is not a universal generalized-SEM solution (The lavaan project, n.d.).

4. Ordered items and threshold models

An ordinal indicator can be represented through thresholds on an underlying response. The observed category code is distinct from distance on that response. Li’s comparison of MLR and WLSMV shows why performance depends on data conditions rather than a universal category-count rule (Li, 2016).

Inspect category frequencies, constant items, sparse bivariate cells, missingness and coding direction. Do not collapse categories merely to obtain convergence if the change destroys their substantive meaning.

In lavaan, ordered indicators trigger WLSMV, using DWLS estimation with the implementation’s adjusted inference. Do not append missing="fiml" to this ordinal example: the official tutorial states that FIML is not supported for this case (The lavaan project, n.d.).

5. An explicit CFA command template

The input survey.csv must contain s1 through s4, coded only 1–5 or declared missing. The example assumes one reflective SAT factor. It is a template for the reader’s data, not fitted output or validation of a measure.

R/lavaan: CFA with four ordinal indicators

library(lavaan)
dat <- read.csv("survey.csv", na.strings = c("", "NA"), check.names = FALSE)
items <- c("s1", "s2", "s3", "s4")
stopifnot(all(items %in% names(dat)))
valid <- vapply(dat[items], function(x) all(is.na(x) | x %in% 1:5), logical(1))
stopifnot(all(valid))
model <- 'SAT =~ s1 + s2 + s3 + s4'
fit <- cfa(model, data = dat, ordered = items, estimator = "WLSMV")
summary(fit, fit.measures = TRUE, standardized = TRUE)

The validation stops on out-of-range values instead of silently converting coding errors to missing. Preserve the original file and report the actual missing-data handling; these commands do not establish a missingness mechanism.

Inspect convergence, thresholds, loadings, standard errors and estimator-appropriate fit output. Counting parameters is not enough to rule out an inadmissible or weakly informed solution. Do not combine adjusted statistics with ordinary ML difference-test formulas without the required correction.

6. Categorical data do not select the SEM family

A nominal predictor may enter several SEM families. An algorithm accepting 0/1 data does not establish that it fits the intended probability model. Check the conceptual representation, equation type and actual estimator (Hair et al., 2022) (Kline, 2023).

For group comparisons, one significant p value and one nonsignificant value do not establish a difference. Examine measurement comparability and test the planned parameter contrast or restrictions. Splitting a continuous score into groups changes the question and requires justification.

7. Report coding, inference and limits

Reporting template

Variable [name] had [K] categories and served as [role]. The reference category/order was [ ]. The model used [coding or link/threshold], estimator [ ] and missing-data handling [ ]. Coefficients are interpreted on [scale], with confidence intervals [ ].
  • Codes and labels match the questionnaire.
  • Predictor, outcome, indicator and group roles are explicit.
  • Reference categories, ordering and links are reported.
  • Probit coefficients are not described as odds ratios.
  • The estimator and missing-data method are supported by the actual version.
  • Sparse cells, solution behavior and uncertainty have been examined.

Continue: choosing CB-SEM and PLS-SEM.

Conclusion

Establish each variable’s role and scale before selecting software. Correct coding supports correct interpretation; changing SEM families cannot replace that work.

References