Stata和R之间的Heckman 2阶段模型的不同结果

时间:2016-05-09 20:35:13

标签: r stata

我正在开展一个项目,要求我运行一个Heckman 2阶段模型,这对我来说很新,使用两个阶段的probit。作为经验检查,我在Stata和R中运行了模型。我使用“sampleSelection”包运行Stata 13和R v.3.2.3。问题是我得到了不同的结果,我认为这是因为我对代码背后的算法缺乏了解。也许我错过了论点。我知道的一件事是R正在为第二阶段而不是probit运行Tobit模型。我想知道是否有人可能对如何使用probit方法为两个阶段运行2阶段模型获得R有所了解。下面我首先介绍了Stata代码和结果,然后是R代码和结果。

Stata代码

heckprob  ivburden  isingle recuse50 infobk2 timesurv inh icp itime igate ioth, 
select(iw5rsp= i201 isingle icatmpgte7 ichgfrwv inh icp itime igate     ioth)  vce(robust)

STATA Output

R代码

library(sampleSelection)
heckit(selection = iw5rsp ~ i201 + isingle + icatmpgte7 + ichgfrwv + 
              inh + icp + itime + igate + ioth, 
          outcome = ivburden ~ isingle + recuse50 + infobk50 + timesurv + 
              inh + icp + itime + igate + ioth, data = dat, 
          method = "2step")

R Output

任何建议都将不胜感激。

4 个答案:

答案 0 :(得分:1)

您提供的R代码将提供与Stata的heckman命令相同的结果:即。,

heckman ivburden isingle recuse50 infobk2 timesurv inh icp itime igate ioth, select(iw5rsp= i201 isingle icatmpgte7 ichgfrwv inh icp itime igate ioth)

一种看待这种情况的方法是输出在底部为您提供“西格玛”的估计值。您想要估算的模型中没有“sigma”。

对于R中的sampleSelection包来估计带有样本选择的双变量概率模型,即heckprob,首先需要指定结果方程的因变量是一个因子。这是修复:

library(sampleSelection)
ivburdenF <- factor(ivburden)
heckit(selection = iw5rsp ~ i201 + isingle + icatmpgte7 + ichgfrwv + 
              inh + icp + itime + igate + ioth, 
          outcome = ivburdenF ~ isingle + recuse50 + infobk50 + timesurv + 
              inh + icp + itime + igate + ioth, data = dat)

最后要提到的一点是,不应该使用“2步”估计器来获得具有概率的概率方程的Heckman风格选择模型。

上面的R语法和Stata的heckprob的结果应该因舍入而有所不同(假设两种最大化方法都实现了收敛)。

答案 1 :(得分:0)

&#34;似乎这个包可能不会做我需要做的事情&#34; - 你想做什么?当你说你想要一个probit-probit模型时,你的意思是你试图用一个结果方程估计一个heckman风格模型,其因变量是二元(二元概率)?规范的heckit模型在结果阶段使用OLS,这是heckman函数的作用(与您使用的heckprob相反)。问题是R的sampleSelection包使用的功能相当于&#34; heckman&#34;而不是&#34; heckprob&#34;。你需要的是R等价物。我实际上并不熟悉一个。我使用专门为此任务编写的函数。请参阅此链接以获取代码:http://dynaman.net/R/HeckmanProbit.R

(与所有这些无关,也可以切换估算方法。对于R模型,您可以将其更改为method='ml'method='2step',因此您可能希望将其保留为比较stata和R)时的想法。

答案 2 :(得分:0)

这是一个我错过的简单解决方案,因为我没有注意到我没有将我的因变量表示为不等式。在我在这里发布的代码中,您可以看到没有不等式符号。我仔细看了一下这里的文档和示例:https://r-forge.r-project.org/forum/forum.php?thread_id=31866&forum_id=844&group_id=256(Arne Hennigsen指出了这一点,他是#34; sampleSelection&#34的作者之一;非常感谢Arne )

我注意到在这段代码中的表达式中使用了不等式,并且在我自己的代码中实现后,在Stata和R之间获得了匹配的结果,并且出现了小的舍入不一致。

答案 3 :(得分:0)

如果有人正在寻找一个示例,说明如何使用sampleSelection package中的R heckprob函数重现Stata的heckprobit(别名为heckit)的结果作者:Arne Henningsen&amp; Ott Toomet),这是Example 1 from [R] heckprobit的翻译:

library(sampleSelection)
library(readstata13)
library(tidyverse)

df_school = read.dta13("http://www.stata-press.com/data/r13/school.dta") %>% 
  as_data_frame() %>% 
  mutate_at(
    c("vote", "private"), as.factor
  )

heck_school_1 = heckit(
  selection = vote ~ years + loginc + logptax,
  outcome = private ~ years + logptax ,
  data = df_school,
  method = "ml"
)

summary(heck_school_1)

这应该给出相同的结果:

use http://www.stata-press.com/data/r13/school
heckprob private years logptax, select(vote=years loginc logptax)

请注意,需要将结果变量转换为factor,并在拟合模型时使用method = "ml"