Stata: 双栏模型简介 (Double-hurdle model)

mac2024-01-27  57

编译:李琼琼 (山东大学)

Stata 连享会: 知乎 | 简书 | 码云 |

Stata连享会   计量专题 || 简书推文

文章目录

背景介绍1. 双栏模型 (Double-hurdle model) 介绍1.1 Tobit 模型1.2 Double - hurdle 模型1.3 用图形解释 double hurdle 模型1.4 Double - hurdle 模型的特殊形式 2. 模型的 Stata 实现2.1 dhreg 命令介绍2.2 基于模拟分析的范例2.3 模型估计 3. 面板双栏模型 (Panel-hurdle model)3.1 面板双栏模型基本原理3.2 面板双栏模型的 Stata 实现3.3 基于模拟分析的范例 参考文献关于我们  

本文主要翻译自如下论文,并进行了适当的补充和调整. Source: Engel C, Moffatt P G. Dhreg, xtdhreg, and bootdhreg: Commands to implement double-hurdle regression[J]. Stata Journal, 2014, 14(4):778-797. [PDF]

背景介绍

双栏模型 (Double-hurdle model) 是由 Cragg (1971) 提出的:对于一个活动的参与,个体决策是由两部分组成的。第一个门槛 (hurdle), 决定个体是否是零类型;第二个门槛 (hurdle) 是在第一个阶段是非零的条件下,决定个体对活动的参与程度。这个模型的关键特征是这里有两种类型的零观测值,一种是无周围的环境如何变化他的选择都是零,另一种是他可以有非零选择但是目前的环境导致他选择零,后者也被称为归并零 (Tobin,1958) 。因此,双栏模型除了包括自然的零类型外,还允许零的概率由观测值的个体决定的。本质上,Double-hurdle 模型 是 Tobit 模型的延续。本文主要分三部分内容进行介绍:

1 双栏模型介绍2 模型的实现3 面板双栏模型

1. 双栏模型 (Double-hurdle model) 介绍

介绍双栏模型最自然的开始是先介绍 Tobit 模型,再来引入双栏模型。

1.1 Tobit 模型

Tobit 模型又被称为归并回归模型 (censored regression model), 根据 limit 的设置分为左归并 (lower censoring) 和右归并 (upper censoring),左归并指事先设置一个最小值 A,当被解释变量低于这个值时则自动等于 A。 如果最低的 limit 为 0 时,被称为零归并 (zero censoring)。

y i ∗ = x i ′ β + ε i ε i ∼ N ( 0 , σ 2 ) \begin{aligned} y_{i}^{*} &=\mathbf{x}_{i}^{\prime} \boldsymbol{\beta}+\varepsilon_{i} \\ \varepsilon_{i} & \sim N\left(0, \sigma^{2}\right) \end{aligned} yiεi=xiβ+εiN(0,σ2)

上面的公式中潜变量 y i ∗ y_{i}^{*} yi (最终无法直接被看到)代表个体 i i i 希望做出的贡献 (latent contribution), 这个潜在贡献可以为负值,但是试验规则认为只要为负值最终的贡献都归为 0 (规则如下):

y i = { y i ∗  if  y i ∗ > 0 0  if  y i ∗ ⩽ 0 y_{i}=\left\{\begin{array}{cl}{y_{i}^{*}} & {\text { if } y_{i}^{ *}>0} \\ {0} & {\text { if } y_{i}^{ *}\leqslant0}\end{array}\right. yi={yi0 if yi>0 if yi0

这里以零归并举例,采用对数似然函数,估计模型如下: log ⁡ L = ∑ i = 1 n [ I y i = 0 ln ⁡ { Φ ( − x i ′ β σ ) } + I y i > 0 ln ⁡ { 1 σ ϕ ( y i − x i ′ β σ ) } ] \log L=\sum_{i=1}^{n}\left[I_{y_{i}=0} \ln \left\{\Phi\left(-\frac{\mathbf{x}_{i}^{\prime} \boldsymbol{\beta}}{\sigma}\right)\right\}+I_{y_{i}>0} \ln \left\{\frac{1}{\sigma} \phi\left(\frac{y_{i}-\mathbf{x}_{i}^{\prime} \boldsymbol{\beta}}{\sigma}\right)\right\}\right] logL=i=1n[Iyi=0ln{Φ(σxiβ)}+Iyi>0ln{σ1ϕ(σyixiβ)}] 其中 I I I 为示性函数,当下标所表示的条件正确时取值为 1,否则为 0。通过使 log ⁡ L \log L logL 最大化来求出 β \beta β σ \sigma σ

1.2 Double - hurdle 模型

Double - hurdle 模型有两个阶段,这两个阶段分别采用 probit 估计和 tobit 估计:

d i ∗ = z i ′ α + ε 1 , i y i ∗ ∗ = x i ′ β + ε 2 , i ( ε 1 , i ε 2 , i ) ∼ N [ ( 0 0 ) , ( 1 0 0 σ 2 ) ] \begin{aligned} d_{i}^{*} &=\mathbf{z}_{i}^{\prime} \boldsymbol{\alpha}+\varepsilon_{1, i} \\ y_{i}^{* *} &=\mathbf{x}_{i}^{\prime} \boldsymbol{\beta}+\varepsilon_{2, i} \\\left(\begin{array}{c}{\varepsilon_{1, i}} \\ {\varepsilon_{2, i}}\end{array}\right) & \sim N\left[\left(\begin{array}{l}{0} \\ {0}\end{array}\right),\left(\begin{array}{cc}{1} & {0} \\ {0} & {\sigma^{2}}\end{array}\right)\right] \end{aligned} diyi(ε1,iε2,i)=ziα+ε1,i=xiβ+ε2,iN[(00),(100σ2)]

在第一个阶段 (hurdle),被解释变量 ( d i d_i di) 是二元变量,由潜变量 d i ∗ d_i^{*} di 决定。

d i = { d i ∗  if  d i ∗ > 0 0  if  d i ∗ ⩽ 0 d_{i}=\left\{\begin{array}{cl}{d_{i}^{*}} & {\text { if } d_{i}^{ *}>0} \\ {0} & {\text { if } d_{i}^{ *}\leqslant0}\end{array}\right. di={di0 if di>0 if di0

在第二个阶段 (hurdle), 被解释变量 y i ∗ y_{i}^{*} yi 是零或者正数,非常像 Tobit 模型 (Ⅰ)。 y i ∗ = max ⁡ ( y i ∗ ∗ , 0 ) y_{i}^{*}=\max \left(y_{i}^{* *}, 0\right) yi=max(yi,0) 双栏模型对数似然函数为:

log ⁡ L = ∑ 0 ln ⁡ { 1 − Φ ( z i ′ α ) Φ ( x i ′ β σ ) } + ∑ + ln ⁡ { Φ ( z i ′ α ) 1 σ ϕ ( y i − x i ′ β σ ) } \log L=\sum_{0} \ln \left\{1-\Phi\left(\mathbf{z}_{i}^{\prime} \boldsymbol{\alpha}\right) \Phi\left(\frac{\mathbf{x}_{i}^{\prime} \boldsymbol{\beta}}{\sigma}\right)\right\}+\sum_{+} \ln \left\{\Phi\left(\mathbf{z}_{i}^{\prime} \boldsymbol{\alpha}\right) \frac{1}{\sigma} \phi\left(\frac{y_{i}-\mathbf{x}_{i}^{\prime} \boldsymbol{\beta}}{\sigma}\right)\right\} logL=0ln{1Φ(ziα)Φ(σxiβ)}++ln{Φ(ziα)σ1ϕ(σyixiβ)}

上式中,双栏模型的第二个阶段给 y i ∗ y_{i}^{*} yi 设置了最小值 0 ,当然也可以将最小值设置为其他数 y m i n y_{min} ymin, 都被称为 lower hurdle。 若最小值为 y m i n y_{min} ymin, 对数似然函数的变为:

log ⁡ L = ∑ m i n ln ⁡ { 1 − Φ ( z i ′ α ) Φ ( x i ′ β − y m i n σ ) } + ∑ + ln ⁡ { Φ ( z i ′ α ) 1 σ ϕ ( y i − x i ′ β σ ) } \log L=\sum_{min} \ln \left\{1-\Phi\left(\mathbf{z}_{i}^{\prime} \boldsymbol{\alpha}\right) \Phi\left(\frac{\mathbf{x}_{i}^{\prime} \boldsymbol{\beta} - y_{min}}{\sigma}\right)\right\}+\sum_{+} \ln \left\{\Phi\left(\mathbf{z}_{i}^{\prime} \boldsymbol{\alpha}\right) \frac{1}{\sigma} \phi\left(\frac{y_{i}-\mathbf{x}_{i}^{\prime} \boldsymbol{\beta}}{\sigma}\right)\right\} logL=minln{1Φ(ziα)Φ(σxiβymin)}++ln{Φ(ziα)σ1ϕ(σyixiβ)}

若双栏模型是 upper hurdle 型,即第二个阶段设置一个最大值 y m a x y_{max} ymax, 所有超过 y m a x y_{max} ymax 的值都等于 y m a x y_{max} ymax,小于 y m a x y_{max} ymax 的值则不改变,那么此时模型变为:

log ⁡ L = ∑ m a x ln ⁡ { 1 − Φ ( z i ′ α ) Φ ( y m a x − x i ′ β σ ) } + ∑ + ln ⁡ { Φ ( z i ′ α ) 1 σ ϕ ( y i − x i ′ β σ ) } \log L=\sum_{max} \ln \left\{1-\Phi\left(\mathbf{z}_{i}^{\prime} \boldsymbol{\alpha}\right) \Phi\left( \frac{y_{max}-\mathbf{x}_{i}^{\prime} \boldsymbol{\beta}}{\sigma}\right)\right\}+\sum_{+} \ln \left\{\Phi\left(\mathbf{z}_{i}^{\prime} \boldsymbol{\alpha}\right) \frac{1}{\sigma} \phi\left(\frac{y_{i}-\mathbf{x}_{i}^{\prime} \boldsymbol{\beta}}{\sigma}\right)\right\} logL=maxln{1Φ(ziα)Φ(σymaxxiβ)}++ln{Φ(ziα)σ1ϕ(σyixiβ)}

1.3 用图形解释 double hurdle 模型

上图中的的同心圆是 d ∗ d^{*} d y ∗ ∗ y^{**} y 的联合分布,这个同心圆是以 ( z i ′ α ({z}_{i}^{\prime} \alpha (ziα, x i ′ β ) {x}_{i}^{\prime} \beta) xiβ) 为中心并根据解释变量的变动进行移动。在第二、三象限,由于 d ∗ d^{*} d 小于 0, y y y 一直为 0,表现为个体永远不会 contribute;在第四象限, d ∗ d^{*} d 大于 0, 但是 y ∗ ∗ y^{**} y 小于 0, 所以 y y y 暂时为 0,会随着 x x x 变量的变动的而可能大于 0;在第一象限, y y y 为正数,个体实际做了 contribution。

1.4 Double - hurdle 模型的特殊形式

如果模型第一阶段,只有截距而没有解释变量, Φ ( z i ′ α ) = Φ ( α 0 ) \Phi\left(\mathbf{z}_{i}^{\prime}\boldsymbol{\alpha}\right) = \Phi\left({\alpha_0}\right) Φ(ziα)=Φ(α0), 则对数似然函数变为: log ⁡ L = ∑ 0 ln ⁡ { 1 − Φ ( α 0 ) Φ ( x i ′ β σ ) } + ∑ + ln ⁡ { Φ ( α 0 ) 1 σ ϕ ( y i − x i ′ β σ ) } \log L=\sum_{0} \ln \left\{1-\Phi\left(\alpha_{0}\right) \Phi\left(\frac{\mathrm{x}_{i}^{\prime} \beta}{\sigma}\right)\right\}+\sum_{+} \ln \left\{\Phi\left(\alpha_{0}\right) \frac{1}{\sigma} \phi\left(\frac{y_{i}-\mathrm{x}_{i}^{\prime} \beta}{\sigma}\right)\right\} logL=0ln{1Φ(α0)Φ(σxiβ)}++ln{Φ(α0)σ1ϕ(σyixiβ)} p = Φ ( α 0 ) p = \Phi\left({\alpha_0}\right) p=Φ(α0) ,此时模型就变成了 p-tobit 模型,即认为有一定比例 p p p 的样本可能会 contribute, 而永远不会 contribute 的样本占 1 − p 1-p 1p 的比例。 p-tobit 模型最先由 (Deaton and Irish, 1984) 提出。

2. 模型的 Stata 实现

2.1 dhreg 命令介绍

我们可以使用 dhreg 命令来实现双栏模型的估计。在 Stata 命令窗口中输入 help dhreg 命令即可查看其完整帮助文件。dhreg 命令的基本语法为:

dhreg depvar indepvars [if] [in] [, up ptobit hd(varlist) millr]

各项的含义如下:

depvar: 表示被解释变量,即最终的可观测的 y y yindepvars:表示关键的解释变量,即决定 y ∗ ∗ y^{**} y (潜变量) 的解释变量 x x xup: 将模型设置为右归并,并且设置 y y y 最大值(默认为左归并)ptobit: 将双栏模型设置为 p-tobit 模型hd(varlist): 表示第一栏中决定 d ∗ d^{*} d 的解释变量 z z zmillr: 用逆米尔斯比率来控制扰动项的相关性

2.2 基于模拟分析的范例

我们通过模拟生成的数据来对 dhreg 命令的使用进行介绍,下面是数据生成的过程 (DGP): d i ∗ = { 1 − 2 + 4 z i + ε i 1 > 0 0 o t h e r w i s e d_i^*=\begin{cases} 1& -2+4z_i+\varepsilon_{i1} >0 \\ 0 & otherwise \end{cases} di={102+4zi+εi1>0otherwise

y i ∗ ∗ = 0.5 + 0.3 x i + ε i 2 y_i^{**} = 0.5+0.3x_i+\varepsilon_{i2} yi=0.5+0.3xi+εi2

y i ∗ = { y ∗ ∗ y i ∗ ∗ > 0 0 o t h e r w i s e y_i^*=\begin{cases} y^{**}& y_i^{**} >0 \\ 0 & otherwise \end{cases} yi={y0yi>0otherwise

y i = ( d i ∗ ) ( y i ∗ ) y_i=(d_i^*)(y_i^*) yi=(di)(yi)

ε i 1 = 0.5 ε i 2 + 1 − 0. 5 2 η i \varepsilon_{i1}=0.5\varepsilon_{i2}+\sqrt{1-0.5^2}\eta_i εi1=0.5εi2+10.52 ηi

ε i 1 , η i ∼ N ( 0 , 1 ) \varepsilon_{i1},\eta_i \sim N(0,1) εi1,ηiN(0,1)

c o r r ( ε i 1 , ε i 2 ) = 0.5 corr(\varepsilon_{i1},\varepsilon_{i2})=0.5 corr(εi1,εi2)=0.5

z i , x i ∼ U ( 0 , 1 ) z_i,x_i \sim U(0,1) zi,xiU(0,1)

上面第一个公式生成的潜变量 d i ∗ d_i^* di 即为第一个栏 (hurdle),是由服从均匀分布的外生变量 z i z_i zi 和扰动项 ε i 1 \varepsilon_{i1} εi1 决定的。第二个公式生成潜变量 y ∗ ∗ y^{**} y 是第二个栏 (hurdle),是由外生变量 x i x_i xi 和扰动项 ε i 2 \varepsilon_{i2} εi2 决定的。当前面两个栏都被跨过时,就可以观察到变量 y i y_i yi (可观测变量)的取值 (非 0),否则 y i y_i yi 为 0。

clear all set obs 1000 set seed 123 // 设置种子,为了使每次重复模拟过程的结果相同 gen z_i = uniform() // z_i 服从(0,1)均匀分布 set seed 1234 gen x_i = uniform() set obs 1000 set seed 12345 gen e_i2 = invnormal(uniform()) // e_i2 服从标准正态分布 set seed 12435 gen n_i = invnormal(uniform()) gen e_i1 = 0.5*e_i2 + sqrt(1-0.5*0.5)*n_i gen d_i = 0 replace d_i = 1 if -2 + 4*z_i + e_i1 > 0 gen y_i2 = 0.5 + 0.3*x_i + e_i2 gen y_i1 = 0 replace y_i1 = y_i2 if y_i2 > 0 gen y_i = d_i*y_i1 save data_process1.dta, replace // 保存一份模拟数据

数据效果如下:

use "data_process1.dta", clear hist y_i if d_i == 1,title(Conditional on passing first hurdle) scheme(sj) graph save y_i_1.gph, replace hist y_i ,title(All Data) scheme(sj) graph save y_i_2.gph, replace gr combine y_i_1.gph y_i_2.gph graph save y_i.png, replace

从左图可以看出有很多观测值通过了第一栏(即 d i ∗ > 0 d_i^* > 0 di>0), 但是由于潜变量 y i ∗ ∗ y_i^{**} yi 为 0, 导致了最终观测值为 0。而更多的 y i y_i yi 为 0 的观测值是因为没有通过第一栏 (即 d i ∗ < = 0 d_i^* <= 0 di<=0)。

2.3 模型估计

我们先进行传统的 tobit 估计, 再使用 dhreg 进行估计,然后对这两种估计结果进行比较。

. use "data_process1.dta", clear . tobit y_i x_i, ll(0) Tobit regression Number of obs = 1,000 Uncensored = 413 Limits: lower = 0 Left-censored = 587 upper = +inf Right-censored = 0 LR chi2(1) = 3.49 Prob > chi2 = 0.0619 Log likelihood = -1129.3849 Pseudo R2 = 0.0015 ------------------------------------------------------------------------------ y_i | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- x_i | .3617779 .1939403 1.87 0.062 -.0187992 .7423551 _cons | -.4709888 .1194536 -3.94 0.000 -.7053975 -.2365801 -------------+---------------------------------------------------------------- var(e.y_i)| 2.40666 .191884 2.058097 2.814257 ------------------------------------------------------------------------------

接着是进行 dhreg 估计:

dhreg y_i x_i, hd(z_i) (output omitted) maximum likelihood estimates of double hurdle model N = 1000 log likelihood = -984.07209 chi square hurdle equation = 67.264411 p hurdle equation = 2.374e-16 chi square above equation = 4.8518223 p above equation = .02761694 chi square overall = 69.895304 p overall = 6.644e-16 -------------------------------------------------------------------------------- | coef se z p lower CI upper CI -------------+------------------------------------------------------------------ hurdle | z_i | 3.644556 .4443773 8.201488 2.22e-16 2.773592 4.515519 _cons | -1.727589 .1522467 -11.3473 7.65e-30 -2.025987 -1.429191 above | x_i | .416768 .189209 2.202685 .0276169 .0459251 .7876109 _cons | .5702333 .1428997 3.990444 .0000659 .290155 .8503115 sigma | _cons | 1.053116 .0643765 16.35869 0 .9269402 1.179292 --------------------------------------------------------------------------------

Tobit 模型估计 x i x_i xi 的系数为 0.362 (在 10% 水平上显著) , 而 double hurdle 模型估计 x i x_i xi 的系数为 0.417 (在 5% 水平上显著), 由本次模拟结果来看 Tobit 估计似乎接近真实值 ( x i x_i xi 实际系数为 0.3), 但是双栏模型可以将决定 d i d_i di的变量 z i z_i zi 的系数估计出来 (估计为3.645), 非常接近真实值 4 (在 1% 水平上显著)。

[注:我们尝试通过设置不同的种子,生成不同的随机数,发现 double hurdle 模型对 x i x_i xi 的估计有时候会比 Tobit 模型估计更加准确]。

3. 面板双栏模型 (Panel-hurdle model)

3.1 面板双栏模型基本原理

Dong and Kaiser (2008) 将双栏模型发展成面板双栏模型,并使用这个模型对家庭牛奶消费做实证分析。Dong 假设并验证了家庭牛奶消费总的来说由非经济因素和经济因素决定,非经济因素包括户主年龄、教育、种族背景等,经济因素包括收入、牛奶的价格等。在一定的时间内,非经济因素一般不会发生改变,并且在家庭是否产生购买牛奶的行为中起决定性作用。

第一阶段 (first hurdle) d i ∗ = z i ′ α + ε 1 , i d i = 1  if  ∣ d i ∗ > 0 ; d i = 0  otherwise  ε 1 , i ∼ N ( 0 , 1 ) \begin{aligned} d_{i}^{*} &=\mathbf{z}_{i}^{\prime} \boldsymbol{\alpha}+\varepsilon_{1, i} \\ d_{i} &=1 \text { if } | d_{i}^{*}>0 ; d_{i}=0 \text { otherwise } \\ \varepsilon_{1, i} & \sim N(0,1) \end{aligned} didiε1,i=ziα+ε1,i=1 if di>0;di=0 otherwise N(0,1)

第二阶段 (second hurdle)

y i t ∗ ∗ = x i t ′ β + u i + ε 2 , i t y i t ∗ = max ⁡ ( y i t ∗ ∗ , 0 ) ( ε 1 , i u i ε 2 , i t ) ∼ N [ ( 0 0 0 ) , ( 1 ρ σ u 0 ρ σ u σ u 2 0 0 0 σ 2 ) ] \begin{aligned} y_{i t}^{* *} &=\mathrm{x}_{i t}^{\prime} \beta+u_{i}+\varepsilon_{2, i t} \\ y_{i t}^{*} &=\max \left(y_{i t}^{* *}, 0\right) \\\left(\begin{array}{c}{\varepsilon_{1, i}} \\ {u_{i}} \\ {\varepsilon_{2, i t}}\end{array}\right) & \sim N\left[\left(\begin{array}{l}{0} \\ {0} \\ {0}\end{array}\right),\left(\begin{array}{ccc}{1} & {\rho \sigma_{u}} & {0} \\ {\rho \sigma_{u}} & {\sigma_{u}^{2}} & {0} \\ {0} & {0} & {\sigma^{2}}\end{array}\right)\right] \end{aligned} yityitε1,iuiε2,it=xitβ+ui+ε2,it=max(yit,0)N000,1ρσu0ρσuσu2000σ2

最终观测值 y i t = d i y i t ∗ y_{i t}=d_{i} y_{i t}^{*} yit=diyit 在第一个阶段中, α \alpha α 相当于非经济因素, d i d_i di 表示个体家庭是否会购买牛奶,基本不随着时间变化而改变;在第二个阶段中, β \beta β 相当于经济因素,决定家庭购买牛奶的数量, y i t ∗ y_{it}^{*} yit 表示个体家庭潜在购买牛奶的数量, μ i \mu_i μi 代表个体效应, 且 μ i \mu_i μi 与解释变量 x i t x_{it} xit 均不相关。 y i t y_{it} yit 表示个体家庭在第 t t t 期购买牛奶的数量。

似然函数模型

( L i ∣ d i = 1 , u i ) = ∏ t = 1 T { 1 − Φ ( x i t ′ β + u i σ ) } I ( y i t = 0 ) { 1 σ ϕ ( y i t − x i t ′ β − u i σ ) } I ( y i t > 0 ) \left(L_{i} | d_{i}=1, u_{i}\right)=\prod_{t=1}^{T}\left\{1-\Phi\left(\frac{\mathbf{x}_{i t}^{\prime} \boldsymbol{\beta}+u_{i}}{\sigma}\right)\right\}^{I\left(y_{i t}=0\right)}\left\{\frac{1}{\sigma} \phi\left(\frac{y_{i t}-\mathbf{x}_{i t}^{\prime} \boldsymbol{\beta}-u_{i}}{\sigma}\right)\right\}^{I\left(y_{i t}>0\right)} (Lidi=1,ui)=t=1T{1Φ(σxitβ+ui)}I(yit=0){σ1ϕ(σyitxitβui)}I(yit>0)

( L i ∣ d i = 0 ) = { 1  if  ∑ t = 1 T y i t > 0 0  if  ∑ t = 1 T y i t = 0 \left(L_{i} | d_{i}=0\right)=\left\{\begin{array}{ll}{1} & {\text { if }\sum_{t=1}^{T} y_{i t}>0} \\ {0} & {\text { if }\sum_{t=1}^{T} y_{i t}=0}\end{array}\right. (Lidi=0)={10 if t=1Tyit>0 if t=1Tyit=0

( L i ∣ u i ) = Φ ( z i ′ α ) ( L i ∣ d i = 1 , u i ) + { 1 − Φ ( z i ′ α ) } ( L i ∣ d i = 0 ) \left(L_{i} | u_{i}\right)=\Phi\left(\mathrm{z}_{i}^{\prime} \boldsymbol{\alpha}\right)\left(L_{i} | d_{i}=1, u_{i}\right)+\left\{1-\Phi\left(\mathrm{z}_{i}^{\prime} \boldsymbol{\alpha}\right)\right\}\left(L_{i} | d_{i}=0\right) (Liui)=Φ(ziα)(Lidi=1,ui)+{1Φ(ziα)}(Lidi=0)

L i = ∫ − ∞ ∞ ( L i ∣ u ) f ( u ) d u L_{i}=\int_{-\infty}^{\infty}\left(L_{i} | u\right) f(u) d u Li=(Liu)f(u)du

样本最终的似然对数函数为: log ⁡ L = ∑ i = 1 n ln ⁡ L i \log L=\sum_{i=1}^{n} \ln L_{i} logL=i=1nlnLi

3.2 面板双栏模型的 Stata 实现

Stata 中用 xtdhreg 和 boothreg 命令对面板数据进行双栏模型的估计。首先在 Stata 命令窗口中输入 help xtdhreg 命令即可查看其完整帮助文件。xtdhreg 命令的基本语法为:

xtdhreg depvar indepvars [if] [in] [, up ptobit hd(varlist) uncorr trace /// difficult constraints(numlist)]

各项的含义如下:

depvar: 表示被解释变量,即最终的可观测的 y y yindepvars: 表示关键的解释变量,即决定 y ∗ ∗ y^{**} y (潜变量) 的解释变量 x x xup: 将模型设置为右归并,并且设置 y y y 最大值(默认为左归并)ptobit: 将双栏模型设置为 p-tobit 模型hd(varlist): 表示第一栏中决定 d ∗ d^* d 的解释变量 z z zmillr: 用逆米尔斯比率来控制扰动项的相关性uncorr: 表示第一栏和第二栏中的扰动项不相关trace: 显示每一次迭代的系数difficult: 当模型不收敛时,换用其他替代的算法constraints(numlist): 允许对模型进行限制

在 Stata 命令窗口中输入 help boothreg 命令即可查看其完整帮助文件。boothreg 命令的基本语法为:

bootreg depvar indepvars [if] [in] [, up ptobit hd(varlist) millr /// margins(string) seed(integer) reps(integer) strata(varlist) cluster(varlist) /// capt maxiter(integer)]

各项的含义如下:

depvar: 表示被解释变量,即最终的可观测的 y y yindepvars:表示关键的解释变量,即决定 y ∗ ∗ y^{**} y (潜变量) 的解释变量 x x xup: 将模型设置为右归并,并且设置 y y y 最大值(默认为左归并)ptobit: 将双栏模型设置为 p-tobit 模型hd(varlist): 表示第一栏中决定 d ∗ d^{*} d 的解释变量 z z zmillr: 用逆米尔斯比率来控制扰动项的相关性margins(string): bootstrep 估计的边际效应seed(integer): 设置种子,为了使结果可重复reps(integer): boostrap 重复的次数,默认是 50 次strata(varlist): 进行分层抽样capt: 自动忽略不收敛的情况maxiter(integer): 设置迭代的最多次数,默认为 50

3.3 基于模拟分析的范例

本小节我们先模拟生成面板数据,然后再利用生成的数据进行模型估计。

数据生成过程 (DPG) d i ∗ = { 1 - 2 + 4 × z i + ε i 1 > 0 0  otherwise  y i t ∗ = 0.5 + 0.3 × x i t + u i + ε i t 2 y i t ∗ = { y i t ∗ ∗ y i t ∗ ∗ > 0 0  otherwise  y i t = d i ∗ × y i t ∗ ε i 1 = 0.9 × u i + ( 1 − 0. 9 2 ) × η i ( ε i t 2 u i ) ∼ N [ ( 0 0 ) , ( 1 0 0 σ 2 ] × η i η i ∼ N ( 0 , σ 2 ) \begin{aligned} d_{i}^{*} &=\left\{\begin{array}{cl}{1} & {\text -2+4 \times z_{i}+\varepsilon_{i 1}>0} \\ {0} & {\text { otherwise }}\end{array}\right.\\ y_{i t}^{*}=& 0.5+0.3 \times x_{i t}+u_{i}+\varepsilon_{i t 2} \\ y_{i t}^{*} &=\left\{\begin{array}{cc}{y_{i t}^{* *}} & {\text y_{i t}^{* *}>0} \\ {0} & {\text { otherwise }}\end{array}\right.\\ y_{i t}=& d_{i}^{*} \times y_{i t}^{*} \\ \varepsilon_{i 1} &=0.9 \times u_{i}+\sqrt{\left(1-0.9^{2}\right)} \times \eta_{i} \\\left(\begin{array}{c}{\varepsilon_{i t 2}} \\ {u_{i}}\end{array}\right) & \sim N\left[\left(\begin{array}{l}{0} \\ {0}\end{array}\right),\left(\begin{array}{ll}{1} & {0} \\ {0} & {\sigma^{2}}\end{array}\right] \times \eta_{i}\right.\\ \eta_{i} & \sim N\left(0, \sigma^{2}\right) \end{aligned} diyit=yityit=εi1(εit2ui)ηi={10-2+4×zi+εi1>0 otherwise 0.5+0.3×xit+ui+εit2={yit0yit>0 otherwise di×yit=0.9×ui+(10.92) ×ηiN[(00),(100σ2]×ηiN(0,σ2)

面板数据的个体为 i i i, 一共有 T T T 期。这些个体的决策 (是否 参与) 是由第一栏 d i ∗ d_i^* di 是否大于 0 和第二栏 y i t ∗ y_{it}^* yit 是否大于 0 共同决定的。值得注意的是, d i ∗ d_i^{*} di 不会随着时间 t t t 变化而改变,如果第一期 d i ∗ = 0 d_i^{*} = 0 di=0, 那么剩下的 t − 1 t-1 t1 期都会有 d i ∗ = 0 d_i^{*} = 0 di=0 即该个体一直选择不参与; 而当 d i ∗ > 0 d_i^{*} > 0 di>0 时, y i t ∗ = 0 y_{it}^{*} = 0 yit=0,个体暂时不参与但并不会影响其他几期该的决策。另外,我们设置了个体随机效应 u i u_i ui, 并且 u i u_i ui 与 第一个公式的误差项存在相关性。用 Stata 生成数据的过程如下:

clear all set obs 2000 set seed 10011979 gen z_i = uniform() set seed 1111122 gen u_i = rnormal(0, 3) set seed 1222222 gen n_i = rnormal(0,3) gen e_i1 = 0.9*u_i + sqrt(1-0.9^2)*n_i /* 面板数据生成过程 */ gen d_i = 0 replace d_i = 1 if -2 + 4*z_i + e_i1 > 0 gen id = _n expand 5 // 将 T 设置为 5 期 bys id: gen t = _n xtset id t bysort id (t): gen x_it = rnormal(0,1) + rnormal(0,1) if _n==1 bysort id (t): replace x_it = .8 * x_it[_n-1] + rnormal(0,1) if _n!=1 gen e_i2 = rnormal(0,1) gen y_it2 = 0.5 + 0.3*x_it + u_i + e_i2 corr e_i2 u_i // 检查e_i2和u_i的相关性 gen y_it1 = 0 replace y_it1 = y_it2 if y_it2 > 0 gen y_it = y_it1*d_i save data_process2.dta, replace //保存模拟数据 模型估计 用 xtdhreg 命令进行双栏估计的结果如下: use data_process2.dta, clear help mdraws // 进行 xtdhreg 估计前,需要装`mdraws`包 xtdhreg y_it x_it, hd(z_i) (output omitted) Number of obs = 10,000 Wald chi2(1) = 46.82 Log likelihood = -9013.4217 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ Coef. Std. Err. z P>|z| [95% Conf. Interval] ----------------+------------------------------------------------------------- hurdle z_i | .6908215 .1009566 6.84 0.000 .4929501 .8886929 _cons | -.2702063 .0611108 -4.42 0.000 -.3899812 -.1504313 ----------------+------------------------------------------------------------- above x_it | .2971716 .0162833 18.25 0.000 .2652569 .3290863 _cons | 3.887898 .1050517 37.01 0.000 3.682001 4.093796 ----------------+------------------------------------------------------------- sigma_u _cons | 3.249278 .0942043 34.49 0.000 3.064641 3.433915 ----------------+------------------------------------------------------------- sigma_e _cons | .9920639 .012312 80.58 0.000 .9679329 1.016195 ----------------+------------------------------------------------------------- transformed_rho _cons | -.9211924 .0730788 -12.61 0.000 -1.064424 -.7779606 ------------------------------------------------------------------------------ rho: tanh([transformed_rho]_cons) ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- rho | -.726461 .0345118 -21.05 0.000 -.7941029 -.6588192 ------------------------------------------------------------------------------ separate Wald tests for joint significance of all explanatory variables note if you use factor variables, i.e. the i., c., # and ## notation, you must run the Wald test by hand. For detail see help file estimates of joint significance chi square hurdle equation = 46.823275 p hurdle equation = 7.769e-12 chi square above equation = 333.06554 p above equation = 2.066e-74 chi square overall = 376.42223 p overall = 1.824e-82

用 bootdreg 命令进行双栏模型估计结果如下:

bootdhreg y_it x_it, hd(z_i) cluster(id) capt (output omitted) maximum likelihood estimates of double hurdle model N = 10000 log likelihood = -14962 chi square hurdle equation = 140.17438 p hurdle equation = 2.438e-32 chi square main equation = 140.17438 p main equation = 2.438e-32 chi square overall = 442.19897 p overall = 9.500e-97 bootstrap results ------------------------------------------------------------------------------ | coef se p lowciz upciz lowcip upcip ------------+----------------------------------------------------------------- hurdle | z_i | 1.002614 .122 0 .7634344 1.241794 .7598894 1.346414 _cons | -.4531903 .072 0 -.5948118 -.3115688 -.6363495 -.2646514 main | 0 x_it | .3388443 .052 0 .2370221 .4406664 .2289405 .4781399 _cons | 2.279919 .132 0 2.020481 2.539356 1.868922 2.511813 sigma | _cons | 2.583072 .095 0 2.396594 2.76955 2.401081 2.808727 ------------------------------------------------------------------------------

从回归结果可以看出,xtdhreg 和 bootdhreg 对样本的 x i x_i xi 系数估计值 (0.297 和 0.339) 非常接近 x i x_i xi 真实系数 (0.3),且均在 1% 水平上显著。

参考文献

Bruno García, 2013, Implementation of a Double-Hurdle Model, Stata Journal, 13(4): 776–794. [pdf]Christoph Engel, Peter G. Moffatt, 2014, Dhreg, Xtdhreg, and Bootdhreg: Commands to Implement Double-Hurdle Regression, Stata Journal, 14(4): 778–797. [pdf]Dong, Diansheng, and H. M. Kaiser. Studying household purchasing and nonpurchasing behaviour for a frequently consumed commodity: two models[J]. Applied Economics, 2008, 40(15):1941-1951. [PDF]Engel C, Moffatt P G. Dhreg, xtdhreg, and bootdhreg: Commands to implement double-hurdle regression[J]. Stata Journal, 2014, 14(4):778-797. [PDF]

关于我们

「Stata 连享会」 由中山大学连玉君老师团队创办,定期分享实证分析经验, 公众号:StataChina。公众号推文同步发布于 、简书 和 知乎Stata专栏。可在百度中搜索关键词 「Stata连享会」查看往期推文。点击推文底部【阅读原文】可以查看推文中的链接并下载相关资料。欢迎赐稿: 欢迎赐稿。录用稿件达 三篇 以上,即可 免费 获得一期 Stata 现场培训资格。E-mail: StataChina@163.com往期推文:计量专题 || 简书推文 || 公众号合集


最新回复(0)