Interpreting commands generated by MLwiN

When using MLwiN through the GUI (Graphical User Interface: i.e. the various windows), it is possible to make a record of the commands generated by MLwiN. This is achieved by opening the Command interface window (select 'Command interface' from the Data Manipulation menu) and then unticking the 'User' check box at the top of the window. This can be very useful when trying to learn to use MLwiN commands as it enables the user to see what commands are needed to perform a particular operation. It can also be useful to record what has been done during a session using the GUI. However, caution should be exercised because when MLwiN produces these commands, they include some that are not needed if the user wants to carry out the procedure via commands instead of by using the GUI. If the commands produced by MLwiN are copied blindly and simply pasted as they are into a macro or one by one into the Command interface window, these extra commands will often not cause problems (they will simply have no effect in some cases and in others they will just represent a longer way of carrying out some process for which there is a shorter simpler sequence of commands). But in some cases, these commands will actually cause an error message to be generated. Therefore it is important when using this method to find out about MLwiN commands that the user tries to understand (to a certain extent) what each command is doing, and removes the un-needed commands before using them in MLwiN. This can be done by looking up the commands in the Command Manual. This process of trying to interpret the generated commands will also provide the best means for the user to learn from them, so as to be able to write macros or use the Command interface window directly in the future, without first carrying out the process via the GUI.

Example

As an example of this process of understanding the commands and discarding the un-needed ones, open the tutorial dataset supplied with MLwiN, and from the Data Manipulation menu select 'Select or omit cases'. In the Select or omit cases window, under Condition to select or omit on type " 'school'==12". Under Input columns select all the variables in the dataset, and under Output columns select Free columns. Then select Add to action list and Execute. Now under Input columns click 'Omit cases', and again select 'Add to action list' and 'Execute'.

If you now go to the Command interface window and untick the 'user' box, you will see:

RETR "C:\Program Files\MLwiN v2.10\samples\tutorial.ws"
PREF 0
POST 0
WSET
CALCulate C1500= 'school' ==12
CHOOse  1 C1500  'school'  C1499  'c11' 
CHOOse  1 C1500  'student'  C1499  'c12' 
CHOOse  1 C1500  'normexam'  C1499  'c13' 
CHOOse  1 C1500  'cons'  C1499  'c14' 
CHOOse  1 C1500  'standlrt'  C1499  'c15' 
CHOOse  1 C1500  'girl'  C1499  'c16' 
CHOOse  1 C1500  'schgend'  C1499  'c17' 
CHOOse  1 C1500  'avslrt'  C1499  'c18' 
CHOOse  1 C1500  'schav'  C1499  'c19' 
CHOOse  1 C1500  'vrband'  C1499  'c20' 
ERASe C1500
NAME C1500 "c1500"
ERASe C1499
NAME C1499 "c1499"
WSET
JOIN  'c11'  C1500 C1500
JOIN  'c12'  C1500 C1500
JOIN  'c13'  C1500 C1500
JOIN  'c14'  C1500 C1500
JOIN  'c15'  C1500 C1500
JOIN  'c16'  C1500 C1500
JOIN  'c17'  C1500 C1500
JOIN  'c18'  C1500 C1500
JOIN  'c19'  C1500 C1500
JOIN  'c20'  C1500 C1500
CALCulate C1499= 'school' ==12
OMIT  1 C1499  'school'  C1498  'c11' 
OMIT  1 C1499  'student'  C1498  'c12' 
OMIT  1 C1499  'normexam'  C1498  'c13' 
OMIT  1 C1499  'cons'  C1498  'c14' 
OMIT  1 C1499  'standlrt'  C1498  'c15' 
OMIT  1 C1499  'girl'  C1498  'c16' 
OMIT  1 C1499  'schgend'  C1498  'c17' 
OMIT  1 C1499  'avslrt'  C1498  'c18' 
OMIT  1 C1499  'schav'  C1498  'c19' 
OMIT  1 C1499  'vrband'  C1498  'c20' 
ERASe C1499
NAME C1499 "c1499"
ERASe C1498
NAME C1498 "c1498"
WSET

What we have just done is to pick out the values for all the variables in the dataset for all pupils except those in school 12 and put them into columns 11 to 20, and then to pick out the values for all the variables in the original dataset only for pupils in school 12 and put those into columns 11 to 20 (overwriting the data we put in columns 11 to 20 originally). This is of course not a very useful thing to do in general, but it is useful if we just want to find out what the commands are for selecting and omitting data.

If we look at the generated commands, we can see a block of CHOOse commands and a block of OMIT commands. From their names they sound like they might be doing the important part of selecting and omitting, so we look them up in the Command manual. Under CHOOse we find

2.12 Command CHOOse

CHOOse only the items with value(s) <value> {to <value>} in <input key column>
{carrying <input group>} and put into <output key column> {with carried values to
<output group>} <input group> and <output group>, if specified, must have the same
number of columns. <input key column> and <output key column> must be specified, and
they may also belong to <input group> and <output group> respectively. For example, if C1
= (1 2 3 4 2 3 4 5), C2 = (1 2 3 4 5 6 7 8), C3 = (0 1 2 3 4 5 6 7), B7 = 3, then CHOO 1 B7
C1 C2-C3 C11 C12-C13 gives C11 = (1 2 3 2 3), C12 = (1 2 3 5 6), C13 = (0 1 2 4 5) If
the values are such that nothing is chosen from the input key column then the output columns
will all have zero length. See also OMIT.

and under OMIT we find

2.35 Command OMIT

OMIT items with value(s) <value> {to <value>} from <input key column> {carrying
<input group>}, remainder to <output key column> {with carried values to <output
group>} <input group> and <output group>, if they are specified, must have the same
number of columns. <input key column> and <output key column> must be specified, and
they may also belong to <input group> and <output group> respectively. For example
OMIT 1 C3 C1-C10 C13 C11-C20 will copy the records in C1-C10 across to C11-C20,
omitting any records that contain a 1 in C3. OMIT 1 C3 C1-C2 C4-C10 C13 C11-C12 C14-
C20 has the same effect. If the values are such that every value is chosen for omission from
the input key column then the output columns will all have zero length

Reading these entries, we can see that to achieve the selecting and omitting we have just performed, we need a column (let's call it c30) which takes the value 1 when school = 12 and 0 otherwise, and then we can just use these commands:

CHOOse 1 c30 c1-c10 c31 c11-c20
OMIT 1 c30 c1-c10 c31 c11-c20

Now we just need to generate c30 with the correct values. If we look again at the commands we copied from the Command interface window, this command looks likely:

CALCulate C1500= 'school' ==12

MLwiN has used c1500 instead of c30, but checking the entry for CALC in the command manual confirms that indeed this is creating a variable that takes the value 1 when school is 12 and 0 otherwise. So our completed set of commands to replicate what we did using the graphical user interface is:

CALC c30 = 'school' == 12
CHOOse 1 c30 c1-c10 c31 c11-c20
OMIT 1 c30 c1-c10 c31 c11-c20

Which is quite a bit shorter than the set of commands that MLwiN used. This is partly because MLwiN did not enter the columns we selected or omitted from into a single command in a group, but generated a CHOOse (or OMIT) command for each column. We don't have to do this. Then when we performed the Omit, we were outputting into columns that already had data. MLwiN saved the data that was in those columns by putting it all into c1500 with a series of JOIN commands, so that we could undo the OMIT and get back the data originally in those columns. But we don't need to do that because we know we don't want the data that was in those columns. Then MLwiN has erased the data in the column used for comparison (c1500 when we were selecting and c1499 when we were omitting), and then renamed it. We don't need to do this with our c30. At the beginning, after a command opening the worksheet (not part of the selecting and omitting operation), MLwiN has put the commands PREF 0 and POST 0. These are necessary when running certain types of model, but we don't need them just to select and omit. And finally, MLwiN has added some WSET commands, which just refresh the windows.

The lesson from this is that it is important to try to work out which of the commands generated by MLwiN you need and which you don't.

(Back to top)

Edit this page