Page 1 of 1

Adding a new variable in an existing dataset of MLwin

Posted: Tue Dec 08, 2009 8:28 am
by jeanninekhan
I have a MLwin dataset in which I already fixed a model under "Equations" and where I made calculations. Now I want to add a new variable to the model, which isn't included in my dataset. As I know, it is not possible to import a new variable into an existing dataset. So I created a new dataset in SPSS and opened it with MLwin. I hade to fix my model again under "equations" starting by cero.

Does anyone have a solution for this problem? How can I add new variables to an existing dataset?

Best regards, Jeannine

Re: Adding a new variable in an existing dataset of MLwin

Posted: Tue Dec 08, 2009 3:50 pm
by ChrisCharlton
If you have the data in a text file then you can use the ASCII text input commands to add these variables to an existing worksheet. The easiest way of doing this is via the File->ASCII text file input menu.

Alternatively you can use the "paste" button in the "names" window add variables from other applications or from other running copies of MLwiN. You can find further information about this, and the underlying commands, in the User Manual Supplement.

Unfortunately these methods only transfer the numeric data, so you will need to re-enter any categorical information or column descriptions.

Another option that you may want to consider is to set up your model in a macro file. This provides an quick way to apply the same model to several data sets.

Re: Adding a new variable in an existing dataset of MLwin

Posted: Wed Dec 09, 2009 9:58 am
by jeanninekhan
Dear Chris

Thank you for your reply.

The variable that I want to include comes from an SPSS dataset. If I add new variables in an existing SPSS file, I can choose a "key variable" like for example "identification number of a student" and the data will be ordered according to the identification number. But this I cannot do in MLwin. I know that I can add a variable with the "paste" button in the names window. But there is a problem: if I dont' have exactely the same number of variables and the same order of variables, the allocation of the data to each identification number of a student gets wrong, so this procedure is problematic.
Is there a solution for this?

Do you have further informations about the macro file?


Kind regards, Jeannine

Re: Adding a new variable in an existing dataset of MLwin

Posted: Wed Dec 09, 2009 11:33 am
by ChrisCharlton
I think that you should be able to use MLwiN sort functionality (Data Manipulation->Sort, or the SORT command) to reorder your data so it is ordered by identification number. Once you have both sets of data in the same order then you should be able to copy variables from one to another. Of course you will then have to resort your data to match your model hierarchy before fitting the model.

Probably the easiest way of writing a macro is to untick "user" in the "command interface" window and then copy and paste the commands generated by MLwiN from the GUI. If you intend to run as well as set up the model from the macro you need to remember to include the commands "BATCh 1" and "MAXIterations 20" (change 20 to a sensible number for your model) near the beginning of your macro file. For further information see the following FAQ questions:

http://www.cmm.bristol.ac.uk/MLwiN/tech ... l#commands

Re: Adding a new variable in an existing dataset of MLwin

Posted: Thu Dec 10, 2009 12:57 pm
by jeanninekhan
Hallo Chris

Thank you for your help!

I tried to order the variables under "Data Manipulation"- "Sort" by identification number. If I press "Execute", the following error message appears: "command line longer than 10000 characters- command ignored".

Thank you also for the informations concerning the macro.

Jeannine

Re: Adding a new variable in an existing dataset of MLwin

Posted: Thu Dec 10, 2009 1:54 pm
by ChrisCharlton
The command being generated by the "sort" window is being more verbose than is necessary in your case as it is writing out each column name involved in the sort separately. Because you are sorting most of your data you can specify a range of columns instead, preventing you from exceeding the maximum command length

For example, assuming your identifier variable is in a column called "id" and the data to be sorted is in columns 1 to 100 then entering the following command will sort the data on the identifier column:

SORT 1 'id' c1-c100 'id' c1-100

For a more detailed description of the syntax of the sort command see the MLwiN help system.