I am trying to conduct sem to examine measurement invariance with multiple groups (bipoc gender). Bipoc consists of 0 vs. 1. Gender consists of 0, 1, 2. The model I am trying to examine is a two-factor structure (latent variables are A and B).
I did not have any issue running the sem models with each group separately. The models successfully converged. However, ultimately, I want to include both groups in one model, but when I do so, I get an error message that says, "group(): too many variables specified, r(103)." I am pretty sure that I should be able to include both groups at the same time, and I think when I tried to do the same a couple months ago, it did run and converge without any issue. But now that I am trying to replicate, it doesn't seem to work. I don't think I have updated my Stata, or changed the data in any way.
Could you help me how to employ sem to examine measurement invariance with multiple groups at the same time. I am using Stata 15.1 on Mac. It would be helpful to get the exact code I could use. Also, if there is anything I am doing wrong, please let me know, and give me suggestions on the actual code to use.
These are the codes I ran to examine the measurement invariance with respect to each group (bipoc and gender separately).
1) bipoc: all these models converged successfully
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(bipoc) mean(A) mean(B) ginvariant(none) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(bipoc) mean(A) mean(B) ginvariant(mceof) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(bipoc) mean(A) mean(B) ginvariant(mcoef mcons) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
2) gender: all these models converged successfully
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(gender) mean(A) mean(B) ginvariant(none) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(gender) mean(A) mean(B) ginvariant(mceof) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(gender) mean(A) mean(B) ginvariant(mcoef mcons) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
These are the codes I am trying to run to exa ine the measurement invariance with respect to both groups at the same time (bipoc and gender together).
3) including both bipoc and gender: I get an error message that says group(): too many variables specified, r(103). The same error message for all three following models.
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(bipoc gender) mean(A) mean(B) ginvariant(none) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(bipoc gender) mean(A) mean(B) ginvariant(mceof) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(bipoc gender) mean(A) mean(B) ginvariant(mcoef mcons) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
The example data is as follows (I have uploaded the full dataset just in case). Data.xlsx
input byte(B1 B2 B3 B4 B5 A1 B6 B7 A2 A3 A4 A5 A6 bipoc gender)
5 5 5 5 5 5 5 5 5 5 5 5 5 0 2
5 5 3 5 4 3 3 4 2 2 2 3 2 1 2
5 5 4 5 5 5 5 5 5 5 5 5 5 1 2
5 5 5 5 3 4 5 5 5 5 5 5 5 0 2
5 5 5 5 5 5 4 4 5 5 5 5 5 0 0
4 3 3 4 3 4 3 4 5 4 5 4 4 0 0
4 2 3 2 1 4 3 5 4 3 4 4 2 1 0
5 4 2 4 4 4 5 5 4 5 5 5 4 0 0
4 4 5 5 5 4 4 5 4 4 4 3 4 . 2
5 5 5 5 5 3 4 4 4 4 4 5 5 1 0
5 5 5 5 5 5 5 5 5 5 5 5 5 0 2
5 5 5 5 5 4 5 5 5 5 5 5 5 0 2
5 5 3 5 3 4 4 1 4 4 3 4 5 0 2
5 2 4 5 5 3 4 4 5 3 4 5 4 0 0
5 5 4 3 5 3 5 4 5 5 5 5 4 0 1
4 3 2 4 4 4 3 4 4 2 4 3 4 0 2
5 4 5 5 5 5 5 5 5 5 4 4 5 1 1
5 4 5 5 5 3 4 5 5 4 5 5 5 0 0
5 4 4 4 2 3 4 4 4 4 4 5 3 1 2
4 5 5 3 5 5 5 5 5 5 5 5 5 0 0
I think the number per group is sufficient to run this.
tab bipoc
bipoc | Freq. Percent Cum.
------------+-----------------------------------
0 | 556 70.38 70.38
1 | 234 29.62 100.00
------------+-----------------------------------
Total | 790 100.00
. tab gender
gender | Freq. Percent Cum.
------------+-----------------------------------
0 | 240 29.93 29.93
1 | 316 39.40 69.33
2 | 246 30.67 100.00
------------+-----------------------------------
Total | 802 100.00
Thank you so much for your help!!
I did not have any issue running the sem models with each group separately. The models successfully converged. However, ultimately, I want to include both groups in one model, but when I do so, I get an error message that says, "group(): too many variables specified, r(103)." I am pretty sure that I should be able to include both groups at the same time, and I think when I tried to do the same a couple months ago, it did run and converge without any issue. But now that I am trying to replicate, it doesn't seem to work. I don't think I have updated my Stata, or changed the data in any way.
Could you help me how to employ sem to examine measurement invariance with multiple groups at the same time. I am using Stata 15.1 on Mac. It would be helpful to get the exact code I could use. Also, if there is anything I am doing wrong, please let me know, and give me suggestions on the actual code to use.
These are the codes I ran to examine the measurement invariance with respect to each group (bipoc and gender separately).
1) bipoc: all these models converged successfully
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(bipoc) mean(A) mean(B) ginvariant(none) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(bipoc) mean(A) mean(B) ginvariant(mceof) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(bipoc) mean(A) mean(B) ginvariant(mcoef mcons) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
2) gender: all these models converged successfully
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(gender) mean(A) mean(B) ginvariant(none) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(gender) mean(A) mean(B) ginvariant(mceof) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(gender) mean(A) mean(B) ginvariant(mcoef mcons) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
These are the codes I am trying to run to exa ine the measurement invariance with respect to both groups at the same time (bipoc and gender together).
3) including both bipoc and gender: I get an error message that says group(): too many variables specified, r(103). The same error message for all three following models.
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(bipoc gender) mean(A) mean(B) ginvariant(none) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(bipoc gender) mean(A) mean(B) ginvariant(mceof) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
sem (A -> A1 A2 A3 A4 A5 A6, ) (B -> B1 B2 B3 B4 B5 B6 B7, ) (A -> A1@0) (B -> B1@0) (A1 <- A _cons@1) (B1 <- B _cons@0), covstruct(_lexogenous, diagonal) group(bipoc gender) mean(A) mean(B) ginvariant(mcoef mcons) latent(A B) cov( A*B) nocapslatent standardized iterate(100)
The example data is as follows (I have uploaded the full dataset just in case). Data.xlsx
input byte(B1 B2 B3 B4 B5 A1 B6 B7 A2 A3 A4 A5 A6 bipoc gender)
5 5 5 5 5 5 5 5 5 5 5 5 5 0 2
5 5 3 5 4 3 3 4 2 2 2 3 2 1 2
5 5 4 5 5 5 5 5 5 5 5 5 5 1 2
5 5 5 5 3 4 5 5 5 5 5 5 5 0 2
5 5 5 5 5 5 4 4 5 5 5 5 5 0 0
4 3 3 4 3 4 3 4 5 4 5 4 4 0 0
4 2 3 2 1 4 3 5 4 3 4 4 2 1 0
5 4 2 4 4 4 5 5 4 5 5 5 4 0 0
4 4 5 5 5 4 4 5 4 4 4 3 4 . 2
5 5 5 5 5 3 4 4 4 4 4 5 5 1 0
5 5 5 5 5 5 5 5 5 5 5 5 5 0 2
5 5 5 5 5 4 5 5 5 5 5 5 5 0 2
5 5 3 5 3 4 4 1 4 4 3 4 5 0 2
5 2 4 5 5 3 4 4 5 3 4 5 4 0 0
5 5 4 3 5 3 5 4 5 5 5 5 4 0 1
4 3 2 4 4 4 3 4 4 2 4 3 4 0 2
5 4 5 5 5 5 5 5 5 5 4 4 5 1 1
5 4 5 5 5 3 4 5 5 4 5 5 5 0 0
5 4 4 4 2 3 4 4 4 4 4 5 3 1 2
4 5 5 3 5 5 5 5 5 5 5 5 5 0 0
I think the number per group is sufficient to run this.
tab bipoc
bipoc | Freq. Percent Cum.
------------+-----------------------------------
0 | 556 70.38 70.38
1 | 234 29.62 100.00
------------+-----------------------------------
Total | 790 100.00
. tab gender
gender | Freq. Percent Cum.
------------+-----------------------------------
0 | 240 29.93 29.93
1 | 316 39.40 69.33
2 | 246 30.67 100.00
------------+-----------------------------------
Total | 802 100.00
Thank you so much for your help!!
Comment