Why run HLM models in batch mode?
- The more you can do in batch mode, the less you have to do using repeated points and clicks.
- If running many models, you can write code that submits the models at the command line, saving time.
- It is possible to schedule model runs.
- Gains in efficiency for advanced users.
- More replicable process than repeated point-and-click.
After some initial setup of files using the HLM interface, it can be easy and fast to run your HLM models in batch mode. This page will outline the necessary steps for a two-level model using a level-1 dataset HSB-L1.SAV and a level-2 dataset HSB-L2.SAV.
In order to run HLM in batch mode, you will first need to generate .mdmt and .mdm files. After specifying the data files in HLM, indicating the needed variables out of each, and providing a .mdm file name, you can click on “Save mdmt file”.
Next, click on “Check Stats”. This will open a .sts file with descriptive statistics for both datasets. If these look correct, click on “Make MDM”.
You now have all of the essential information needed for running a model. The .mdm file is a binary file containing the information needed from the data files for fitting models. The .mdmt file can be opened and read as text. It indicates the locations of the data files, the name of the .mdm file, and the variables to be used.
Next, you can build a model in HLM. For some introductory HLM model-building information, see our Seminar on Multilevel Modeling Using HLM. We are interested in modeling math achievement (MATHACH) with FEMALE as a level-1 predictor and MEANSES as a level-2 predictor. In HLM, you can click on “Level-1” or “Level-2” to see the variables available at each level. Then, when you click on a variable name, you are given options of how you can include it in your model.
Once you have specified the model you wish to run, you can choose “File, Save As” and save it as a .hlm file.
If you wish to run multiple models in batch mode, then you will need to indicate different names for the output files of each model. You can do this by opening the .hlm files in a text editor and changing the “output” line. Below is the .hlm file that we will run in batch mode.
We now have all of the files we would need. In order to run HLM in batch mode, you must have a path pointing to HLM. For instructions on how to set up this path, see How can I set the path variable to point to HLM?.
On a Windows machine, you can get to the command line by choosing “Run” from the start menu and then entering “cmd”. On a Mac, you can open a Terminal window. Once here, you can navigate to the folder that contains your HLM files. To run a model, you simply need to enter the .mdm and .hlm file names after the name of the module that matches the type of model you are running:
- hlm2 for 2-level models, no missing data
- hlm3 for 3-level models, no missing data
- hmlm, hlml2, and hcm2 for various combinations of missing data and levels
For the model above, we enter: hlm2 HSB_demo.mdm HSB_demo1.hlm. Once this is entered, the iteration output begins to appear in the command window and the output .txt file is generated.