Monday, November 9, 2015

Oaxaca with R

setwd ("F:/Dropbox/R/")
#install.packages("oaxaca")
require("oaxaca")

# set random seed
set.seed(08544)
# load data set of Hispanic workers in Chicago
data("chicago")
# perform Blinder-Oaxaca Decomposition:
# explain differences in log real wages across native and foreign-born groups
results <- oaxaca(ln.real.wage ~ age + female + LTHS + some.college +
college + advanced.degree | foreign.born,
data = chicago, R = 50)
results$n
results$y
results$threefold$overall
# plot results of the threefold decomposition, variable-by-variable
# only include educational variables
# decomposition components along the left side of the plot
plot(results, component.left = TRUE,
     variables = c("LTHS", "some.college", "college", "advanced.degree"),
     variable.labels = c("LTHS" = "less than high school",
      "some.college" = "some college",
       "advanced.degree" = "advanced degree"))
plot(results, components = c("endowments","coefficients"))
# plot results of the twofold decomposition (overall results)
# equal weight for Group A and B in reference coefficient determinantion (weight = 0.5)
# unexplained portion split into A and B
plot(results, decomposition = "twofold", type = "overall",
     weight = 0.5, unexplained.split = TRUE,
     bar.color = c("limegreen", "hotpink", "steelblue"))

results$twofold$overall
plot(results, decomposition = "twofold", weight = -1)
plot(results, decomposition = "twofold", weight = -1,
      unexplained.split = TRUE, components = c("unexplained A",
      "unexplained B"), component.labels = c("unexplained A" =
      "In Favor of Natives", "unexplained B" = "Against the Foreign-Born"),
      variables = c("age", "female", "college"), variable.labels = c("age" =
      "Years of Age", "female" = "Female", "college" = "College Education"))

plot(results, decomposition = "twofold", weight = -1,
    unexplained.split = TRUE, components = c("unexplained A",
    "unexplained B"), component.labels = c("unexplained A" =
    "In Favor of Natives", "unexplained B" = "Against the Foreign-Born"),
    component.left = TRUE, variables = c("age","female","college"),
    variable.labels = c("age" = "Years of Age", "female" = "Female",
    "college" = "College Education"))

#Specifc numerical values of the point estimates of the unexplained discrimination components
#can, of course, be obtained directly from the "oaxaca"-class object:
variables <- c("age", "female", "college")
columns <- c("weight", "coef(unexplained A)", "coef(unexplained B)")
results$twofold$variables[[5]][variables, columns]

No comments:

Post a Comment