楼主: Kamize
1717 0

[stata资源分享] Tip5:hlm线性分层回归 [推广有奖]

院士

28%

还不是VIP/贵宾

-

威望
0
论坛币
83511 个
通用积分
263.0394
学术水平
168 点
热心指数
194 点
信用等级
142 点
经验
492 点
帖子
5147
精华
0
在线时间
1713 小时
注册时间
2012-4-6
最后登录
2024-4-20

楼主
Kamize 学生认证  发表于 2016-8-23 23:53:58 |只看作者 |坛友微信交流群|倒序 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

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 save hsball describeContains 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 pracad float %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 idid | 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 STATISTICSVARIABLE 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.99LEVEL-2 DESCRIPTIVE STATISTICSVARIABLE 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.

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:HLM tip Multivariate descriptive multivariat sufficient following interface directly discuss

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-1 12:57