# NOT RUN {
# Subset of Immigration Choice Conjoint Experiment Data from Hainmueller et. al. (2014).
data("immigrationdata")
form = formula("Y ~ FeatEd + FeatGender + FeatCountry + FeatReason + FeatJob +
FeatExp + FeatPlans + FeatTrips + FeatLang + ppage + ppeducat + ppethm + ppgender")
left = colnames(immigrationdata)[1:9]
right = colnames(immigrationdata)[10:18]
# }
# NOT RUN {
# Testing whether edcuation matters for immigration preferences
education_test = CRT_pval(formula = form, data = immigrationdata, X = "FeatEd",
left = left, right = right, non_factor = "ppage", B = 100, analysis = 2)
education_test$p_val
# }
# NOT RUN {
# Testing whether job matters for immigration preferences
constraint_randomization = list() # (Job has dependent randomization scheme)
constraint_randomization[["FeatJob"]] = c("Financial analyst","Computer programmer",
"Research scientist","Doctor")
constraint_randomization[["FeatEd"]] = c("Equivalent to completing two years of
college in the US", "Equivalent to completing a graduate degree in the US",
"Equivalent to completing a college degree in the US")
# }
# NOT RUN {
job_test = CRT_pval(formula = form, data = immigrationdata, X = "FeatJob",
left = left, right = right, design = "Constrained Uniform",
constraint_randomization = constraint_randomization, non_factor = "ppage", B = 100)
job_test$p_val
# }
# NOT RUN {
# Testing whether Mexican and European immigrants are treated indistinguishably
country_data = immigrationdata
country_data$FeatCountry = as.character(country_data$FeatCountry)
country_data$FeatCountry_2 = as.character(country_data$FeatCountry_2)
country_data$FeatCountry[country_data$FeatCountry %in% c("Germany", "France",
"Poland")] = "Europe"
country_data$FeatCountry_2[country_data$FeatCountry_2 %in% c("Germany", "France",
"Poland")] = "Europe"
country_data$FeatCountry = factor(country_data$FeatCountry)
country_data$FeatCountry_2 = factor(country_data$FeatCountry_2)
# }
# NOT RUN {
mexico_Europe_test = CRT_pval(formula = form, data = country_data, X = "FeatCountry",
left = left, right = right, design = "Nonuniform",
in_levs = c("Mexico", "Europe"), p = c(0.25, 0.75), non_factor = "ppage", B = 100,
analysis = 2)
# }
# NOT RUN {
# example case with supplying own resamples
resample_Mexico_Europe = function(country_data) {
resamples_1 = sample(c("Mexico", "Europe"), size = nrow(country_data),
replace = TRUE, p = c(0.25, 0.75))
resamples_2 = sample(c("Mexico", "Europe"), size = nrow(country_data),
replace = TRUE, p = c(0.25, 0.75))
resample_df = data.frame(resamples_1, resamples_2)
return(resample_df)
}
own_resamples = list()
for (i in 1:100) {
own_resamples[[i]] = resample_Mexico_Europe(country_data)
}
mexico_Europe_test = CRT_pval(formula = form, data = country_data, X = "FeatCountry",
left = left, right = right, design = "Manual",
in_levs = c("Mexico", "Europe"), supplyown_resamples = own_resamples,
non_factor = "ppage", B = 100, analysis = 2)
# }
# NOT RUN {
# example case with forcing with candidate gender
# }
# NOT RUN {
mexico_Europe_test_force = CRT_pval(formula = form, data = country_data,
X = "FeatCountry", left = left, right = right, design = "Nonuniform",
in_levs = c("Mexico", "Europe"), p = c(0.25, 0.75), forced_var = "FeatGender",
non_factor = "ppage", B = 100)
# }
Run the code above in your browser using DataLab