Savedata with LCA PreviousNext
Mplus Discussion > Latent Variable Mixture Modeling >
 Katharina Schmid posted on Thursday, December 01, 2005 - 3:49 am
I am in the process of carrying out LCA and the model appears to be running ok. However, I am having difficulty saving the conditional probabilities- I get an error message in the output. Would appreciate any advice on this.
Input and warning as follows:


Title: LCA for experience (5classes)
Data: FILE IS modeldata.dat;
FORMAT IS 124F7.0 11F7.2 20F7.0 1F7.2;

Variable: NAMES ARE id a1-a28 b1-b127;
CLASSES = c(5);

Analysis: TYPE = MIXTURE;
STARTS = 500 10;

Output: TECH8 TECH10 TECH11;

Savedata: File is exp5.sav;
Save = CPROB;

*** WARNING in Savedata command
(Err#: 9)
Error opening data save file:
Data will not be saved.
 Anonymous posted on Thursday, December 01, 2005 - 5:29 am
I donīt know if there is another mistake, but you didnīt specify a file path in the savedata command (like "C:\exp.5.sav";).
 Anonymous posted on Thursday, December 01, 2005 - 5:35 am
Sorry for the overhasty comment, according to the userīs guide, a file path doesnīt seems to be necessary in the savedata command.
 Marco Grados posted on Thursday, December 01, 2005 - 9:57 am
I have used this with success in MPLUS 3.0

 Linda K. Muthen posted on Thursday, December 01, 2005 - 12:58 pm
You would get this message if the file is open or if the directory cannot be written to.
 Hee-Jin Jun posted on Tuesday, February 06, 2007 - 8:03 pm
I used savedata command and got the data.
but when I opened the data,
there were '*' for missing (originally it was -999) and '**********' for id (originally id was 6 digit)
How can I get the real numbers instead of ***.

My command was
FILE IS BMI10C1_2.sav;
format is delimited;

I used 'format is free' as well. It gave me the same result.

Thanks a lot for your help.
 Linda K. Muthen posted on Wednesday, February 07, 2007 - 7:51 am
It seems that your id variable is too long. The asterisks indicate that it will not fit in the space provided. The default for missing is the asterisk. If you cannot figure this out, please send your input, data, output, and license number to
 Hee-Jin Jun posted on Friday, February 09, 2007 - 4:46 pm
Thanks Linda,

If my id number does not fit in the space provided, how many digits Mplus allows and is there any way that I can increase the digit?

Thank you for your help.
 Linda K. Muthen posted on Friday, February 09, 2007 - 5:18 pm
You will need to shorten your id variable to no more than 7 digits.
 Phil Wood posted on Friday, June 15, 2007 - 11:53 am
Here's a somewhat related question:
I have an ID variable which contains alpha information (e.g., 198292A).
Is there any way to save this alpha information in the savedata statement?
I tried using
IDVARIABLE to read the information in, (i.e., idvariable is dadid;)
but when I save the data, the output doesn't contain the alpha variable.
Thanks for any insights!
(Alternatively, I guess a workaround is to case-merge the files afterward, but I'm, as always, lazy).
 Linda K. Muthen posted on Friday, June 15, 2007 - 3:12 pm
For Mplus, all data must be numeric. There is no way around this. You could do a global change of A to 9 for example.

I'm surprised you don't get an error message. I added an A to a variable in a data set and I did.
 MAH posted on Wednesday, August 06, 2008 - 10:04 am
My ID variable is 7 digits long, ranging from 0001502 to 2601602. Right now, when I save the data, 0001502 becomes 1502. I need to retain the leading zeros on the smaller numbers when I use the savedata command. How can I do this?
 Linda K. Muthen posted on Wednesday, August 06, 2008 - 10:22 am
Are you identifying the ID variable using the IDVARIABLE option of the VARIABLE command? Also, you can use a FORMAT statement in SAVEDATA. See the user's guide.
 Linda K. Muthen posted on Wednesday, August 06, 2008 - 10:57 am
I was just informed that leading zeroes are not saved. I don't know of how you would do that or why it would matter. Can you explain?
 Kätlin Peets posted on Tuesday, July 28, 2009 - 7:16 am

I have a question. I am conducting a LCA (mixture missing). When I save my data (class membership and other data), can I somehow override the default option for missing values (i.e., asterisks) and use a numerical value instead? I have a problem opening the dat. file in spss with asterisks.
 Linda K. Muthen posted on Tuesday, July 28, 2009 - 8:37 am
There is not an option in the SAVEDATA command to change the missing data flag. If you want to do this, I suggest opening the file in the Mplus or some other editor and doing a global replace of the asterisk with another missing value flag.
 Gareth posted on Wednesday, September 23, 2009 - 7:28 am
Could an option to change the default asterisk (e.g. to 9999) be included in a future update? It is difficult to get SPSS and Excel to recognize the asterisk.
 Linda K. Muthen posted on Wednesday, September 23, 2009 - 7:40 am
You can do a global change of asterisk to either a number of symbol that is recognized by SPSS and Excel, for example, 9999.
 luke fryer posted on Monday, November 22, 2010 - 6:22 am
Dr. Linda Muthen,

Mplus (6.1) can now save variables 16 in length... But we are still restricted to numbers only right? There is no possible way around this...?

Just checking,

 Linda K. Muthen posted on Monday, November 22, 2010 - 8:02 am
Yes, ASCII files must be numeric if this is what you mean.
 sunyforever posted on Friday, November 01, 2013 - 8:15 am
Dear Linda or Bengt,

I have difficulty saving the latent class membership after fitting a LCA model.

In the model I controlled the effects of complex survey. My commands were:

weight = wt;
CLUSTER = psu;

FILE IS newdata.dat ;

However, when I checked the exported data file, I found two problems: 1) the id variable is composed of 7-digit numbers, and should look like 1311110, 6522222, and so forth. But in many cases these values were truncated and looked like 131, 652, ..

2) When I read the data file in Stata, I found all the variables were not aligned with the respective columns. For instance, case#1 of the id variable lies rightly in the first column, but case#2 of id falls in the second column, and #3 in the third column..

I tried to save the model without controlling complex survey effects. It turned out a success. But I do wish to save the data with the survey effects. Could you help to figure out where the problem is?

 Linda K. Muthen posted on Friday, November 01, 2013 - 8:43 am
Please send the files and your license number to
 Belinda Needham posted on Thursday, July 03, 2014 - 12:28 pm
I am using the Add Health data for a LCA, and the ID number appears to be too long (8 digits). I need to keep the ID number in the data set so I can merge the C variable with the original data set for analysis. If I divide the ID number by 100, Mplus can use it, but the numbers are no longer unique, and the merge doesn't work properly. Do you know a workaround for this?
 Thuy Nguyen posted on Thursday, July 03, 2014 - 4:39 pm
You can declare the variable as AUXILIARY instead of IDVARIABLE. It will be saved with the rest of the data.

The default format for saving the data is F10.3 for free format. You can specify FORMAT = F15.3 so the format width is big enough for the values.
 Maggie Thorsen posted on Tuesday, September 22, 2015 - 2:09 pm
When I transfer my data from Stata to MPlus using the "stata2plus" command my id variable, which was originally 8 digits long, somehow is getting converted to a different number. E.g. the first record is now getting a '1" for the id variable instead of the eight digit code it had before. This is especially problematic when trying to merge the class variable and c-probabilities back in with the original dataset. Why would the value of the id variable change? Is there any way to fix this or syntax to use to ensure the original values are retained? Thank you!
 Linda K. Muthen posted on Tuesday, September 22, 2015 - 4:55 pm
I do not know why this would happen. It must be because of stata2mplus. You should contact the author of stata2mplus.
 John Bulluck posted on Wednesday, June 15, 2016 - 9:23 am
I am having a similar problem, though my error number is 29 but I cant find any documentation that tells me what the #29 means

this is my code:

TITLE: this is an example of a LCA with
continuous latent class indicators using
automatic starting values with random
DATA: FILE IS qs_lpa.csv;
VARIABLE: NAMES ARE id seek lr avd sens;
id seek lr avd sens;
MISSING = all(-99);
CLASSES = c (4);
OUTPUT: tech1 tech8 tech11 tech14 CINTERVAL;
SAVEDATA: File is "C:/R/o.csv";

This is my output
*** WARNING in SAVEDATA command
(Err#: 29)
Error opening data save file:
Data will not be saved.

I have rights to the folder location and the path is correct. Interestingly, when I change the direction of the slash from / to \ I get error #9 but still doesnt save the data and error message otherwise is the same
 Linda K. Muthen posted on Wednesday, June 15, 2016 - 11:23 am
Please send the input, data, output, and your license number to
 Tess Yanisch posted on Friday, June 09, 2017 - 5:11 am
I am having a similar problem to several of the previous posters. I'm running an LCA with students nested in schools. I'm clustering by school and using a weighting variable. I also need the student ID variable to show up when I export classes and CPROBs. I have the IDSTUD (student ID) variable as an auxiliary.

I have a beautiful export of IDs for about 3/5 of the sample and ******** or missing for the rest. Is length still an issue here? It's the ones that are 6 digits long or more that aren't showing up.

Relevant part of syntax is below:


[things I'm doing LCA on];

Categorical are [things I'm doing LCA on];

Auxiliary = IDSTUD;

Classes = patrn (4);

Missing are all (-9999);

Type= mixture complex;
Starts = 200 100;

File is 20170608FourClassProbs.sav;
save = cprobabilities;

Thank you in advance--this has been driving me crazy.
 Linda K. Muthen posted on Friday, June 09, 2017 - 2:02 pm
This means the ID variable is too large to fit in the space provided. Use the IDVARIABLE option to indicate that it is an ID variable.
 Adrian Rothers posted on Saturday, December 01, 2018 - 7:46 am

I am using save=crprobabilities to save the results of a 3-class lca with 9 ordered categorical indicators.
My dataset contains 523 cases.
However, the lca-output only mentions 507 observations (with number of missing data patterns=3 / number of y missing data patterns=3). Accordingly, the resulting crprobabilities-.txt-file has only 507 cases.
For my next analysis steps, I would like to add the most likely class memberships to the original dataset, which makes little sense with the two files containing different numbers of cases.

Could you tell me why the .txt-file has less cases than the original dataset and how to fix this situation?

Thank you very much in advance!
 Bengt O. Muthen posted on Saturday, December 01, 2018 - 10:30 am
Check the beginning of your output where the number of cases used in the analysis is reported and deleted cases are mentioned.

If this doesn't help, send your output to Support along with your license number.
 Debbie Hahs-Vaughn posted on Thursday, January 09, 2020 - 3:40 pm
I would like to save the probabilities from my LCA model, which uses imputed data. I receive the following error so it seems that the probabilities can't be saved. Since I'm using imputed data, is there any workaround to save the probabilities? Thanks.

*** WARNING in SAVEDATA command
The FILE option is not available for TYPE=MONTECARLO or TYPE=IMPUTATION.
The FILE option will be ignored.

*** WARNING in SAVEDATA command
The SAVE option is not available for TYPE=MONTECARLO or TYPE=IMPUTATION.
The SAVE option will be ignored.
 Bengt O. Muthen posted on Friday, January 10, 2020 - 11:45 am
Perhaps you are referring to saving CPROBS. If so, it will have to be done for each data set and then averaged if you really want the posterior probabilities for each individua.l
Back to top
Add Your Message Here
Username: Posting Information:
This is a private posting area. Only registered users and moderators may post messages here.
Options: Enable HTML code in message
Automatically activate URLs in message