1. Random intercept model without independent variables


1.1 ML-estimation

Stata

use "_data/ess50.dta", clear

xtmixed stfdem || cntry:  // ML is default in Stata
estat icc

. use "_data/ess50.dta", clear

. 
. xtmixed stfdem || cntry:  // ML is default in Stata

Performing EM optimization: 

Performing gradient-based optimization: 

Iteration 0:   log likelihood = -24517.125  
Iteration 1:   log likelihood = -24517.125  

Computing standard errors:

Mixed-effects ML regression                     Number of obs     =     11,026
Group variable: cntry                           Number of groups  =         22

                                                Obs per group:
                                                              min =         46
                                                              avg =      501.2
                                                              max =      1,547

                                                Wald chi2(0)      =          .
Log likelihood = -24517.125                     Prob > chi2       =          .

------------------------------------------------------------------------------
      stfdem |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |   5.455405   .1666017    32.75   0.000     5.128871    5.781938
------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
cntry: Identity              |
                   sd(_cons) |    .771068   .1197082      .5687793    1.045302
-----------------------------+------------------------------------------------
                sd(Residual) |   2.227136   .0150127      2.197906    2.256756
------------------------------------------------------------------------------
LR test vs. linear model: chibar2(01) = 1157.51       Prob >= chibar2 = 0.0000

. estat icc

Intraclass correlation

------------------------------------------------------------------------------
                       Level |        ICC   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
                       cntry |   .1070351   .0297069      .0611934    .1806113
------------------------------------------------------------------------------

R

First: Save Model (like Stata’s est store)
multi1 <- lmer(stfdem ~ (1|cntry), data = ess, REML = FALSE) # REML is default in R

1 is R’s way of refering to an intercept

Then: Inspect model
Coefficients (Lower block in Stata output; std.dev no variance)
tidy(multi1)
Model fit (Upper block in Stata output)
glance(multi1)
Regression values for each observation, head shows only first 6 rows
augment(multi1) %>% head()
Shows intraclass correlation
icc(multi1) 
## 
## Linear mixed model
##  Family: gaussian (identity)
## Formula: stfdem ~ (1 | cntry)
## 
##   ICC (cntry): 0.107035

1.2 REML-estimation

Stata

ML is default in stata, REML-estimation can be achieved with option , reml
use "_data/ess50.dta", clear
xtmixed stfdem || cntry:, reml
estat icc

. use "_data/ess50.dta", clear

. xtmixed stfdem || cntry:, reml

Performing EM optimization: 

Performing gradient-based optimization: 

Iteration 0:   log restricted-likelihood = -24517.987  
Iteration 1:   log restricted-likelihood = -24517.987  

Computing standard errors:

Mixed-effects REML regression                   Number of obs     =     11,026
Group variable: cntry                           Number of groups  =         22

                                                Obs per group:
                                                              min =         46
                                                              avg =      501.2
                                                              max =      1,547

                                                Wald chi2(0)      =          .
Log restricted-likelihood = -24517.987          Prob > chi2       =          .

------------------------------------------------------------------------------
      stfdem |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |   5.455717   .1705508    31.99   0.000     5.121443     5.78999
------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
cntry: Identity              |
                   sd(_cons) |   .7898175   .1253521      .5786719    1.078006
-----------------------------+------------------------------------------------
                sd(Residual) |   2.227136   .0150127      2.197905    2.256755
------------------------------------------------------------------------------
LR test vs. linear model: chibar2(01) = 1161.54       Prob >= chibar2 = 0.0000

. estat icc

Intraclass correlation

------------------------------------------------------------------------------
                       Level |        ICC   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
                       cntry |   .1117152   .0315294      .0632058    .1899076
------------------------------------------------------------------------------

R

REML is default in R, option needs to be turned off for ML-estimation (REML = FALSE)
reml <- lmer(stfdem ~ (1|cntry), data = ess)               
ml   <- lmer(stfdem ~ (1|cntry), data = ess, REML = FALSE) 
icc(reml)
## 
## Linear mixed model
##  Family: gaussian (identity)
## Formula: stfdem ~ (1 | cntry)
## 
##   ICC (cntry): 0.111715
icc(ml)    
## 
## Linear mixed model
##  Family: gaussian (identity)
## Formula: stfdem ~ (1 | cntry)
## 
##   ICC (cntry): 0.107035
-> REML results differ from ML

1.3 Plot Data

Stata

  not available (?)
  

R

sjp.lmer(multi1, type = "fe.slope", vars = c("country"))