Adding a new variable in an existing dataset of MLwin

Welcome to the forum for MLwiN users. Feel free to post your question about MLwiN software here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Remember to check out our extensive software FAQs which may answer your question: http://www.bristol.ac.uk/cmm/software/s ... port-faqs/
Post Reply
jeanninekhan
Posts: 6
Joined: Wed Dec 02, 2009 10:28 am

Adding a new variable in an existing dataset of MLwin

Post 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
ChrisCharlton
Posts: 1265
Joined: Mon Oct 19, 2009 10:34 am

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

Post 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.
jeanninekhan
Posts: 6
Joined: Wed Dec 02, 2009 10:28 am

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

Post 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
ChrisCharlton
Posts: 1265
Joined: Mon Oct 19, 2009 10:34 am

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

Post 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
jeanninekhan
Posts: 6
Joined: Wed Dec 02, 2009 10:28 am

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

Post 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
ChrisCharlton
Posts: 1265
Joined: Mon Oct 19, 2009 10:34 am

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

Post 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.
Post Reply