1. Adapt the model of today’s session such that it might fit the data better in Czech Republic, Poland, and Hungary. Investigate whether your adaption is indeed an improvement.

2. Add the unemployment rate of 2011 and immigrant integration policies to today’s model. Inspect the distribution of the random effects; does anything look suspicious?

# Small self-written function for z-standardization
std <- function(x) {
  (x - mean(x, na.rm = TRUE)) / sd(x, na.rm = TRUE)
}

# Import the ESS round 7 data via the API
ESS <- import_rounds(rounds = 7, ess_email = YOUR_EMAIL) %>%
  recode_missings() %>%
  filter(brncntr == 1 & mocntr == 1 & facntr == 1 & cntry != "IL") %>%
  mutate(
    ## Years of education
    eduyrs_ij = zap_labels(eduyrs),
    z_eduyrs_ij = std(eduyrs_ij),
    # Watching TV, but not news on TV
    TV_not_news_ij = tvtot - tvpol,
    agea = zap_labels(agea),
    dfegcf = zap_labels(dfegcf),
    hincfel = zap_labels(hincfel),
    # anti-Muslim xenophobia
    z_anti_muslim_ij = std(almuslv),
    # Categorical variables
    cntry = as_factor(cntry) %>% fct_drop()) %>%
  select(pspwght, z_eduyrs_ij, z_anti_muslim_ij, TV_not_news_ij, cntry, agea, dfegcf, hincfel) %>%
  inner_join(., 
            read_dta("./../../assets/ESS7/Schlueter.dta") %>%
              mutate(mipex_j = mipex_j - mean(mipex_j, na.rm = TRUE)),
            by = "cntry") %>%
  inner_join(., read_dta("./../../assets/ESS7/ESSMD-2014-cntry_F1.dta") %>%
               mutate(
                 cntry = as_factor(cntry) %>% fct_drop(),
                 z_geothreat_j = case_when(
                   cntry == "AT" ~ 3, cntry == "BE" ~ 2, cntry == "CH" ~ 0, 
                   cntry == "CZ" ~ 3, cntry == "DE" ~ 3, cntry == "DK" ~ 1,
                   cntry == "EE" ~ 3, cntry == "ES" ~ 2, cntry == "FI" ~ 1, 
                   cntry == "FR" ~ 0, cntry == "GB" ~ 3, cntry == "HU" ~ 4,
                   cntry == "IE" ~ 1, cntry == "LT" ~ 2, cntry == "NL" ~ 0, 
                   cntry == "NO" ~ 0, cntry == "PL" ~ 2, cntry == "PT" ~ 0,
                   cntry == "SE" ~ 1, cntry == "SI" ~ 0) %>%
                   std()), # Z-standardize across countries (i.e., macro),
             by = "cntry")
library(lme4)

# Estimate the expanded model.
ris_mod <- lmer(z_anti_muslim_ij ~ agea + TV_not_news_ij + hincfel + z_eduyrs_ij*z_geothreat_j + c_unall_2011 + mipex_j + (1 + z_eduyrs_ij | cntry), data = ESS)
# Print the results
summary(ris_mod)
# Linear mixed model fit by REML ['lmerMod']
# Formula: z_anti_muslim_ij ~ agea + TV_not_news_ij + hincfel + z_eduyrs_ij *  
#     z_geothreat_j + c_unall_2011 + mipex_j + (1 + z_eduyrs_ij |      cntry)
#    Data: ESS
# 
# REML criterion at convergence: 70605
# 
# Scaled residuals: 
#    Min     1Q Median     3Q    Max 
# -3.588 -0.695  0.018  0.741  3.603 
# 
# Random effects:
#  Groups   Name        Variance Std.Dev. Corr
#  cntry    (Intercept) 0.06797  0.261        
#           z_eduyrs_ij 0.00336  0.058    0.76
#  Residual             0.73415  0.857        
# Number of obs: 27843, groups:  cntry, 20
# 
# Fixed effects:
#                            Estimate Std. Error t value
# (Intercept)               -5.46e-01   6.94e-02   -7.86
# agea                       6.22e-03   2.89e-04   21.52
# TV_not_news_ij             3.67e-02   3.05e-03   12.01
# hincfel                    1.07e-01   7.10e-03   15.10
# z_eduyrs_ij               -2.02e-01   1.44e-02  -14.06
# z_geothreat_j              1.64e-01   6.32e-02    2.60
# c_unall_2011              -5.86e-05   3.31e-05   -1.77
# mipex_j                   -1.14e-02   3.85e-03   -2.95
# z_eduyrs_ij:z_geothreat_j  4.46e-02   1.47e-02    3.03
# 
# Correlation of Fixed Effects:
#             (Intr) agea   TV_n__ hincfl z_dyr_ z_gth_ c__201 mipx_j
# agea        -0.207                                                 
# TV_nt_nws_j -0.091  0.004                                          
# hincfel     -0.188  0.014 -0.075                                   
# z_eduyrs_ij  0.520  0.098  0.065  0.079                            
# z_geothrt_j  0.069 -0.001 -0.014 -0.009 -0.001                     
# c_unll_2011 -0.447 -0.009  0.007  0.001  0.030 -0.147              
# mipex_j      0.053 -0.005  0.007  0.028  0.031  0.285 -0.124       
# z_dyrs_j:__ -0.011 -0.011  0.002  0.015  0.002  0.645  0.016 -0.018
# fit warnings:
# Some predictor variables are on very different scales: consider rescaling
# Predict U_0j and U_1j.
Blups <- ranef(ris_mod) %>% as_tibble()

# Visualize the Blups
## The random intercept
ggplot(data = Blups %>% filter(term == "(Intercept)"), aes(y = condval, x = reorder(grp, condval))) +
  geom_point() +
  theme_minimal()

## The random slope
ggplot(data = Blups %>% filter(term != "(Intercept)"), aes(y = condval, x = reorder(grp, condval))) +
  geom_point() +
  theme_minimal()

# 
# . * The micro d. use "./../../assets/ESS7/ESS7e02_2.dta", clear
# 
# . quietly do "./../../assets/ESS7/ESS7e02_2_formats_unicode.do"
# . ** Case-selection: No persons of immigrant origin
# 
# . keep if brncntr == 1 & mocntr == 1 & facntr == 1 & cntry != "IL"
# (9,510 observations deleted)
# 
# . ** Xenophobia
# 
# . gen anti_muslim_ij = almuslv,
# (1,139 missing values generated)
# 
# . *** z-standardize across micro units
# 
# . egen z_anti_muslim_ij = std(anti_muslim_ij) 
# (1139 missing values generated)
# 
# . label var z_anti_muslim_ij "Anti-Muslim Prejudice"
# 
# . ** Years of education, z-standardize across micro units
# 
# . egen z_eduyrs_ij = std(eduyrs)
# (254 missing values generated)
# 
# . label var z_eduyrs_ij "Education"
# 
# . ** Watching TV, but not news on TV
# 
# . gen TV_not_news_ij = tvtot - tvpol
# (1,323 missing values generated)
# 
# . ** reduce memory size and save for later use
# 
# . keep z_anti_muslim_ij z_eduyrs_ij cntry TV_not_news_ij agea dfegcf hincfel
# 
# . label var TV_not_news_ij "TV exposure"
# 
# . ** Create a temporary file
# 
# . tempfile micro_data 
# 
# . ** Save memory into the temporary file
# 
# . save "`micro_data'"  
# file /var/folders/2_/0vc2cx65781cm0qm9tw72fg80000gn/T//St34054.000001 saved
# 
# . * The macro data
# 
# . use c_unall_2011 cntry using "./../../assets/ESS7/ESSMD-2014-cntry_F1.dta", c
# > lear
# 
# . ** Add Geopolitical threat
# 
# . gen geothreat_j = .
# (40 missing values generated)
# 
# . replace geothreat_j = 3 if cntry == "AT"
# (1 real change made)
# 
# . replace geothreat_j = 2 if cntry == "BE"
# (1 real change made)
# 
# . replace geothreat_j = 0 if cntry == "CH"
# (1 real change made)
# 
# . replace geothreat_j = 3 if cntry == "CZ"
# (1 real change made)
# 
# . replace geothreat_j = 3 if cntry == "DE"
# (1 real change made)
# 
# . replace geothreat_j = 1 if cntry == "DK"
# (1 real change made)
# 
# . replace geothreat_j = 3 if cntry == "EE"
# (1 real change made)
# 
# . replace geothreat_j = 2 if cntry == "ES"
# (1 real change made)
# 
# . replace geothreat_j = 1 if cntry == "FI"
# (1 real change made)
# 
# . replace geothreat_j = 0 if cntry == "FR"
# (1 real change made)
# 
# . replace geothreat_j = 3 if cntry == "GB"
# (1 real change made)
# 
# . replace geothreat_j = 4 if cntry == "HU"
# (1 real change made)
# 
# . replace geothreat_j = 1 if cntry == "IE"
# (1 real change made)
# 
# . replace geothreat_j = 2 if cntry == "LT"
# (1 real change made)
# 
# . replace geothreat_j = 0 if cntry == "NL"
# (1 real change made)
# 
# . replace geothreat_j = 0 if cntry == "NO"
# (1 real change made)
# 
# . replace geothreat_j = 2 if cntry == "PL"
# (1 real change made)
# 
# . replace geothreat_j = 0 if cntry == "PT"
# (1 real change made)
# 
# . replace geothreat_j = 1 if cntry == "SE"
# (1 real change made)
# 
# . replace geothreat_j = 0 if cntry == "SI"
# (1 real change made)
# 
# . ** z-standardize across individuals (i.e. micro)
# 
# . egen z_geothreat_j = std(geothreat_j)
# (20 missing values generated)
# 
# . label var z_geothreat_j "Geopolitical threat"
# 
# . * Conjoin micro and macro data, keep only matched cases and generate no _merg
# > e variable
# 
# . merge 1:m cntry using "`micro_data'", keep(match) nogen
# 
#     Result                           # of obs.
#     -----------------------------------------
#     not matched                             0
#     matched                            30,675  
#     -----------------------------------------
# 
# . merge m:1 cntry using "./../../assets/ESS7/Schlueter.dta", keep(match) nogen
# 
#     Result                           # of obs.
#     -----------------------------------------
#     not matched                             0
#     matched                            30,675  
#     -----------------------------------------
# 
# . compress
#   variable geothreat_j was float now byte
#   variable TV_not_news_ij was float now byte
#   (184,050 bytes saved)
# 
# . 
# . *// Estimate the model
# 
# . mixed z_anti_muslim_ij agea dfegcf TV_not_news_ij hincfel c_unall_2011 mipex_
# > j  c.z_eduyrs_ij##c.z_geothreat_j || cntry: z_eduyrs_ij, reml covariance(unst
# > ructured)
# 
# Performing EM optimization: 
# 
# Performing gradient-based optimization: 
# 
# Iteration 0:   log restricted-likelihood = -34767.675  
# Iteration 1:   log restricted-likelihood = -34767.675  
# 
# Computing standard errors:
# 
# Mixed-effects REML regression                   Number of obs     =     27,786
# Group variable: cntry                           Number of groups  =         20
# 
#                                                 Obs per group:
#                                                               min =        793
#                                                               avg =    1,389.3
#                                                               max =      2,271
# 
#                                                 Wald chi2(9)      =    2256.87
# Log restricted-likelihood = -34767.675          Prob > chi2       =     0.0000
# 
# ------------------------------------------------------------------------------
# z_anti_mus~j |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
# -------------+----------------------------------------------------------------
#         agea |   .0045627   .0002896    15.76   0.000     .0039951    .0051303
#       dfegcf |   .2442154    .008013    30.48   0.000     .2285102    .2599206
# TV_not_new~j |   .0308441   .0030097    10.25   0.000     .0249451    .0367431
#      hincfel |   .1133556   .0069937    16.21   0.000     .0996482    .1270631
# c_unall_2011 |  -.0000517   .0000323    -1.60   0.109     -.000115    .0000116
#      mipex_j |  -.0105283   .0037466    -2.81   0.005    -.0178716    -.003185
#  z_eduyrs_ij |  -.1814173   .0129721   -13.99   0.000    -.2068422   -.1559925
# z_geothrea~j |   .1456279   .0587233     2.48   0.013     .0305323    .2607234
#              |
#           c. |
#  z_eduyrs_ij#|
#           c. |
# z_geothrea~j |   .0436775   .0132797     3.29   0.001     .0176498    .0697052
#              |
#        _cons |  -.4622759    .220328    -2.10   0.036    -.8941109   -.0304409
# ------------------------------------------------------------------------------
# 
# ------------------------------------------------------------------------------
#   Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
# -----------------------------+------------------------------------------------
# cntry: Unstructured          |
#                var(z_eduy~j) |    .002618    .001124      .0011286    .0060732
#                   var(_cons) |   .0580739   .0201089      .0294605    .1144778
#          cov(z_eduy~j,_cons) |    .008919   .0039147      .0012463    .0165917
# -----------------------------+------------------------------------------------
#                var(Residual) |   .7100198   .0060288      .6983013     .721935
# ------------------------------------------------------------------------------
# LR test vs. linear model: chi2(3) = 1720.42               Prob > chi2 = 0.0000
# 
# Note: LR test is conservative and provided only for reference.
# 
# . 
# . *// Predict U_0j and U_1j, 
# 
# . *// "*" ensures that both are predicted and called eblup1 and eblup2
# 
# . predict eblup*, reffects
# 
# . 
# . graph dot (mean) eblup1, over(cntry, sort(eblup1)) yline(0) vertical ytitle("
# > U{sub:0j}")
# 
# . graph dot (mean) eblup2, over(cntry, sort(eblup2)) yline(0) vertical ytitle("
# > U{sub:1j}")
# 
# .

3. Test whether the results for the context effects (DCE and CLI) are driven by outliers. + Continue to drop outliers until none remain; what do you learn from this?

library(influence.ME)

# Estimate -j models
one_out_models <- influence(model = ris_mod, group = "cntry")

# Calculate the DFBETAs and turn into tibble
DFBETAs <- dfbetas(one_out_models) %>% 
    data.frame() %>% 
    rownames_to_column() %>% 
    as_tibble() %>%
    select(rowname, z_eduyrs_ij, z_geothreat_j, z_eduyrs_ij.z_geothreat_j, c_unall_2011, mipex_j)

# Reshape to long
DFBETAs <- pivot_longer(
  DFBETAs, 
  cols = c("z_eduyrs_ij", "z_geothreat_j", "z_eduyrs_ij.z_geothreat_j", "c_unall_2011", "mipex_j"), 
  names_to = "Variable")

# Plot the results
ggplot(data = DFBETAs, 
       aes(y = value, x = Variable, label = rowname)) +
  geom_violin(color = "gray") +
  geom_text(position=position_jitter(width=0.2,height=0)) +
  geom_hline(yintercept = 2/sqrt(20), color = "#901A1E") +
  geom_hline(yintercept = -2/sqrt(20), color = "#901A1E") +
  theme_minimal() +
  labs(y = "DFBETA")

# Drop ES, PT, SI, SE, HU, and DE and re-iterate
# Estimate the expanded model.
ESS <- ESS %>% filter(cntry != "ES" & cntry != "PT" & cntry != "SI" & cntry != "SE" & cntry != "HU" & cntry != "DE")
ris_mod <- lmer(z_anti_muslim_ij ~ agea + TV_not_news_ij + hincfel + z_eduyrs_ij*z_geothreat_j + c_unall_2011 + mipex_j + (1 + z_eduyrs_ij | cntry), data = ESS)
one_out_models <- influence(model = ris_mod, group = "cntry")
DFBETAs <- dfbetas(one_out_models) %>% 
    data.frame() %>% 
    rownames_to_column() %>% 
    as_tibble() %>%
    select(rowname, z_eduyrs_ij, z_geothreat_j, z_eduyrs_ij.z_geothreat_j, c_unall_2011, mipex_j)
DFBETAs <- pivot_longer(
  DFBETAs, 
  cols = c("z_eduyrs_ij", "z_geothreat_j", "z_eduyrs_ij.z_geothreat_j", "c_unall_2011", "mipex_j"), 
  names_to = "Variable")
ggplot(data = DFBETAs, 
       aes(y = value, x = Variable, label = rowname)) +
  geom_violin(color = "gray") +
  geom_text(position=position_jitter(width=0.2,height=0)) +
  geom_hline(yintercept = 2/sqrt(20), color = "#901A1E") +
  geom_hline(yintercept = -2/sqrt(20), color = "#901A1E") +
  theme_minimal() +
  labs(y = "DFBETA")

# ... and so on.
# . quietly do "./../../assets/ESS7/12-Assumptions.do"
# . gen cli = z_eduyrs_ij*z_geothreat
# (254 missing values generated)
# 
# . xtmixed z_anti_muslim_ij agea dfegcf TV_not_news hincfel z_eduyrs_ij z_geothr
# > eat cli c_unall_2011 mipex_j || cntry: c.z_eduyrs_ij, reml cov(unstructured)
# 
# Performing EM optimization: 
# 
# Performing gradient-based optimization: 
# 
# Iteration 0:   log restricted-likelihood = -34767.675  
# Iteration 1:   log restricted-likelihood = -34767.675  
# 
# Computing standard errors:
# 
# Mixed-effects REML regression                   Number of obs     =     27,786
# Group variable: cntry                           Number of groups  =         20
# 
#                                                 Obs per group:
#                                                               min =        793
#                                                               avg =    1,389.3
#                                                               max =      2,271
# 
#                                                 Wald chi2(9)      =    2256.87
# Log restricted-likelihood = -34767.675          Prob > chi2       =     0.0000
# 
# ------------------------------------------------------------------------------
# z_anti_mus~j |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
# -------------+----------------------------------------------------------------
#         agea |   .0045627   .0002896    15.76   0.000     .0039951    .0051303
#       dfegcf |   .2442154    .008013    30.48   0.000     .2285102    .2599206
# TV_not_new~j |   .0308441   .0030097    10.25   0.000     .0249451    .0367431
#      hincfel |   .1133556   .0069937    16.21   0.000     .0996482    .1270631
#  z_eduyrs_ij |  -.1814173   .0129721   -13.99   0.000    -.2068422   -.1559925
# z_geothrea~j |   .1456279   .0587233     2.48   0.013     .0305323    .2607234
#          cli |   .0436775   .0132797     3.29   0.001     .0176498    .0697052
# c_unall_2011 |  -.0000517   .0000323    -1.60   0.109     -.000115    .0000116
#      mipex_j |  -.0105283   .0037466    -2.81   0.005    -.0178716    -.003185
#        _cons |  -.4622759    .220328    -2.10   0.036    -.8941109   -.0304409
# ------------------------------------------------------------------------------
# 
# ------------------------------------------------------------------------------
#   Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
# -----------------------------+------------------------------------------------
# cntry: Unstructured          |
#                 sd(z_eduy~j) |   .0511667   .0109837      .0335942     .077931
#                    sd(_cons) |   .2409852   .0417223      .1716407    .3383457
#         corr(z_eduy~j,_cons) |   .7233369   .1480193      .2969128    .9092341
# -----------------------------+------------------------------------------------
#                 sd(Residual) |   .8426267   .0035774      .8356443    .8496676
# ------------------------------------------------------------------------------
# LR test vs. linear model: chi2(3) = 1720.42               Prob > chi2 = 0.0000
# 
# Note: LR test is conservative and provided only for reference.
# 
# . mltcooksd, graph
# Level 2 variable is cntry 
#  
# Calculating DFBETAs for the fixed effects of 
#  agea dfegcf TV_not_news_ij hincfel z_eduyrs_ij z_geothreat_j cli c_unall_2011 
# > mipex_j _cons 
#  
# Cutoff value for DFBETAs is
# 0.4472
# Cutoff value for Cook's D is
# 0.2000
#  
# Level-two units with Cook's D above the cut off value:
# 
#   +-----------------+
#   | L2ID     CooksD |
#   |-----------------|
#   |   EE   .3964192 |
#   |   HU   .3348971 |
#   |   CZ   .3033558 |
#   |   SI   .2981909 |
#   |   SE   .2660684 |
#   |   ES   .2602893 |
#   |   AT   .2392094 |
#   |   GB   .2001689 |
#   +-----------------+
#    Legend: CooksD   = overall Cook's D
#  
#  
# Level-two units with DFBETAs above cut off value:
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   EE |   2.2458 |    -0.7546 |     0.1199 |     0.2684 |     0.1131 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |      0.1759  |  -0.1369  |     -0.2859  |     -0.0812  |    0.0545  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   HU |  -0.5872 |     0.2921 |     0.2651 |    -0.7327 |     0.2331 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |      0.4430  |   0.5986  |     -0.0146  |     -0.0120  |    0.1259  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   CZ |  -0.5949 |     0.0398 |    -0.7720 |    -0.7579 |     0.1935 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |      0.3941  |   0.4878  |     -0.0491  |     -0.0635  |    0.2587  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   SI |   0.2849 |     0.2465 |    -0.3057 |     0.4758 |    -0.4122 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.2126  |   0.5948  |     -0.2964  |     -0.8782  |    0.8122  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   SE |   0.0135 |    -0.5388 |    -0.1149 |     0.1936 |    -0.2320 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.1213  |   0.0895  |      0.3676  |     -1.0217  |    0.8773  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   ES |  -0.4445 |     0.5951 |     0.1993 |    -0.3616 |     0.0855 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.0231  |   0.0039  |      1.0784  |      0.1151  |   -0.2364  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   AT |  -0.8533 |     0.6570 |     1.2590 |     0.2114 |    -0.2159 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.3076  |  -0.3142  |      0.1021  |      0.0811  |   -0.2113  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   GB |   0.2895 |    -1.1397 |    -0.2751 |     0.4571 |    -0.2857 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.1905  |  -0.2728  |     -0.0600  |      0.0070  |    0.0168  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   DE |  -0.1474 |     0.3066 |     0.7197 |     0.7128 |    -0.2756 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.6150  |  -0.4225  |     -0.3034  |     -0.2020  |    0.0282  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   IE |  -0.3653 |     0.4817 |     0.4805 |     0.3614 |    -0.0035 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.0698  |   0.0336  |     -0.0463  |     -0.0943  |    0.0585  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   LT |  -0.2727 |    -0.2476 |    -0.6016 |    -0.6083 |     0.0870 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |      0.0808  |   0.0819  |      0.0490  |      0.1199  |   -0.0144  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   NL |  -0.8552 |    -0.6841 |     0.0511 |     0.1721 |     0.1064 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.0501  |  -0.2622  |      0.0326  |      0.0123  |    0.1013  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   FI |   0.9961 |     0.1951 |    -0.1075 |    -0.1407 |     0.1340 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |      0.0225  |  -0.0488  |     -0.1610  |      0.2944  |   -0.2884  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   PT |  -0.3694 |     0.0195 |    -0.0131 |     0.0394 |     0.2176 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.3151  |  -0.2847  |     -0.0412  |      0.7879  |   -0.6426  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   NO |   0.5079 |    -0.1035 |    -0.2158 |    -0.3759 |    -0.1080 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |      0.0623  |   0.1132  |     -0.0263  |      0.0070  |   -0.0085  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   BE |  -0.2013 |     0.6006 |    -0.1069 |     0.0601 |    -0.1105 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |      0.0793  |  -0.0597  |     -0.1213  |      0.2060  |   -0.2177  |
#   +---------------------------------------------------------------------+
# 
# . 
# . *// Drop ES, PT, SI, SE, HU, and DE and re-iterate
# 
# . keep if cntry != "ES" & cntry != "PT" & cntry != "SI" & cntry != "SE" & cntry
# >  != "HU" & cntry != "DE"
# (9,339 observations deleted)
# 
# . xtmixed z_anti_muslim_ij agea dfegcf TV_not_news hincfel c.z_eduyrs_ij z_geot
# > hreat cli c_unall_2011 mipex_j || cntry: c.z_eduyrs_ij, reml cov(unstructured
# > )
# 
# Performing EM optimization: 
# 
# Performing gradient-based optimization: 
# 
# Iteration 0:   log restricted-likelihood = -24576.126  
# Iteration 1:   log restricted-likelihood = -24576.126  
# 
# Computing standard errors:
# 
# Mixed-effects REML regression                   Number of obs     =     19,434
# Group variable: cntry                           Number of groups  =         14
# 
#                                                 Obs per group:
#                                                               min =        793
#                                                               avg =    1,388.1
#                                                               max =      1,808
# 
#                                                 Wald chi2(9)      =    1585.50
# Log restricted-likelihood = -24576.126          Prob > chi2       =     0.0000
# 
# ------------------------------------------------------------------------------
# z_anti_mus~j |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
# -------------+----------------------------------------------------------------
#         agea |   .0050587   .0003494    14.48   0.000     .0043739    .0057435
#       dfegcf |   .2341591   .0097007    24.14   0.000      .215146    .2531722
# TV_not_new~j |   .0278507   .0036099     7.72   0.000     .0207755    .0349259
#      hincfel |   .1106246   .0085089    13.00   0.000     .0939475    .1273018
#  z_eduyrs_ij |  -.1752573   .0137532   -12.74   0.000     -.202213   -.1483016
# z_geothrea~j |   .1891536   .0551246     3.43   0.001     .0811114    .2971958
#          cli |   .0337963   .0153586     2.20   0.028      .003694    .0638986
# c_unall_2011 |  -.0000746   .0000406    -1.84   0.066    -.0001542    4.98e-06
#      mipex_j |  -.0059702   .0039151    -1.52   0.127    -.0136438    .0017033
#        _cons |   -.671959   .2245674    -2.99   0.003    -1.112103   -.2318149
# ------------------------------------------------------------------------------
# 
# ------------------------------------------------------------------------------
#   Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
# -----------------------------+------------------------------------------------
# cntry: Unstructured          |
#                 sd(z_eduy~j) |   .0429892   .0126044      .0241985    .0763715
#                    sd(_cons) |   .1747167   .0394597      .1122254    .2720057
#         corr(z_eduy~j,_cons) |   .7426463   .1957359      .1005938    .9480118
# -----------------------------+------------------------------------------------
#                 sd(Residual) |   .8537358   .0043338      .8452838    .8622724
# ------------------------------------------------------------------------------
# LR test vs. linear model: chi2(3) = 497.85                Prob > chi2 = 0.0000
# 
# Note: LR test is conservative and provided only for reference.
# 
# . mltcooksd, graph
# Level 2 variable is cntry 
#  
# Calculating DFBETAs for the fixed effects of 
#  agea dfegcf TV_not_news_ij hincfel z_eduyrs_ij z_geothreat_j cli c_unall_2011 
# > mipex_j _cons 
#  
# Cutoff value for DFBETAs is
# 0.5345
# Cutoff value for Cook's D is
# 0.2857
#  
# Level-two units with Cook's D above the cut off value:
# 
#   +-----------------+
#   | L2ID     CooksD |
#   |-----------------|
#   |   CZ   .6261191 |
#   |   DK   .6001244 |
#   |   EE   .5212711 |
#   |   AT   .4927546 |
#   +-----------------+
#    Legend: CooksD   = overall Cook's D
#  
#  
# Level-two units with DFBETAs above cut off value:
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   CZ |  -0.7995 |     0.1149 |    -0.8046 |    -0.8869 |     0.4062 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |      0.8964  |   0.8778  |      0.0100  |      0.1111  |    0.1827  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   DK |   0.2377 |    -0.2162 |     0.3230 |     0.0671 |     0.4227 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.0833  |  -0.2098  |      0.1419  |     -0.7619  |    0.6041  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   EE |   2.5784 |    -0.8122 |     0.1850 |     0.3298 |     0.1306 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |      0.1935  |  -0.1580  |     -0.3232  |     -0.1144  |    0.0414  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   AT |  -1.0888 |     0.8302 |     1.5358 |     0.2569 |    -0.3089 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.7008  |  -0.4821  |      0.5515  |      0.5411  |   -0.8038  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   GB |   0.1707 |    -1.2322 |    -0.2431 |     0.6449 |    -0.4234 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.6737  |  -0.4061  |     -0.6746  |     -0.2819  |    0.3352  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   IE |  -0.5360 |     0.6558 |     0.6806 |     0.5045 |    -0.0634 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.1909  |   0.0777  |     -0.2662  |     -0.3437  |    0.2922  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   FI |   1.0706 |     0.3436 |    -0.0756 |    -0.1253 |     0.1094 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |      0.0928  |  -0.0088  |     -0.0958  |      0.5776  |   -0.6075  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   NL |  -1.1513 |    -0.7314 |     0.1271 |     0.2335 |     0.0369 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.1114  |  -0.2703  |      0.0219  |     -0.0426  |    0.2006  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   FR |  -0.1875 |     0.5702 |    -0.2805 |     0.4483 |    -0.0575 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.3577  |   0.1985  |      0.7567  |     -0.1619  |    0.0049  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   LT |  -0.4606 |    -0.1556 |    -0.6465 |    -0.7057 |     0.1227 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |      0.1049  |   0.1323  |      0.0052  |     -0.0564  |    0.2026  |
#   +---------------------------------------------------------------------+
# 
#   +---------------------------------------------------------------------+
#   | L2ID | DFB_agea | DFB_dfegcf | DFB_TV_n~j | DFB_hinc~l | DFB_z_ed~j |
#   |   BE |  -0.3130 |     0.7754 |    -0.0835 |     0.1014 |    -0.1761 |
#   |--------------------------------------------------------+------------|
#   |  DFB_z_ge~j  |  DFB_cli  |  DFB_c~2011  |  DFB_mipe~j  |  DFB_cons  |
#   |     -0.0607  |  -0.0869  |     -0.0078  |      0.0049  |   -0.0834  |
#   +---------------------------------------------------------------------+
# 
# . 
# . *// and so on
# 
# .