use use https://stats.idre.ucla.edu/stat/stata/examples/alda/data/opposites_pp, clear
* Table 7.2, pg. 246
* Conventional multilevel model for change: Opposite naming data, Restricted ML
mixed opp c.time##c.ccog || id: time, reml cov(un)
Performing EM optimization ...
Performing gradient-based optimization:
Iteration 0: Log restricted-likelihood = -630.14238
Iteration 1: Log restricted-likelihood = -630.14238
Computing standard errors ...
Mixed-effects REML regression Number of obs = 140
Group variable: id Number of groups = 35
Obs per group:
min = 4
avg = 4.0
max = 4
Wald chi2(3) = 191.85
Log restricted-likelihood = -630.14238 Prob > chi2 = 0.0000
---------------------------------------------------------------------------------
opp | Coefficient Std. err. z P>|z| [95% conf. interval]
----------------+----------------------------------------------------------------
time | 26.95998 1.993881 13.52 0.000 23.05205 30.86792
ccog | -.1135527 .5040122 -0.23 0.822 -1.101398 .874293
|
c.time#c.ccog | .4328577 .1619279 2.67 0.008 .1154849 .7502306
|
_cons | 164.3743 6.206099 26.49 0.000 152.2106 176.538
---------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
id: Unstructured |
var(time) | 107.2493 34.67673 56.90847 202.1212
var(_cons) | 1236.414 332.4029 730.0008 2094.135
cov(time,_cons) | -178.2335 85.42989 -345.673 -10.79396
-----------------------------+------------------------------------------------
var(Residual) | 159.477 26.95653 114.5035 222.1147
------------------------------------------------------------------------------
LR test vs. linear model: chi2(3) = 120.72 Prob > chi2 = 0.0000
Note: LR test is conservative and provided only for reference.
*Get fit indices. Deviance is 2*ll(model).
estat ic
Akaike's information criterion and Bayesian information criterion
-----------------------------------------------------------------------------
Model | N ll(null) ll(model) df AIC BIC
-------------+---------------------------------------------------------------
. | 140 . -630.1424 8 1276.285 1299.818
-----------------------------------------------------------------------------
Note: BIC uses N = number of observations. See [R] IC note.
/*
Table 7.3, pg 258-259
Conventional multilevel model for change: Opposite naming data,
Comparing alternative error structures at level-1, with none at level-2 (REML).
*/
*unstructured
mixed opp c.time##c.ccog || id: , reml residuals(un, t(wave)) noconstant
Performing gradient-based optimization:
Iteration 0: Log restricted-likelihood = -690.50483 (not concave)
Iteration 1: Log restricted-likelihood = -651.8354 (not concave)
Iteration 2: Log restricted-likelihood = -635.69879
Iteration 3: Log restricted-likelihood = -629.49921
Iteration 4: Log restricted-likelihood = -627.9363
Iteration 5: Log restricted-likelihood = -627.8945
Iteration 6: Log restricted-likelihood = -627.89441
Iteration 7: Log restricted-likelihood = -627.89441
Computing standard errors ...
Mixed-effects REML regression Number of obs = 140
Group variable: id Number of groups = 35
Obs per group:
min = 4
avg = 4.0
max = 4
Wald chi2(3) = 201.54
Log restricted-likelihood = -627.89441 Prob > chi2 = 0.0000
-------------------------------------------------------------------------------
opp | Coefficient Std. err. z P>|z| [95% conf. interval]
--------------+----------------------------------------------------------------
time | 26.58438 1.925883 13.80 0.000 22.80972 30.35904
ccog | -.0740848 .4834593 -0.15 0.878 -1.021648 .8734781
|
c.time#c.ccog | .4582924 .1564056 2.93 0.003 .1517431 .7648418
|
_cons | 165.8321 5.953023 27.86 0.000 154.1644 177.4998
-------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
id: (empty) |
-----------------------------+------------------------------------------------
Residual: Unstructured |
var(e1) | 1345.124 330.293 831.2873 2176.574
var(e2) | 1150.473 282.2083 711.3428 1860.691
var(e3) | 1235.768 301.8905 765.5857 1994.712
var(e4) | 1205.956 296.73 744.5434 1953.317
cov(e1,e2) | 1005.78 277.9799 460.9491 1550.61
cov(e1,e3) | 946.1969 276.9865 403.3133 1489.08
cov(e1,e4) | 583.202 243.6272 105.7015 1060.702
cov(e2,e3) | 1028.537 272.8032 493.8522 1563.221
cov(e2,e4) | 846.5654 252.1232 352.413 1340.718
cov(e3,e4) | 969.2858 270.8016 438.5243 1500.047
------------------------------------------------------------------------------
LR test vs. linear model: chi2(9) = 125.22 Prob > chi2 = 0.0000
Note: The reported degrees of freedom assumes the null hypothesis is not on the boundary of the parameter space. If
this is not true, then the reported test is conservative.
*compound symmetry(exchangeable)
mixed opp c.time##c.ccog || id: , reml residuals(ex, t(wave)) noconstant
Note: t() not required for this residual structure; ignored
Performing gradient-based optimization:
Iteration 0: Log restricted-likelihood = -690.50483
Iteration 1: Log restricted-likelihood = -643.56325
Iteration 2: Log restricted-likelihood = -643.52387
Iteration 3: Log restricted-likelihood = -643.52383
Computing standard errors ...
Mixed-effects REML regression Number of obs = 140
Group variable: id Number of groups = 35
Obs per group:
min = 4
avg = 4.0
max = 4
Wald chi2(3) = 400.51
Log restricted-likelihood = -643.52383 Prob > chi2 = 0.0000
-------------------------------------------------------------------------------
opp | Coefficient Std. err. z P>|z| [95% conf. interval]
--------------+----------------------------------------------------------------
time | 26.95998 1.375883 19.59 0.000 24.2633 29.65666
ccog | -.1135527 .461855 -0.25 0.806 -1.018772 .7916665
|
c.time#c.ccog | .4328577 .1117387 3.87 0.000 .2138539 .6518616
|
_cons | 164.3743 5.687002 28.90 0.000 153.228 175.5206
-------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
id: (empty) |
-----------------------------+------------------------------------------------
Residual: Exchangeable |
var(e) | 1231.355 244.4355 834.472 1816.999
cov(e) | 900.0706 242.2461 425.277 1374.864
------------------------------------------------------------------------------
LR test vs. linear model: chi2(1) = 93.96 Prob > chi2 = 0.0000
Note: The reported degrees of freedom assumes the null hypothesis is not on the boundary of the parameter space. If
this is not true, then the reported test is conservative.
*Get level 1 residual variance
display 1231.355-900.0711
331.2839
*NOTE: Cannot specify heterogeneous compound symmetry in Stata
*autoregressive
mixed opp c.time##c.ccog || id: , reml residuals(ar, t(wave)) noconstant
Performing gradient-based optimization:
Iteration 0: Log restricted-likelihood = -690.50483
Iteration 1: Log restricted-likelihood = -657.30842 (backed up)
Iteration 2: Log restricted-likelihood = -632.9387
Iteration 3: Log restricted-likelihood = -632.93822
Iteration 4: Log restricted-likelihood = -632.93822
Computing standard errors ...
Mixed-effects REML regression Number of obs = 140
Group variable: id Number of groups = 35
Obs per group:
min = 4
avg = 4.0
max = 4
Wald chi2(3) = 221.36
Log restricted-likelihood = -632.93822 Prob > chi2 = 0.0000
-------------------------------------------------------------------------------
opp | Coefficient Std. err. z P>|z| [95% conf. interval]
--------------+----------------------------------------------------------------
time | 27.19789 1.868923 14.55 0.000 23.53487 30.86091
ccog | -.03324 .4856219 -0.07 0.945 -.9850414 .9185614
|
c.time#c.ccog | .4196712 .1517797 2.77 0.006 .1221885 .717154
|
_cons | 164.3386 5.979652 27.48 0.000 152.6187 176.0585
-------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
id: (empty) |
-----------------------------+------------------------------------------------
Residual: AR(1) |
rho | .8253423 .039481 .7308867 .8887754
var(e) | 1256.686 248.2353 853.2721 1850.828
------------------------------------------------------------------------------
LR test vs. linear model: chi2(1) = 115.13 Prob > chi2 = 0.0000
Note: The reported degrees of freedom assumes the null hypothesis is not on the boundary of the parameter space. If
this is not true, then the reported test is conservative.
*NOTE: Cannot specify heterogeneous autoregressive in Stata
*toeplitz
mixed opp c.time##c.ccog || id: , reml var residuals(to, t(wave)) noconstant
Performing gradient-based optimization:
Iteration 0: Log restricted-likelihood = -690.50483 (not concave)
Iteration 1: Log restricted-likelihood = -666.53267 (not concave)
Iteration 2: Log restricted-likelihood = -650.70702 (not concave)
Iteration 3: Log restricted-likelihood = -642.16171
Iteration 4: Log restricted-likelihood = -632.0239
Iteration 5: Log restricted-likelihood = -629.2499
Iteration 6: Log restricted-likelihood = -629.04277
Iteration 7: Log restricted-likelihood = -629.04036
Iteration 8: Log restricted-likelihood = -629.04035
Computing standard errors ...
Mixed-effects REML regression Number of obs = 140
Group variable: id Number of groups = 35
Obs per group:
min = 4
avg = 4.0
max = 4
Wald chi2(3) = 201.71
Log restricted-likelihood = -629.04035 Prob > chi2 = 0.0000
-------------------------------------------------------------------------------
opp | Coefficient Std. err. z P>|z| [95% conf. interval]
--------------+----------------------------------------------------------------
time | 26.89541 1.942931 13.84 0.000 23.08734 30.70349
ccog | -.0007051 .480975 -0.00 0.999 -.9433988 .9419887
|
c.time#c.ccog | .4364364 .1577901 2.77 0.006 .1271736 .7456993
|
_cons | 165.0984 5.922434 27.88 0.000 153.4907 176.7062
-------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
id: (empty) |
-----------------------------+------------------------------------------------
Residual: Toeplitz(3) |
cov1 | 1029.312 239.5689 559.7658 1498.859
cov2 | 896.5791 232.7494 440.3986 1352.76
cov3 | 624.0486 234.886 163.6805 1084.417
var(e) | 1246.884 242.6643 851.4677 1825.93
------------------------------------------------------------------------------
LR test vs. linear model: chi2(3) = 122.93 Prob > chi2 = 0.0000
Note: The reported degrees of freedom assumes the null hypothesis is not on the boundary of the parameter space. If
this is not true, then the reported test is conservative.
/*
Table 7.4, pg 265
Comparing fixed effects in models with alternative error structures
*/
*Note Stata calculates AIC and BIC differently from SAS (which was used for the book)
*Standard error covariance structure
mixed opp c.time##c.ccog || id: time, reml cov(un)
Performing EM optimization ...
Performing gradient-based optimization:
Iteration 0: Log restricted-likelihood = -630.14238
Iteration 1: Log restricted-likelihood = -630.14238
Computing standard errors ...
Mixed-effects REML regression Number of obs = 140
Group variable: id Number of groups = 35
Obs per group:
min = 4
avg = 4.0
max = 4
Wald chi2(3) = 191.85
Log restricted-likelihood = -630.14238 Prob > chi2 = 0.0000
---------------------------------------------------------------------------------
opp | Coefficient Std. err. z P>|z| [95% conf. interval]
----------------+----------------------------------------------------------------
time | 26.95998 1.993881 13.52 0.000 23.05205 30.86792
ccog | -.1135527 .5040122 -0.23 0.822 -1.101398 .874293
|
c.time#c.ccog | .4328577 .1619279 2.67 0.008 .1154849 .7502306
|
_cons | 164.3743 6.206099 26.49 0.000 152.2106 176.538
---------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
id: Unstructured |
var(time) | 107.2493 34.67673 56.90847 202.1212
var(_cons) | 1236.414 332.4029 730.0008 2094.135
cov(time,_cons) | -178.2335 85.42989 -345.673 -10.79396
-----------------------------+------------------------------------------------
var(Residual) | 159.477 26.95653 114.5035 222.1147
------------------------------------------------------------------------------
LR test vs. linear model: chi2(3) = 120.72 Prob > chi2 = 0.0000
Note: LR test is conservative and provided only for reference.
* Get fit indices. Deviance is 2*ll(model).
estat ic
Akaike's information criterion and Bayesian information criterion
-----------------------------------------------------------------------------
Model | N ll(null) ll(model) df AIC BIC
-------------+---------------------------------------------------------------
. | 140 . -630.1424 8 1276.285 1299.818
-----------------------------------------------------------------------------
Note: BIC uses N = number of observations. See [R] IC note.
*toeplitz
mixed opp c.time##c.ccog || id:, reml var residuals(to, t(wave)) noconstant
Performing gradient-based optimization:
Iteration 0: Log restricted-likelihood = -690.50483 (not concave)
Iteration 1: Log restricted-likelihood = -666.53267 (not concave)
Iteration 2: Log restricted-likelihood = -650.70702 (not concave)
Iteration 3: Log restricted-likelihood = -642.16171
Iteration 4: Log restricted-likelihood = -632.0239
Iteration 5: Log restricted-likelihood = -629.2499
Iteration 6: Log restricted-likelihood = -629.04277
Iteration 7: Log restricted-likelihood = -629.04036
Iteration 8: Log restricted-likelihood = -629.04035
Computing standard errors ...
Mixed-effects REML regression Number of obs = 140
Group variable: id Number of groups = 35
Obs per group:
min = 4
avg = 4.0
max = 4
Wald chi2(3) = 201.71
Log restricted-likelihood = -629.04035 Prob > chi2 = 0.0000
-------------------------------------------------------------------------------
opp | Coefficient Std. err. z P>|z| [95% conf. interval]
--------------+----------------------------------------------------------------
time | 26.89541 1.942931 13.84 0.000 23.08734 30.70349
ccog | -.0007051 .480975 -0.00 0.999 -.9433988 .9419887
|
c.time#c.ccog | .4364364 .1577901 2.77 0.006 .1271736 .7456993
|
_cons | 165.0984 5.922434 27.88 0.000 153.4907 176.7062
-------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
id: (empty) |
-----------------------------+------------------------------------------------
Residual: Toeplitz(3) |
cov1 | 1029.312 239.5689 559.7658 1498.859
cov2 | 896.5791 232.7494 440.3986 1352.76
cov3 | 624.0486 234.886 163.6805 1084.417
var(e) | 1246.884 242.6643 851.4677 1825.93
------------------------------------------------------------------------------
LR test vs. linear model: chi2(3) = 122.93 Prob > chi2 = 0.0000
Note: The reported degrees of freedom assumes the null hypothesis is not on the boundary of the parameter space. If
this is not true, then the reported test is conservative.
* Get fit indices. Deviance is 2*ll(model).
estat ic
Akaike's information criterion and Bayesian information criterion
-----------------------------------------------------------------------------
Model | N ll(null) ll(model) df AIC BIC
-------------+---------------------------------------------------------------
. | 140 . -629.0404 8 1274.081 1297.614
-----------------------------------------------------------------------------
Note: BIC uses N = number of observations. See [R] IC note.
* Unstructured
mixed opp c.time##c.ccog || id: , reml residuals(un, t(wave)) noconstant
Performing gradient-based optimization:
Iteration 0: Log restricted-likelihood = -690.50483 (not concave)
Iteration 1: Log restricted-likelihood = -651.8354 (not concave)
Iteration 2: Log restricted-likelihood = -635.69879
Iteration 3: Log restricted-likelihood = -629.49921
Iteration 4: Log restricted-likelihood = -627.9363
Iteration 5: Log restricted-likelihood = -627.8945
Iteration 6: Log restricted-likelihood = -627.89441
Iteration 7: Log restricted-likelihood = -627.89441
Computing standard errors ...
Mixed-effects REML regression Number of obs = 140
Group variable: id Number of groups = 35
Obs per group:
min = 4
avg = 4.0
max = 4
Wald chi2(3) = 201.54
Log restricted-likelihood = -627.89441 Prob > chi2 = 0.0000
-------------------------------------------------------------------------------
opp | Coefficient Std. err. z P>|z| [95% conf. interval]
--------------+----------------------------------------------------------------
time | 26.58438 1.925883 13.80 0.000 22.80972 30.35904
ccog | -.0740848 .4834593 -0.15 0.878 -1.021648 .8734781
|
c.time#c.ccog | .4582924 .1564056 2.93 0.003 .1517431 .7648418
|
_cons | 165.8321 5.953023 27.86 0.000 154.1644 177.4998
-------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
id: (empty) |
-----------------------------+------------------------------------------------
Residual: Unstructured |
var(e1) | 1345.124 330.293 831.2873 2176.574
var(e2) | 1150.473 282.2083 711.3428 1860.691
var(e3) | 1235.768 301.8905 765.5857 1994.712
var(e4) | 1205.956 296.73 744.5434 1953.317
cov(e1,e2) | 1005.78 277.9799 460.9491 1550.61
cov(e1,e3) | 946.1969 276.9865 403.3133 1489.08
cov(e1,e4) | 583.202 243.6272 105.7015 1060.702
cov(e2,e3) | 1028.537 272.8032 493.8522 1563.221
cov(e2,e4) | 846.5654 252.1232 352.413 1340.718
cov(e3,e4) | 969.2858 270.8016 438.5243 1500.047
------------------------------------------------------------------------------
LR test vs. linear model: chi2(9) = 125.22 Prob > chi2 = 0.0000
Note: The reported degrees of freedom assumes the null hypothesis is not on the boundary of the parameter space. If
this is not true, then the reported test is conservative.
* Get fit indices. Deviance is 2*ll(model).
estat ic
Akaike's information criterion and Bayesian information criterion
-----------------------------------------------------------------------------
Model | N ll(null) ll(model) df AIC BIC
-------------+---------------------------------------------------------------
. | 140 . -627.8944 14 1283.789 1324.972
-----------------------------------------------------------------------------
Note: BIC uses N = number of observations. See [R] IC note.
