See this blog post and this Stata do-file.
Last active
December 22, 2015 02:49
-
-
Save briatte/6406111 to your computer and use it in GitHub Desktop.
The Israel survey weights in the European Social Survey need fixing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setwd("~/Documents/Data/ESS/IL_DWEIGHT/") | |
library(foreign) | |
library(reshape) | |
dw4 = read.spss("ESS4designweightIL.spss/ESS4IL_DWEIGHT.por", to.data.frame = TRUE) | |
head(dw4) | |
names(dw4) = tolower(names(dw4)) | |
essround = 4 | |
dw4 = cbind(essround, dw4) | |
dw5 = read.spss("ESS5designweightIL.spss/ESS5IL_DWEIGHT.por", to.data.frame = TRUE) | |
head(dw5) | |
names(dw5) = tolower(names(dw5)) | |
essround = 5 | |
dw5 = cbind(essround, dw5) | |
dw = rbind(dw4, dw5) | |
names(dw)[grepl("dweight", names(dw))] = "dweight_corrected" | |
dw$cntry = as.character(dw$cntry) | |
dw$cntry[dw$cntry == "Israel"] = "IL" | |
str(dw) | |
dw = sort_df(dw, vars = c("essround", "cntry", "idno")) | |
write.dta(dw, "dweight_corrected.dta") | |
load("../ESS1_5/ESS1-5_cumulative_e01_1.Rda") | |
i = subset(ess, cntry == "Israel" & essround > 3) | |
nrow(i) == nrow(dw) | |
all(dw$essround == i$essround) | |
library(ggplot2) | |
essround = factor(dw$essround) | |
qplot(x = dw$dweight_corrected, y = i$dweight, colour = essround, fill = essround) + | |
stat_smooth(method = "loess") + | |
stat_function(fun = identity, colour = "black") + | |
geom_rug() + | |
labs(y = "Original design weights\n", x = "\nCorrected design weights") + | |
theme_minimal() | |
qplot(data = dw, x = dweight_corrected, geom = "density", colour = "corrected") + | |
geom_density(data = i, aes(x = dweight), colour = "black") + facet_wrap(~ essround) + | |
scale_colour_discrete("") + | |
labs(x = "\nDesign weights") + | |
theme_minimal() | |
cor(dw$dweight_corrected[dw$essround==4], i$dweight[i$essround==4]) | |
cor(dw$dweight_corrected[dw$essround==5], i$dweight[i$essround==5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment