This is a mediation model with a categorical exogenous variable. I am trying to compare the results by running SEM and regression. The third step regression was conducted and I found the estimates were the same, but the standard errors were different. Any idea? Thanks for your help.
library(rms) library(lavaan) y <- seq(1:10) m <- c(1,4,5,3,6,3,5,7,4,9) race <- c(1,3,2,1,2,3,3,2,2,2) data <- data.frame(cbind(y, m, race)) A <- as.data.frame(model.matrix( y~ m*factor(race), data = data)) data$rd2 <- A[,3] data$rd3 <- A[,4] data$inter2 <- A[,5] data$inter3 <- A[,6] ols(y~m+rd2+rd3+inter2+inter3, data=data) model <- 'm~rd2+rd3 y~m+rd2+rd3+inter2+inter3 m~~0*y' fit<-sem(model, data=data) summary(fit)