1. Do Danes with native-born parents prefer higher- over lower-skilled immigrants? Analyze the experiment using OLS regression without any additional control variables. Make sure to combine treatment conditions for higher/less-skilled immigrants from within and outside of Europe.
library(tidyverse) # Add the tidyverse package to my current library.
library(haven) # Handle labelled data.
library(essurvey) # Add ESS API package.
library(estimatr) # For regression with robust SE
library(texreg) # For nicely-formatted regression tables
# Import the ESS round 7 data via the API
ESS <- import_country(
country = "Denmark",
rounds = 7,
ess_email = YOUR_EMAIL) %>%
recode_missings() %>%
# Keep only respondents with Danish-born parents.
filter(brncntr == 1 & mocntr == 1 & facntr == 1) %>%
mutate(
# The experiment
## Outcome
outcome = case_when(
admaimg == 1 ~ zap_labels(alpfpe),
admaimg == 2 ~ zap_labels(alpfpne),
admaimg == 3 ~ zap_labels(allbpe),
admaimg == 4 ~ zap_labels(allbpne),
TRUE ~ as.numeric(NA)),
## Treatment
frame = case_when(
admaimg < 3 ~ "Professional",
admaimg > 2 & admaimg < 5 ~ "Unskilled laborer",
TRUE ~ as.character(NA)) %>% factor())
# Weighted OLS with robust SE
ols1 <- lm_robust(data = ESS, formula = outcome ~ frame, weight = pspwght)
screenreg(ols1, include.ci = FALSE, digits = 3)
#
# ====================================
# Model 1
# ------------------------------------
# (Intercept) 2.061 ***
# (0.033)
# frameUnskilled laborer 0.578 ***
# (0.049)
# ------------------------------------
# R^2 0.111
# Adj. R^2 0.110
# Num. obs. 1290
# RMSE 0.819
# ====================================
# *** p < 0.001; ** p < 0.01; * p < 0.05
# . use "./../../assets/ESS7/ESS7DK.dta", clear
#
# . quietly do "./../../assets/ESS7/ESS7e02_2_formats_unicode.do"
# . keep if brncntr == 1 & mocntr == 1 & facntr == 1
# (198 observations deleted)
#
# . * The experiment
#
# . ** The outcome
#
# . gen outcome = alpfpe if admaimg == 1
# (955 missing values generated)
#
# . replace outcome = alpfpne if admaimg == 2
# (314 real changes made, 3 to missing)
#
# . replace outcome = allbpe if admaimg == 3
# (314 real changes made, 3 to missing)
#
# . replace outcome = allbpne if admaimg == 4
# (324 real changes made, 5 to missing)
#
# .
# . ** The treatment
#
# . gen frame = 0 if admaimg < 3
# (639 missing values generated)
#
# . replace frame = 1 if admaimg > 2 & admaimg < 5
# (638 real changes made)
#
# . lab def frame 0 "Professional" 1 "Unskilled laborer"
#
# . lab val frame fame
#
# .
# . * Weighted OLS with robust SE
#
# . reg outcome i.frame [w = pspwght], rob
# (analytic weights assumed)
# (sum of wgt is 1,284.76997571329)
#
# Linear regression Number of obs = 1,290
# F(1, 1288) = 137.27
# Prob > F = 0.0000
# R-squared = 0.1106
# Root MSE = .8205
#
# ------------------------------------------------------------------------------
# | Robust
# outcome | Coef. Std. Err. t P>|t| [95% Conf. Interval]
# -------------+----------------------------------------------------------------
# 1.frame | .5782535 .0493542 11.72 0.000 .48143 .675077
# _cons | 2.060796 .0326044 63.21 0.000 1.996832 2.124759
# ------------------------------------------------------------------------------
#
# .
On a scale from 1 “Allow many” to 4 “Allow none”, unskilled immigrants are units less wanted.
2. Does the competition model hold in Denmark? Use respondents’ years of education and household income decile as continuous moderator variables. Are those with more education and higher income less xenophobic against less- compared to higher-skilled immigrants?
ESS <- ESS %>%
mutate(
eduyrs = zap_labels(eduyrs),
hinctnta = zap_labels(hinctnta))
# Weighted OLS with robust SE
ols2 <- lm_robust(data = ESS, formula = outcome ~ frame*eduyrs + frame*hinctnta, weight = pspwght)
screenreg(ols2, include.ci = FALSE, digits = 3)
#
# =============================================
# Model 1
# ---------------------------------------------
# (Intercept) 2.441 ***
# (0.110)
# frameUnskilled laborer 0.604 ***
# (0.159)
# eduyrs -0.017 *
# (0.007)
# hinctnta -0.032 **
# (0.012)
# frameUnskilled laborer:eduyrs -0.017
# (0.011)
# frameUnskilled laborer:hinctnta 0.030
# (0.018)
# ---------------------------------------------
# R^2 0.137
# Adj. R^2 0.134
# Num. obs. 1142
# RMSE 0.800
# =============================================
# *** p < 0.001; ** p < 0.01; * p < 0.05
# . use "./../../assets/ESS7/ESS7DK.dta", clear
#
# . quietly do "./../../assets/ESS7/ESS7e02_2_formats_unicode.do"
# . keep if brncntr == 1 & mocntr == 1 & facntr == 1
# (198 observations deleted)
#
# . * The experiment
#
# . ** The outcome
#
# . gen outcome = alpfpe if admaimg == 1
# (955 missing values generated)
#
# . replace outcome = alpfpne if admaimg == 2
# (314 real changes made, 3 to missing)
#
# . replace outcome = allbpe if admaimg == 3
# (314 real changes made, 3 to missing)
#
# . replace outcome = allbpne if admaimg == 4
# (324 real changes made, 5 to missing)
#
# .
# . ** The treatment
#
# . gen frame = 0 if admaimg < 3
# (639 missing values generated)
#
# . replace frame = 1 if admaimg > 2 & admaimg < 5
# (638 real changes made)
#
# . lab def frame 0 "Professional" 1 "Unskilled laborer"
#
# . lab val frame fame
#
# .
# . * Weighted OLS with robust SE
#
# . reg outcome i.frame##c.eduyrs i.frame##c.hinctnta [w = pspwght], rob
# (analytic weights assumed)
# (sum of wgt is 1,114.11428143459)
#
# Linear regression Number of obs = 1,142
# F(5, 1136) = 32.04
# Prob > F = 0.0000
# R-squared = 0.1374
# Root MSE = .81019
#
# ------------------------------------------------------------------------------
# | Robust
# outcome | Coef. Std. Err. t P>|t| [95% Conf. Interval]
# -------------+----------------------------------------------------------------
# 1.frame | .6042367 .1587562 3.81 0.000 .2927485 .915725
# eduyrs | -.0168778 .0073337 -2.30 0.022 -.031267 -.0024887
# |
# frame#|
# c.eduyrs |
# 1 | -.0165558 .0106373 -1.56 0.120 -.0374269 .0043152
# |
# hinctnta | -.0320516 .0121756 -2.63 0.009 -.0559409 -.0081623
# |
# frame#|
# c.hinctnta |
# 1 | .0297963 .0183895 1.62 0.105 -.0062848 .0658775
# |
# _cons | 2.440592 .1092046 22.35 0.000 2.226327 2.654857
# ------------------------------------------------------------------------------
#
# .
3. Does the reciprocity model hold in Denmark? Use question D8 to test the idea that perceived lack in reciprocity explains why less-skilled immigrants face more xenophobia. Control for education and income, but do not interact those variables with the experimental treatment.
ESS <- ESS %>%
# Turn scale and make it numeric
mutate(imbleco = max(imbleco, na.rm = TRUE) - zap_labels(imbleco))
# Weighted OLS with robust SE
ols3 <- lm_robust(data = ESS, formula = outcome ~ frame*imbleco + eduyrs + hinctnta, weight = pspwght)
screenreg(ols3, include.ci = FALSE, digits = 3)
#
# ============================================
# Model 1
# --------------------------------------------
# (Intercept) 1.675 ***
# (0.132)
# frameUnskilled laborer 0.450 **
# (0.146)
# imbleco 0.121 ***
# (0.019)
# eduyrs -0.019 ***
# (0.005)
# hinctnta -0.007
# (0.009)
# frameUnskilled laborer:imbleco 0.017
# (0.026)
# --------------------------------------------
# R^2 0.219
# Adj. R^2 0.216
# Num. obs. 1129
# RMSE 0.758
# ============================================
# *** p < 0.001; ** p < 0.01; * p < 0.05
# . use "./../../assets/ESS7/ESS7DK.dta", clear
#
# . quietly do "./../../assets/ESS7/ESS7e02_2_formats_unicode.do"
# . keep if brncntr == 1 & mocntr == 1 & facntr == 1
# (198 observations deleted)
#
# . * The experiment
#
# . ** The outcome
#
# . gen outcome = alpfpe if admaimg == 1
# (955 missing values generated)
#
# . replace outcome = alpfpne if admaimg == 2
# (314 real changes made, 3 to missing)
#
# . replace outcome = allbpe if admaimg == 3
# (314 real changes made, 3 to missing)
#
# . replace outcome = allbpne if admaimg == 4
# (324 real changes made, 5 to missing)
#
# .
# . ** The treatment
#
# . gen frame = 0 if admaimg < 3
# (639 missing values generated)
#
# . replace frame = 1 if admaimg > 2 & admaimg < 5
# (638 real changes made)
#
# . lab def frame 0 "Professional" 1 "Unskilled laborer"
#
# . lab val frame fame
#
# .
# . * Turn D8 scale around
#
# . sum imbleco
#
# Variable | Obs Mean Std. Dev. Min Max
# -------------+---------------------------------------------------------
# imbleco | 1,280 4.614844 2.015405 0 10
#
# . replace imbleco = `r(max)' - imbleco
# (933 real changes made, 24 to missing)
#
# .
# . * Weighted OLS with robust SE
#
# . reg outcome i.frame##c.imbleco eduyrs hinctnta [w = pspwght], rob
# (analytic weights assumed)
# (sum of wgt is 1,100.05033984448)
#
# Linear regression Number of obs = 1,129
# F(5, 1123) = 52.36
# Prob > F = 0.0000
# R-squared = 0.2191
# Root MSE = .76807
#
# ------------------------------------------------------------------------------
# | Robust
# outcome | Coef. Std. Err. t P>|t| [95% Conf. Interval]
# -------------+----------------------------------------------------------------
# 1.frame | .4498804 .1461127 3.08 0.002 .1631957 .7365651
# imbleco | .1213515 .0184817 6.57 0.000 .0850889 .157614
# |
# frame#|
# c.imbleco |
# 1 | .0171394 .025701 0.67 0.505 -.033288 .0675668
# |
# eduyrs | -.0193705 .0052121 -3.72 0.000 -.029597 -.009144
# hinctnta | -.0070473 .0088709 -0.79 0.427 -.0244526 .0103581
# _cons | 1.674825 .1316662 12.72 0.000 1.416485 1.933164
# ------------------------------------------------------------------------------
#
# .
4. Full model. Operationalize all the control variables considered in the original article and estimate the full model (i.e., all predictors and interaction terms). Are any results altered?
ESS <- ESS %>%
mutate(
# Turn scales and make them numeric
imwbcnt = max(imwbcnt, na.rm = TRUE) - zap_labels(imwbcnt),
imueclt = max(imueclt, na.rm = TRUE) - zap_labels(imueclt),
prtvtcdk = as_factor(prtvtcdk),
party = case_when(
prtvtcdk == "Socialdemokraterne - the Danish social democrats" ~ "S",
prtvtcdk == "Dansk Folkeparti - Danish peoples party" ~ "DF",
TRUE ~ "Other"
) %>% fct_infreq())
# Weighted OLS with robust SE
ols4 <- lm_robust(data = ESS, formula = outcome ~ frame*imbleco + frame*eduyrs + frame*hinctnta +
agea + factor(gndr) + party + imwbcnt + imueclt, weight = pspwght)
screenreg(ols4, include.ci = FALSE, digits = 3)
#
# =============================================
# Model 1
# ---------------------------------------------
# (Intercept) 1.268 ***
# (0.170)
# frameUnskilled laborer 0.369
# (0.207)
# imbleco 0.040 *
# (0.018)
# eduyrs 0.001
# (0.006)
# hinctnta -0.020
# (0.011)
# agea -0.002
# (0.001)
# factor(gndr)2 -0.016
# (0.046)
# partyS 0.225 ***
# (0.061)
# partyDF 0.186 *
# (0.080)
# imwbcnt 0.080 ***
# (0.018)
# imueclt 0.080 ***
# (0.015)
# frameUnskilled laborer:imbleco 0.018
# (0.024)
# frameUnskilled laborer:eduyrs -0.016
# (0.009)
# frameUnskilled laborer:hinctnta 0.041 *
# (0.016)
# ---------------------------------------------
# R^2 0.364
# Adj. R^2 0.357
# Num. obs. 1121
# RMSE 0.686
# =============================================
# *** p < 0.001; ** p < 0.01; * p < 0.05
# . use "./../../assets/ESS7/ESS7DK.dta", clear
#
# . quietly do "./../../assets/ESS7/ESS7e02_2_formats_unicode.do"
# . keep if brncntr == 1 & mocntr == 1 & facntr == 1
# (198 observations deleted)
#
# . * The experiment
#
# . ** The outcome
#
# . gen outcome = alpfpe if admaimg == 1
# (955 missing values generated)
#
# . replace outcome = alpfpne if admaimg == 2
# (314 real changes made, 3 to missing)
#
# . replace outcome = allbpe if admaimg == 3
# (314 real changes made, 3 to missing)
#
# . replace outcome = allbpne if admaimg == 4
# (324 real changes made, 5 to missing)
#
# .
# . ** The treatment
#
# . gen frame = 0 if admaimg < 3
# (639 missing values generated)
#
# . replace frame = 1 if admaimg > 2 & admaimg < 5
# (638 real changes made)
#
# . lab def frame 0 "Professional" 1 "Unskilled laborer"
#
# . lab val frame fame
#
# .
# . * Turn scales around
#
# . foreach var in imbleco imwbcnt imueclt {
# 2. sum `var'
# 3. replace `var' = `r(max)' - `var'
# 4. }
#
# Variable | Obs Mean Std. Dev. Min Max
# -------------+---------------------------------------------------------
# imbleco | 1,280 4.614844 2.015405 0 10
# (933 real changes made, 24 to missing)
#
# Variable | Obs Mean Std. Dev. Min Max
# -------------+---------------------------------------------------------
# imwbcnt | 1,292 5.610681 2.176769 0 10
# (948 real changes made, 12 to missing)
#
# Variable | Obs Mean Std. Dev. Min Max
# -------------+---------------------------------------------------------
# imueclt | 1,290 5.735659 2.495436 0 10
# (1,061 real changes made, 14 to missing)
#
# .
# . * Generate a recoded party variable
#
# . gen party = prtvtcdk
# (230 missing values generated)
#
# . recode party (1 = 2) (5 = 3) (else = 1)
# (party: 1304 changes made)
#
# . lab def party 1 "Other" 2 "S" 3 "DF"
#
# . lab val party party
#
# .
# . * Weighted OLS with robust SE
#
# . reg outcome i.frame##c.imbleco i.frame##c.eduyrs i.frame##c.hinctnta agea i.g
# > ndr i.party imwbcnt imueclt [w = pspwght], rob
# (analytic weights assumed)
# (sum of wgt is 1,090.33195701591)
#
# Linear regression Number of obs = 1,121
# F(13, 1107) = 48.89
# Prob > F = 0.0000
# R-squared = 0.3642
# Root MSE = .69583
#
# ------------------------------------------------------------------------------
# | Robust
# outcome | Coef. Std. Err. t P>|t| [95% Conf. Interval]
# -------------+----------------------------------------------------------------
# 1.frame | .3694039 .2063253 1.79 0.074 -.0354289 .7742367
# imbleco | .0404425 .0179693 2.25 0.025 .0051848 .0757002
# |
# frame#|
# c.imbleco |
# 1 | .018386 .0237405 0.77 0.439 -.0281953 .0649674
# |
# eduyrs | .0006232 .0063946 0.10 0.922 -.0119238 .0131702
# |
# frame#|
# c.eduyrs |
# 1 | -.0158921 .0092914 -1.71 0.087 -.0341229 .0023387
# |
# hinctnta | -.0200279 .0107677 -1.86 0.063 -.0411552 .0010994
# |
# frame#|
# c.hinctnta |
# 1 | .0412724 .0161881 2.55 0.011 .0095096 .0730351
# |
# agea | -.0017205 .0013464 -1.28 0.202 -.0043623 .0009213
# |
# gndr |
# Female | -.0155801 .0457107 -0.34 0.733 -.1052694 .0741093
# |
# party |
# S | .2252209 .0604314 3.73 0.000 .1066479 .3437939
# DF | .1864426 .0795123 2.34 0.019 .0304308 .3424544
# |
# imwbcnt | .0800002 .0175512 4.56 0.000 .0455629 .1144375
# imueclt | .0804082 .014448 5.57 0.000 .0520596 .1087568
# _cons | 1.268295 .1697356 7.47 0.000 .9352556 1.601335
# ------------------------------------------------------------------------------
#
# .