|
|
|
||||
|
|
|||||
This chapter uses data file gpach5.dta and vocagrwt.dta. This chapter also uses the program gllamm and can be downloaded in Stata by typing findit gllamm (see How can I use the findit command to search for programs and get additional help? for more information about using findit). See http://www.gllamm.org for more info.
Table 5.1 cannot be done in Stata yet.
Table 5.2 on page 79.
use http://www.ats.ucla.edu/stat/stata/examples/mlm_ma_hox/gpach5, clear
table sex _id, contents(mean gpa) col row format(%3.1f)
-----------------------------------------------------------
student | _id
gender | 1 2 3 4 5 6 Total
----------+------------------------------------------------
male | 2.6 2.7 2.7 2.8 2.9 3.0 2.8
female | 2.6 2.8 2.9 3.0 3.1 3.2 2.9
|
Total | 2.6 2.7 2.8 2.9 3.0 3.1 2.9
-----------------------------------------------------------
Figure 5.3 on page 80.
histogram gpa, normal frequency width(.25) start(1.625) xlabel(1.75(.25)4)
Table 5.3 on page 81.
Part 1: Null model.
gllamm gpa, i(student) nrf(1) eq(g_cons) adapt nip(10)
number of level 1 units = 1200
number of level 2 units = 200
Condition Number = 1.4717374
gllamm model
log likelihood = -456.72811
------------------------------------------------------------------------------
gpa | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | 2.865 .0191093 149.93 0.000 2.827547 2.902454
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
.09759579 (.00436475)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (student
var(1): .05676704 (.00733942)
------------------------------------------------------------------------------
Part 2: With additional variable time which is created as follows.
gllamm gpa time, i(student) nrf(1) eq(g_cons) adapt nip(10)
Iteration 0: log likelihood = -196.82458
Iteration 1: log likelihood = -196.82458 (backed up)
number of level 1 units = 1200
number of level 2 units = 200
Condition Number = 6.2549449
gllamm model
log likelihood = -196.82458
------------------------------------------------------------------------------
gpa | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
time | .1063144 .004072 26.11 0.000 .0983335 .1142953
_cons | 2.599213 .0216524 120.04 0.000 2.556775 2.641651
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
.05803303 (.00259537)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (student)
var(1): .06336734 (.00731719)
------------------------------------------------------------------------------
Part 3: The variable job is added.
gllamm gpa time job, i(student) nrf(1) eq(g_cons) adapt nip(10)
Iteration 0: log likelihood = -160.1304
Iteration 1: log likelihood = -160.1304 (backed up)
number of level 1 units = 1200
number of level 2 units = 200
Condition Number = 14.263506
gllamm model
log likelihood = -160.1304
------------------------------------------------------------------------------
gpa | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
time | .1031661 .0040027 25.77 0.000 .095321 .1110113
job | -.1608553 .018671 -8.62 0.000 -.1974497 -.1242609
_cons | 2.945819 .0450675 65.36 0.000 2.857489 3.03415
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
.05560831 (.00249404)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (student)
var(1): .05337401 (.00637367)
------------------------------------------------------------------------------
Part 4: The variable highgpa and sex are added to the model.
gllamm gpa time job highgpa sex, i(student) nrf(1) eq(g_cons) adapt nip(10)
Iteration 0: log likelihood = -147.27247
Iteration 1: log likelihood = -147.27247 (backed up)
number of level 1 units = 1200
number of level 2 units = 200
Condition Number = 38.648951
gllamm model
log likelihood = -147.27247
------------------------------------------------------------------------------
gpa | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
time | .1031483 .0040029 25.77 0.000 .0953027 .1109939
job | -.1617663 .0186339 -8.68 0.000 -.1982881 -.1252445
highgpa | .0858382 .0279804 3.07 0.002 .0309977 .1406788
sex | .148397 .0333168 4.45 0.000 .0830972 .2136968
_cons | 2.465035 .1116246 22.08 0.000 2.246255 2.683815
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
.05561708 (.0024948)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (student)
var(1): .0457676 (.00560837)
------------------------------------------------------------------------------
Table 5.4 on page 83.
Part 1: The variable time is included as a random effect.
eq g_time: time
gllamm gpa time job highgpa sex, i(student) nrf(2) eq(g_cons g_time) adapt nip(10)
Iteration 0: log likelihood = -90.102469
Iteration 1: log likelihood = -90.102469 (backed up)
number of level 1 units = 1200
number of level 2 units = 200
Condition Number = 31.095279
gllamm model
log likelihood = -90.102469
------------------------------------------------------------------------------
gpa | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
time | .1039732 .0056229 18.49 0.000 .0929524 .1149939
job | -.1196185 .0178972 -6.68 0.000 -.1546965 -.0845406
highgpa | .0898356 .0264797 3.39 0.001 .0379363 .1417348
sex | .1167594 .0320687 3.64 0.000 .0539059 .1796129
_cons | 2.410522 .1053438 22.88 0.000 2.204052 2.616992
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
.04176464 (.00209932)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (student)
var(1): .03897208 (.00622169)
cov(2,1): -.00256362 (.00155826) cor(2,1): -.20761373
var(2): .00391238 (.00064558)
------------------------------------------------------------------------------
Part 2: Cross level interaction of variable time and sex is included. We first created the interaction term.
gllamm gpa time job highgpa sex sxtime, i(student) nrf(2) eq(g_cons g_time) adapt nip(10)
Iteration 0: log likelihood = -86.602003
Iteration 1: log likelihood = -86.602003 (backed up)
number of level 1 units = 1200
number of level 2 units = 200
Condition Number = 44.773319
gllamm model
log likelihood = -86.602003
------------------------------------------------------------------------------
gpa | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
time | .0590056 .0177217 3.33 0.001 .0242717 .0937396
job | -.1206102 .0178752 -6.75 0.000 -.1556449 -.0855755
highgpa | .0898071 .0264718 3.39 0.001 .0379234 .1416908
sex | .076796 .0348998 2.20 0.028 .0083936 .1451983
sxtime | .0294742 .0110401 2.67 0.008 .0078359 .0511124
_cons | 2.473688 .1079959 22.91 0.000 2.26202 2.685356
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
.04177691 (.00210044)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (student)
var(1): .03855588 (.00614952)
cov(2,1): -.00227235 (.00150606) cor(2,1): -.19047364
var(2): .0036914 (.00062422)
------------------------------------------------------------------------------
Figure 5.4 on page 84 based on the previous model.
gen p = 2.473688 + .0590056*time + .076796*sex + .0294742*sxtime sort sex occas label variable p "Predicted GPA" graph twoway scatter p occas, connect(L) ylabel(2.5(.1)3.3)
Table 5.5 on page 85.
Part 1: 1st occasion = 0, same as the first part of Table 5.4. We only show the result here.
gllamm model
log likelihood = -90.102469
------------------------------------------------------------------------------
gpa | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
time | .1039732 .0056229 18.49 0.000 .0929524 .1149939
job | -.1196185 .0178972 -6.68 0.000 -.1546965 -.0845406
highgpa | .0898356 .0264797 3.39 0.001 .0379363 .1417348
sex | .1167594 .0320687 3.64 0.000 .0539059 .1796129
_cons | 2.410522 .1053438 22.88 0.000 2.204052 2.616992
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
.04176464 (.00209932)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (student)
var(1): .03897208 (.00622169)
cov(2,1): -.00256362 (.00155826) cor(2,1): -.20761373
var(2): .00391238 (.00064558)
------------------------------------------------------------------------------
Part 2: The variable time has been recoded as -5, ...,-1, 0, ...with the last occasion coded as zero. We first recode variable time into time1.
gen time1 = time -5
eq g_time1: time1
gllamm gpa time1 job highgpa sex , i(student) nrf(2) eq(g_cons g_time1) adapt nip(10)
Iteration 0: log likelihood = -90.102469
Iteration 1: log likelihood = -90.102469 (backed up)
number of level 1 units = 1200
number of level 2 units = 200
Condition Number = 40.98262
gllamm model
log likelihood = -90.102469
------------------------------------------------------------------------------
gpa | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
time1 | .1039732 .0056228 18.49 0.000 .0929528 .1149936
job | -.1196165 .0178973 -6.68 0.000 -.1546946 -.0845384
highgpa | .0898384 .0264797 3.39 0.001 .0379392 .1417375
sex | .1167699 .0320687 3.64 0.000 .0539165 .1796233
_cons | 2.930359 .106397 27.54 0.000 2.721825 3.138893
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
.04176531 (.00209938)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (student)
var(1): .11113844 (.01373522)
cov(2,1): .01699662 (.00267605) cor(2,1): .81514093
var(2): .00391197 (.00064553)
------------------------------------------------------------------------------
Part 3: The variable time is recoded centered around its mean and is included as a fixed effect.
gen timec = time - 2.5
eq g_timec: timec
gllamm gpa timec job highgpa sex , i(student) nrf(2) eq(g_cons g_timec) adapt nip(10)
Iteration 0: log likelihood = -90.102469
Iteration 1: log likelihood = -90.102469 (backed up)
number of level 1 units = 1200
number of level 2 units = 200
Condition Number = 30.467281
gllamm model
log likelihood = -90.102469
------------------------------------------------------------------------------
gpa | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
timec | .1039732 .005623 18.49 0.000 .0929524 .114994
job | -.1196183 .0178972 -6.68 0.000 -.1546962 -.0845403
highgpa | .0898356 .0264798 3.39 0.001 .0379361 .141735
sex | .1167599 .0320688 3.64 0.000 .0539061 .1796136
_cons | 2.670454 .1049347 25.45 0.000 2.464785 2.876122
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
.04176458 (.00209931)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (student)
var(1): .05060669 (.00588538)
cov(2,1): .00721735 (.00148005) cor(2,1): .51291762
var(2): .00391248 (.0006456)
------------------------------------------------------------------------------
Table 5.6 using data file vocagrwt.dta.
use http://www.ats.ucla.edu/stat/stata/examples/mlm_ma_hox/vocagrwt, clear
table age, contents (count child)
----------------------
age in |
months | N(child)
----------+-----------
12 | 22
14 | 5
16 | 22
18 | 11
20 | 22
22 | 11
24 | 22
26 | 11
----------------------
Table 5.7 on page 89. We have to recode the variable study as follows.
Part 1: Intercept only model.
gen study1 = study - .5
gen cons = 1
eq v_cons: cons
gllamm vocab study1, i(child) nrf(1) eq(v_cons) adapt nip(10)
Iteration 0: log likelihood = -834.45006
Iteration 1: log likelihood = -834.45006
number of level 1 units = 126
number of level 2 units = 22
Condition Number = 596.61779
gllamm model
log likelihood = -834.45006
------------------------------------------------------------------------------
vocab | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
study1 | -110.8963 38.97705 -2.85 0.004 -187.2899 -34.50267
_cons | 132.0813 19.48851 6.78 0.000 93.88453 170.2781
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
31093.057 (4206.1879)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (child)
var(1): 2380.0752 (2141.8272)
------------------------------------------------------------------------------
Part 2: The variable age is grand mean centered and is included as a fixed effect.
sum age
Variable | Obs Mean Std. Dev. Min Max
-------------+-----------------------------------------------------
age | 126 18.88889 4.578598 12 26
gen agec = age - r(mean)
gllamm vocab study1 agec, i(child) nrf(1) eq(v_cons) adapt nip(10)
Iteration 0: log likelihood = -775.4679
Iteration 1: log likelihood = -775.4679 (backed up)
number of level 1 units = 126
number of level 2 units = 22
Condition Number = 521.07612
gllamm model
log likelihood = -775.4679
------------------------------------------------------------------------------
vocab | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
study1 | -69.88163 35.55822 -1.97 0.049 -139.5745 -.1888013
agec | 29.55448 2.016058 14.66 0.000 25.60308 33.50588
_cons | 137.7377 17.72871 7.77 0.000 102.99 172.4853
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
10399.904 (1425.6387)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (child)
var(1): 4911.2905 (1952.9652)
------------------------------------------------------------------------------
Part 3: The squared term of agec is included as a fixed effect.
gen agec2 = agec*agec
gllamm vocab study1 agec agec2, i(child) nrf(1) eq(v_cons) adapt nip(10)
Iteration 0: log likelihood = -759.74093
Iteration 1: log likelihood = -759.74093 (backed up)
number of level 1 units = 126
number of level 2 units = 22
Condition Number = 509.05373
gllamm model
log likelihood = -759.74093
------------------------------------------------------------------------------
vocab | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
study1 | -68.20181 34.86173 -1.96 0.050 -136.5295 .1259239
agec | 30.62186 1.746205 17.54 0.000 27.19937 34.04436
agec2 | 2.557382 .4227474 6.05 0.000 1.728812 3.385952
_cons | 84.75887 19.47127 4.35 0.000 46.59588 122.9218
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
7722.6782 (1060.4462)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (child)
var(1): 5166.8894 (1903.1278)
------------------------------------------------------------------------------
Part 4: The centered variable agec is included as a random effect.
Table 5.8 on page 91.
Part 1: Intercept only model. This is Part 1 from Table 5.7. We only show the output here.
gllamm model
log likelihood = -834.45006
------------------------------------------------------------------------------
vocab | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
study1 | -110.8963 38.97705 -2.85 0.004 -187.2899 -34.50267
_cons | 132.0813 19.48851 6.78 0.000 93.88453 170.2781
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
31093.057 (4206.1879)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (child)
var(1): 2380.0752 (2141.8272)
------------------------------------------------------------------------------
Part 2: The variable age is centered on 12 months and is included as a fixed effect.
gllamm vocab study1 age12, i(child) nrf(1) eq(v_cons) adapt nip(10)
Iteration 0: log likelihood = -775.46794
Iteration 1: log likelihood = -775.46794 (backed up)
number of level 1 units = 126
number of level 2 units = 22
Condition Number = 520.59741
gllamm model
log likelihood = -775.46794
------------------------------------------------------------------------------
vocab | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
study1 | -69.90737 35.5669 -1.97 0.049 -139.6172 -.197528
age12 | 29.55647 2.01611 14.66 0.000 25.60497 33.50797
_cons | -65.89678 22.27908 -2.96 0.003 -109.563 -22.2306
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
10400.451 (1425.7349)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (child)
var(1): 4914.585 (1954.6604)
------------------------------------------------------------------------------
Part 3: The variable age12sq is included as a fixed effect.
gllamm vocab study1 age12 age12sq, i(child) nrf(1) eq(v_cons) adapt nip(10)
Iteration 0: log likelihood = -759.74093
Iteration 1: log likelihood = -759.74093 (backed up)
number of level 1 units = 126
number of level 2 units = 22
Condition Number = 508.73928
gllamm model
log likelihood = -759.74093
------------------------------------------------------------------------------
vocab | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
study1 | -68.19972 34.86188 -1.96 0.050 -136.5278 .1283173
age12 | -4.606058 5.911176 -0.78 0.436 -16.19175 6.979635
age12sq | 2.556963 .4227471 6.05 0.000 1.728394 3.385532
_cons | -4.841737 23.23211 -0.21 0.835 -50.37583 40.69236
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
7722.6687 (1060.444)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (child)
var(1): 5166.9513 (1903.1554)
------------------------------------------------------------------------------
Part 4: The variable age12 is a random effect.
eq v_age12: age12
gllamm vocab study1 age12 age12sq, i(child) nrf(2) eq(v_age12 v_cons) adapt nip(10)
Iteration 0: log likelihood = -651.37636
Iteration 1: log likelihood = -651.37636
number of level 1 units = 126
number of level 2 units = 22
Condition Number = 132.5395
gllamm model
log likelihood = -651.37636
------------------------------------------------------------------------------
vocab | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
study1 | -4.943219 8.867463 -0.56 0.577 -22.32313 12.43669
age12 | -1.855363 3.888879 -0.48 0.633 -9.477426 5.766701
age12sq | 2.175521 .1455255 14.95 0.000 1.890296 2.460745
_cons | -2.55427 8.332226 -0.31 0.759 -18.88513 13.77659
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
863.23649 (119.76275)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (child)
var(1): 245.25175 (75.873786)
cov(2,1): -437.32308 (158.8109) cor(2,1): -1
var(2): 779.81698 (359.79036)
------------------------------------------------------------------------------
Table 5.9 on page 92 is created using HLM. We omit it here.
Table 5.10 on page 101 using the data file gpach5.dta.
use http://www.ats.ucla.edu/stat/stata/examples/mlm_ma_hox/gpach5, clear
Part 1: The variable time is a fixed effect. We have built the model at the beginning of this chapter. We will use it here.
gllamm gpa time job highgpa sex, i(student) nrf(1) eq(g_cons) adapt nip(10)
Iteration 0: log likelihood = -147.27247
Iteration 1: log likelihood = -147.27247 (backed up)
number of level 1 units = 1200
number of level 2 units = 200
Condition Number = 38.648951
gllamm model
log likelihood = -147.27247
------------------------------------------------------------------------------
gpa | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
time | .1031483 .0040029 25.77 0.000 .0953027 .1109939
job | -.1617663 .0186339 -8.68 0.000 -.1982881 -.1252445
highgpa | .0858382 .0279804 3.07 0.002 .0309977 .1406788
sex | .148397 .0333168 4.45 0.000 .0830972 .2136968
_cons | 2.465035 .1116246 22.08 0.000 2.246255 2.683815
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
.05561708 (.0024948)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (student)
var(1): .0457676 (.00560837)
------------------------------------------------------------------------------
Part 2: The variable time is included as random effect. This is Part 1 of table 5.4.
eq g_time: time
gllamm gpa time job highgpa sex, i(student) nrf(2) eq(g_cons g_time) adapt nip(10)
Iteration 0: log likelihood = -90.102469
Iteration 1: log likelihood = -90.102469 (backed up)
number of level 1 units = 1200
number of level 2 units = 200
Condition Number = 31.095279
gllamm model
log likelihood = -90.102469
------------------------------------------------------------------------------
gpa | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
time | .1039732 .0056229 18.49 0.000 .0929524 .1149939
job | -.1196185 .0178972 -6.68 0.000 -.1546965 -.0845406
highgpa | .0898356 .0264797 3.39 0.001 .0379363 .1417348
sex | .1167594 .0320687 3.64 0.000 .0539059 .1796129
_cons | 2.410522 .1053438 22.88 0.000 2.204052 2.616992
------------------------------------------------------------------------------
Variance at level 1
------------------------------------------------------------------------------
.04176464 (.00209932)
Variances and covariances of random effects
------------------------------------------------------------------------------
***level 2 (student)
var(1): .03897208 (.00622169)
cov(2,1): -.00256362 (.00155826) cor(2,1): -.20761373
var(2): .00391238 (.00064558)
------------------------------------------------------------------------------
Part 3: The variable time is a fixed effect, MANOVA.
foreach X of numlist 1(1) 6 {gen o`X' = (`X'==occas)}
foreach X of numlist 1(1) 6 {eq g_`X': o`X'}
gllamm gpa time job highgpa sex, i(student) nrf(6) eq(g_1 g_2 g_3 g_4 g_5 g_6) adapt nip(10)
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services