I have a variable PERWT from ipums usa microdata (which represents the weights for each observation). If PERWT in my sample data set is equal to 100, then this observation is representative of 100 observations in the population data set. Those weights need to be applied when running the Oaxaca-blinder decomposition. However my current code doesnt seem to work. I am open to hear your opinion or suggestion on how to do it.
current code that works without weights:
data1940_male <- data %>%
filter(race %in% c(0,1), EMPLOYMENT==1, merged_hours==40, INCWAGE!=0, BIRTHYR == 1940, gender==0,merged_race %in% c("White", "Black"))
data1940_male$gender <- factor(data1940_male$gender, levels = c(0, 1))
results1940_male<- oaxaca(formula=log(INCWAGE)~INDUSTRY+YREDUCATION+EXPERIENCE| race, data=
data1940_male, R=2, group.weights = 0)
trying to apply weights but unsuccessfully:
model_data <- data1940_male[, c("INCWAGE", "INDUSTRY", "YREDUCATION", "EXPERIENCE", "race",
"IPW","PERWT")]
data_group0 <- subset(model_data, race == 0)
data_group1 <- subset(model_data, race == 1)
model_data$ln_INCWAGE <- log(model_data$INCWAGE)
design <- svydesign(ids = ~1, data = model_data, weights = ~PERWT)
model1 <- svyglm(log_INCWAGE ~ INDUSTRY + YREDUCATION + EXPERIENCE, design = design, subset = race == 0)
model2 <- svyglm(log_INCWAGE ~ INDUSTRY + YREDUCATION + EXPERIENCE, design = design, subset = race == 1)
oaxaca_result <- oaxaca(log_INCWAGE ~ INDUSTRY + YREDUCATION + EXPERIENCE | race, data = model_data, weights = model_data$PERWT, reg.fun = svyglm, design = design, R=2,ind=c(0,1))