class: center, middle, inverse, title-slide # Applied Multilevel Analysis ## Session 4a: Random Intercept Replication 1 ### Merlin Schaeffer
Department of Sociology ### 2022-02-28 --- # Anti-Muslim prejudice .left-column[ <img src="https://media.salon.com/2019/05/anti-muslim-protestor.jpg" width="75%" style="display: block; margin: auto;" /> <img src="https://ichef.bbci.co.uk/images/ic/1200x675/p073wl75.jpg" width="75%" style="display: block; margin: auto;" /> <img src="https://www.themorningchronicle.in/wp-content/uploads/2019/07/A-representational-image.jpeg" width="75%" style="display: block; margin: auto;" /> ] .right-column[ .center[**10-minute break out room session**] 1. What are the main research questions of the article? 2. Why can't they use pooled OLS for their analyses? <br> <img src="media/Schlueter1.png" width="90%" style="display: block; margin: auto;" /> .center[.backgrnote[*Source*: Schlueter, Masso, and Davidov (2019)]] ] ??? --- class: inverse # 20-minute exercise <img src="media/Schlueter2.png" width="70%" style="display: block; margin: auto;" /> .center[.backgrnote[.white[*Source*: Schlueter, Masso, and Davidov (2019, p. 8)]]] .center[.content-box-green[ We have access to the same data; **so let's replicate this!** .font90[How does the Stata/R code look like that allows you to estimate that ICC?] ]] --- class: inverse .panelset[ .panel[.panel-name[R data prep] .font90[ ```r library(tidyverse) # Data manipulation library(haven) # Read Stata dta files library(essurvey) # API to ESS # ESS <- import_rounds(rounds = 7, ess_email = YOUR_EMAIL) %>% ESS <- read_dta("./../../assets/ESS7/ESS7e02_2.dta") %>% ## <- recode_missings() %>% # redefine some variables as factors mutate( brncntr = as_factor(brncntr), ctzcntr = as_factor(ctzcntr), rlgblg = as_factor(rlgblg), rlgdnm = as_factor(rlgdnm), uempla = as_factor(uempla), rlgdnm = case_when( # Add atheists to the religion variable rlgblg == "No" ~ "Atheist", rlgdnm=="Not applicable"|rlgdnm=="Refusal"|rlgdnm=="No answer" ~ as.character(NA), TRUE ~ as.character(rlgdnm) ) %>% factor(), gndr = as_factor(gndr), gndr = case_when( gndr == "No answer" ~ as.character(NA), TRUE ~ as.character(gndr) ) %>% factor() ) %>% zap_labels() %>% # keep only those born and with citizenship in country of interview, # non-Muslim and drop Israel filter(brncntr == "Yes" & ctzcntr == "Yes" & rlgdnm != "Islamic" & cntry != "IL") %>% # Keep only the following variables select(cntry, almuslv, agea, gndr, edulvlb, uempla, hincfel, rlgdnm, dfegcf, tvtot, tvpol) %>% drop_na() # Casewise deletion ``` ]] .panel[.panel-name[Stata data prep] ```stata use "./../../assets/ESS7/ESS7e02_2.dta", clear // Keep only those born in and with citizenship of country of interview, // Non-Muslims, and drop Israel keep if brncntr == 1 & ctzcntr == 1 & rlgdnm != 6 & cntry != "IL" // Use the following variables for the analysis keep cntry almuslv agea gndr edulvlb uempla hincfel rlgblg rlgdnm dfegcf tvtot tvpol // Add atheists to the religion variable replace rlgdnm = 0 if rlgblg == 2 // Listwise deletion of missing values foreach var in cntry almuslv agea gndr edulvlb uempla hincfel /// rlgdnm dfegcf tvtot tvpol { drop if missing(`var') } ``` ] .panel[.panel-name[R estimation] .right-column[ ```r library(lme4) # Multilevel modeling # Random effects ANOVA (i.e., empty/null random intercept model) ri_mod0 <- lmer(almuslv ~ (1 | cntry), data = ESS) summary(ri_mod0) # Linear mixed model fit by REML ['lmerMod'] # Formula: almuslv ~ (1 | cntry) # Data: ESS # # REML criterion at convergence: 78146 # # Scaled residuals: # Min 1Q Median 3Q Max # -2.7908 -0.6972 0.0459 0.6335 2.4535 # # Random effects: # Groups Name Variance Std.Dev. # cntry (Intercept) 0.163 0.404 # Residual 0.779 0.883 # Number of obs: 30144, groups: cntry, 20 # # Fixed effects: # Estimate Std. Error t value # (Intercept) 2.6897 0.0905 29.7 ``` ] .left-column[ `\begin{align} \hat{\rho_{\text{I}}} &= \frac{\hat{\tau_0}^2}{\hat{\tau_0}^2 + \hat{\sigma}^2} \\ & = \frac{0.163}{0.163 + 0.779} \\ &= 17.334 \%. \end{align}` ]] .panel[.panel-name[Stata estimation] .left-column[ `\begin{align} \hat{\rho_{\text{I}}} &= \frac{\hat{\tau_0}^2}{\hat{\tau_0}^2 + \hat{\sigma}^2} \\ & = \frac{0.163}{0.163 + 0.779} \\ &= 17.334 \%. \end{align}` ] .font90[ ``` . quietly do "./../../assets/ESS7/7-RI-Replication-1.do" . *// Random effects ANOVA (i.e., empty/null random intercept model) . mixed almuslv || cntry: , reml noheader Performing EM optimization: Performing gradient-based optimization: Iteration 0: log restricted-likelihood = -39072.966 Iteration 1: log restricted-likelihood = -39072.966 (backed up) Computing standard errors: ------------------------------------------------------------------------------ almuslv | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | 2.689677 .0905415 29.71 0.000 2.512218 2.867135 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ cntry: Identity | var(_cons) | .163411 .0531838 .0863474 .3092528 -----------------------------+------------------------------------------------ var(Residual) | .7793264 .0063501 .7669793 .7918722 ------------------------------------------------------------------------------ LR test vs. linear model: chibar2(01) = 5611.79 Prob >= chibar2 = 0.0000 . ``` ]]] --- layout: false layout: true # Anti-Muslim prejudice .push-left[ <img src="media/Schlueter5.png" width="100%" style="display: block; margin: auto;" /> .center[.backgrnote[*Source*: Schlueter, Masso, and Davidov (2019)]] ] --- .push-right[ <img src="media/Schlueter3.png" width="100%" style="display: block; margin: auto;" /> .center[.backgrnote[*Source*: Schlueter, Masso, and Davidov (2019)]] .center[.content-box-green[ How can you see that from Table 1?]] ] -- .center[ `\(\rho_{\text{I}}(Y_{ij}|X) = \frac{\tau_0^2}{\tau_0^2 + \sigma^2} = \frac{0.103}{0.103 + 0.692} =\)` 0.13 ] --- .push-right[ .center[.content-box-green[ What else do we learn about the raised research questions?]] ] --- layout:false # References .font80[ Schlueter, E., A. Masso, and E. Davidov (2019). "What Factors Explain Anti-Muslim Prejudice? An Assessment of the Effects of Muslim Population Size, Institutional Characteristics and Immigration-Related Media Claims". In: _Journal of Ethnic and Migration Studies_ 0.0, pp. 1-16. ]