### Stata FAQ How to Convert a Stata file to a 2-level HLM file Using HLM Window Interface?

Note: The following is for HLM 5.04.

HLM does not generally use the raw data directly. It creates a sufficient statistics matrix stored in an SSM file for a univariate multi-level model and MDM file for a multivariate multi-level model.  In this page, we will discuss how to convert a Stata file into a 2-level HLM SSM file using HLM Window interface.

In order to use HLM's Window interface, we have to first create two Stata data files, one for level-1 data and one for level-2 data. Let's look at an example.

use http://www.ats.ucla.edu/stat/hlm/faq/hsball, clear
sort id /*This is necessary, since the data files have to be sorted.*/
save hsball
describe
Contains data from hsball.dta
obs:         7,185
vars:            11                          17 Oct 2002 09:34
size:       244,290 (76.1% of memory free)
-------------------------------------------------------------------------------
storage  display     value
variable name   type   format      label      variable label
-------------------------------------------------------------------------------
id              str4   %4s
size            int    %9.0g
sector          byte   %9.0g
disclim         float  %9.0g
himinty         byte   %9.0g
meanses         float  %9.0g
minority        byte   %9.0g
female          byte   %9.0g
ses             float  %9.0g
mathach         float  %9.0g
-------------------------------------------------------------------------------
Sorted by:  

The variable id here is school id. This can be seen from the following:

tab id
         id |      Freq.     Percent        Cum.
------------+-----------------------------------
1224 |         47        0.65        0.65
1288 |         25        0.35        1.00
1296 |         48        0.67        1.67
1308 |         20        0.28        1.95
1317 |         48        0.67        2.62
1358 |         30        0.42        3.03
1374 |         28        0.39        3.42
1433 |         35        0.49        3.91
1436 |         44        0.61        4.52
1461 |         33        0.46        4.98
1462 |         57        0.79        5.78
1477 |         62        0.86        6.64
1499 |         53        0.74        7.38
1637 |         27        0.38        7.75
1906 |         53        0.74        8.49
1909 |         28        0.39        8.88
1942 |         29        0.40        9.28
1946 |         39        0.54        9.83
2030 |         47        0.65       10.48
2208 |         60        0.84       11.32

Let's say the level-2 variables that we are interested in are size, sector and meanses. We can create a level-2 data file by collapsing the data.

collapse (mean) size sector meanses, by(id)
save hsb2
file hsb2.dta saved

Now we have two data files, hsball.dta for level-1 data and hsb2.dta for level-2. We can create an SSM file for HLM now. From HLM, click on Preferences and click on other non-ASCII for data file type.

Click on OK to set it up. Now From File, select SSM... -> New... -> Stat package input.

Our example is an HLM2 model, so we check on HLM2 and click on OK.

Following window will come up after we click on OK.

• Input level-1 file by clicking on Browse.

• Select level-1 Stata file

We can then choose the file type by scrolling down the long list of file types. We choose Stata V7 (8 byte doubles)(*.dta) for our example.

Then we select hsball.dta for the level-1 file. We then click on Open.

We are now back to the Make SSM-HLM2 window, and we see that the level-1 file is being recognized.

• Choose level-1 variables by clicking on Choose Variables.

There is always a variable that we have to choose for the ID variable, which indicates the level-2 structure. In our example, it is the id variable. So we check ID beside our id variable and check in SSM for all the other variables. Notice we don't have to select all the variables. If you know exactly what model you want to build, you can simply include those variables that are in the model. Now we can click OK and we are done with Level 1 data file.

• Select level-2 Stata file

It is very similar to selecting level-1 Stata file, we omit the details here.

• Create an SSM file

After entering an SSM file name, say hsb, we also need to save the response file. A response file is an ASCII file which contains all the information about the data files, such as the data file type, id variables, and formats. It is used by HLM to create the SSM file.

We are now ready to make an SSM file. We have to click on Make SSM and then click on Check Stats to finish the process. The following is what we should see by checking the statistics.

                      LEVEL-1 DESCRIPTIVE STATISTICS
 VARIABLE NAME       N       MEAN         SD         MINIMUM      MAXIMUM
SIZE          7185    1056.86     604.17       100.00      2713.00
SECTOR          7185       0.49       0.50         0.00         1.00
PRACAD          7185       0.53       0.25         0.00         1.00
DISCLIM          7185      -0.13       0.94        -2.42         2.76
HIMINTY          7185       0.28       0.45         0.00         1.00
MEANSES          7185       0.01       0.41        -1.19         0.83
MINORITY          7185       0.27       0.45         0.00         1.00
FEMALE          7185       0.53       0.50         0.00         1.00
SES          7185       0.00       0.78        -3.76         2.69
MATHACH          7185      12.75       6.88        -2.83        24.99

                      LEVEL-2 DESCRIPTIVE STATISTICS
 VARIABLE NAME       N       MEAN         SD         MINIMUM      MAXIMUM
SIZE           160    1097.82     629.51       100.00      2713.00
SECTOR           160       0.44       0.50         0.00         1.00
MEANSES           160      -0.00       0.41        -1.19         0.83

After that, we can click on Done and we will be in the analysis window.

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.