Hi Stata users,
I am struggling on using gsem to perform LCA and predict class on group level.
My data looks like this
Using gsem, I was able to run the model and predict posterior probabilities, and assign class for each row (for example, for model with 2 classes):
But what I need is prediction on groupID level so that I can get a class assigned to each groupID (the class within one groupID should not vary).
Any suggestions on how to approach this issue are welcome!
I am struggling on using gsem to perform LCA and predict class on group level.
My data looks like this
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int groupID float choice byte(v1 v2 v3 v4) 2 3 2 1 2 4 2 2 3 3 4 1 2 3 2 2 7 4 2 2 3 3 5 2 2 2 3 1 4 3 2 4 2 2 5 2 2 3 1 3 5 4 2 2 2 1 4 4 2 3 2 1 8 4 2 3 3 2 9 2 2 2 3 1 3 2 2 2 3 1 8 4 2 2 1 3 3 3 2 2 1 1 7 2 2 3 3 1 3 1 3 4 1 2 4 4 3 4 2 3 6 1 3 4 1 1 1 1 3 4 1 2 7 2 3 4 1 2 3 4 3 4 3 2 4 3 3 2 1 1 8 2 3 4 1 3 4 3 3 4 1 1 6 1 3 4 3 2 4 4 3 4 2 1 3 1 3 4 1 1 6 3 3 4 3 1 9 3 3 3 1 3 2 2 3 4 2 2 3 1 4 4 3 2 6 4 4 4 2 3 4 4 4 4 3 1 2 2 4 4 1 2 5 4 4 4 2 1 3 4 4 4 2 3 5 1 4 4 3 2 6 3 4 3 2 2 9 2 4 4 3 2 3 2 4 3 1 2 7 1 4 3 2 1 8 1 4 4 1 2 5 3 4 4 2 1 7 4 4 4 1 1 1 4 4 3 3 2 9 1 5 5 1 2 7 4 5 5 1 2 2 3 5 5 1 1 8 4 5 5 3 3 3 2 5 5 3 3 8 2 5 5 2 3 1 3 5 5 3 1 7 1 5 5 2 3 1 1 5 5 1 3 3 1 5 5 3 3 8 4 5 5 2 1 6 3 5 5 2 1 1 4 5 5 2 3 5 4 5 5 3 3 8 1 5 5 2 1 9 3 end
Using gsem, I was able to run the model and predict posterior probabilities, and assign class for each row (for example, for model with 2 classes):
Code:
gsem /// (choice <- i.v1 i.v2 i.v3 i.v4), /// ologit lclass(C 2) predict cpost*, classposteriorpr egen max = rowmax(cpost*) gen predclass = 1 if cpost1 == max replace predclass = 2 if cpost2 == max (cpost2)
Any suggestions on how to approach this issue are welcome!
Comment