R中的瓦哈卡分解 [英] Oaxaca Decomposition in R

查看:195
本文介绍了R中的瓦哈卡分解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在R中进行瓦哈卡分解.我相信,劳动经济学可以将解释的方差与无法解释的方差区分开.我无法在R中找到合适的解决方案,而我不太愿意自己创建一个(我可能会搞乱它).

I would like to make a Oaxaca Decomposition in R. It is used in e.g. labor economics to distinguish explained variance versus unexplained variance, I believe. I have not been able to find a suitable solution in R, and I am rather reluctant to create one myself (I would probably mess it up).

无论如何,这里简要说明了该过程:

Anyway, the procedure is briefly explained here:

http://en.wikipedia.org/wiki/Ronald_Oaxaca

Stata拥有一个相当不错的软件包,但是Stata对我来说并不容易.

Stata is blessed with a rather good package for this, but Stata is not easily available to me.

www.stata.com/meeting/5german/SINNING_stata_presentation.pdf

请注意:我还在R-help上发布了一条消息,但没有得到回复.我希望也可以在此列表上发帖.

Please note: I have also posted a message on R-help but it has gotten no reply. I hope it is okay to post on this list as well.

预先感谢, 拉斯穆斯

我做了以下功能,这似乎产生错误的答案(敦促).我尝试按照上面的Stata链接进行操作,但效果不理想:)

I have made the following function, which seems to yield wrong answers (urgh). I tried to follow the Stata link above but it did not work out as I hoped :)

oaxaca <- function (fsex,frace1,frace2) {
  ## First we make regresions
  data1 <- subset(l2,sex==fsex & race==frace1)
  data2 <- subset(l2,sex==fsex & race==frace2)

  mindata1 <- subset(cbind(grade,exp,I(exp^2)),sex==fsex & race==frace1)
  mindata2 <- subset(cbind(grade,exp,I(exp^2)),sex==fsex & race==frace2)

  reg1 <- lm(log(wage)~grade+exp+I(exp^2), data=data1)
  reg2 <- lm(log(wage)~grade+exp+I(exp^2), data=data2)

  ## DECOMPOSITION
  ################

  ## Variables
  gap <- mean(log(wage[race==frace1 & sex==fsex]))-mean(log(wage[race==frace2 & sex==fsex]))

  mean1 <- colMeans(mindata1)
  mean2 <- colMeans(mindata2)

  beta1 <- summary(reg1)$coefficients[,1]
  beta2 <- summary(reg2)$coefficients[,1]
  beta1incep <- summary(reg1)$coefficients[1,1]
  beta2incep <- summary(reg2)$coefficients[1,1]
  beta1coef <- summary(reg1)$coefficients[c(2,3,4),1]
  beta2coef <- summary(reg2)$coefficients[c(2,3,4),1]
  betastar <- .5*(beta1coef+beta2coef)
  betastar2 <- (beta1+beta2)/2

  expl <- sum((mean1-mean2)*beta1coef)
  uexpl <- sum(mean2*(beta2coef-beta1coef))

  pct=expl/gap
  pct2=uexpl/gap

  ## output
  out <- data.frame(Gap=gap,
         Explained=expl,
         Unexplained=uexpl,
         Pct=pct*100)

  return(out)
 }

推荐答案

我使用了Oaxaca类型分解.从来没有找到任何R的软件包,所以我写了一些函数来做到这一点.它类似于Stata中的相应软件包.

I have used Oaxaca type decompositions. Did never find any package for R, so I wrote some functions that do it. It is similar to the corresponding package in Stata.

您可以在以下位置找到它的副本: https://github.com/eyjo/Oaxaca

You can find a copy of it in: https://github.com/eyjo/Oaxaca

请注意,当时我对使用固定效果(面板数据)模型感兴趣,该模型与这些分解不直接兼容. FE类型模型有一个未完成的处理程序,但不应使用它.我本打算用它创建一个程序包,但从来没有解决它.

Note that at the time I was interested in using Fixed Effects (panel data) models, which are not directly compatible with these decompositions. There is an unfinished handler for FE type models, but it should not be used. I meant to create a package out of it, but never got around to it.

这篇关于R中的瓦哈卡分解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆