浙江大学【面板数据分析与STATA应用】——第三讲内生性与工具变量法
解释变量和误差项存在内生性问题
内生性问题来源
内生性问题主要来自于三个方面,分别为:遗漏变量、联立性以及度量误差
- 遗漏变量
遗漏变量是指可能与解释变量相关的变量,本来应该加以控制,但却没有控制的变量。这些变量最后进入了误差项,从而导致误差项与解释变量相关,进而导致了内生性问题。 - 联立性
联立性是指一个计量方程中的核心解释变量A对被解释变量B产生影响,反过来,被解释变量B又对A产生影响。
如果B对A有正向的影响,正向冲击就会导致A增加,从而导致核心解释变量A与误差项正相关。
如果B对A有负向的影响,正向冲击就会导致A降低,从而导致核心解释变量A与误差项负相关。
比如:研究犯罪率和警察数量的关系,一般来说,警察数量越多,犯罪率越低;但反过来,犯罪率降低,警察数量也会减少
- 度量误差
度量误差可以分为解释变量的度量误差和被解释变量的度量误差。
内生性带来的问题
- 在存在内生性解释变量的情况下,OLS估计量有偏且不一致。
- 只要任何一个解释变量与随机扰动项相关,全部解释变量的系数都会有偏、不一致。
解决内生性的变化
通常有两种方法解决内生性问题即使用内生变量的滞后一期和工具变量法。
- 使用内生变量的滞后一期
一般来说,内生变量的上一期与当期误差项并不存在相关关系,所以可以考虑使用内生变量的滞后一期替代当期的内生变量。这种方法较为简单,并且在直觉上可行,但这种方法的缺点是:不能够回答当期的内生变量对当期的被解释变量的影响程度;而且,上一期的内生变量也可能因为遗漏变量而具有内生性。 - 工具变量法
工具变量(instrumental variable)是指某一个变量与模型中解释变量高度相关,但却不与误差项相关,估计过程中被作为工具使用,以替代模型中与误差项相关的解释变量的变量。
工具变量法则是使用工具变量进行估计的方法。
工具变量法最常用的估计方法为:两阶段最小二乘法(TSLS)。
两阶段最小二乘法
操作:
- 第一阶段:将内生性变量作为被解释变量,工具变量和方程中的外生变量作为解释变量,来进行最小二乘估计;
- 第二阶段:用第一阶段估计得到的内生变量的预测值替换内生变量,再进行最小二乘估计。
举例:yyy = β1\beta_1β1 + β2x2{\beta_2}{x_2}β2x2 +β3x3{\beta_3}{x_3}β3x3 +β4x4{\beta_4}{x_4}β4x4 + uuu,其中,x2x_2x2是严格外生的,而x3x_3x3x4x_4x4是内生的,则至少需要两个工具变量,设z1z_1z1和z2z_2z2为工具变量。
第一阶段:内生变量工具变量的回归
x3x_3x3 = π1{\pi_1}π1 + π2x2{\pi_2}{x_2}π2x2 +π3z1{\pi_3}{z_1}π3z1 +π4z2{\pi_4}{z_2}π4z2 + u1u_1u1
x4x_4x4 = γ1{\gamma_1}γ1 + γ2x2{\gamma_2}{x_2}γ2x2 +γ3z1{\gamma_3}{z_1}γ3z1 +γ4z2{\gamma_4}{z_2}γ4z2 + u2u_2u2
第二阶段:用预测回归的拟合值进行(代入第一阶段预测值)
yyy = β1\beta_1β1 + β2x2{\beta_2}{x_2}β2x2 +β3x3⋅{\beta_3}{x_3^·}β3x3⋅ +β4x4⋅{\beta_4}{x_4^·}β4x4⋅
STATA实现
regress x3 x1 z1 z2
predict v
regress x4 x2 z1 z2
predict w
regress y x2 v w
TSLS的难点不在于估计方法,而在于恰当的工具变量的选择。若存在N个潜在的内生解释变量,则至少需要N个IV。
原理:
- 第一阶段:消除了潜在内生解释变量的内生性,通过外生变量的预测回归,得到这些变量的外生性部分。
- 第二阶段:利用第一阶段得到外生的预测回归的拟合值进行回归,进而消除偏误。
工具变量法的检验
使用工具变量法进行估计时,我们需要对工具变量进行三项检验,分别为:内生性检验、相关性检验、外生性检验。
- 内生性检验
内生性检验即检验核心变量是否具有内生性。如果我们关心的核心解释变量不具有内生性,我们就没有必要使用工具变量法进行估计,而如果我们使用了工具变量法虽然得到了一致估计量,但并不是有效估计量。 - 相关性检验
相关性检验是检验工具变量是否与内生变量之间存在强相关关系。如果使用的工具变量是弱工具变量,则会导致内生变量估计的标准系数偏大。 - 外生性检验
外生性检验是检验工具变量是否与误差项不相关。如果工具变量与误差项相关,则不满足外生性条件,那么使用工具变量法(IV)估计很可能会比OLS估计的结果更糟糕。
实操
- 第一步 模型设定与数据
use crime.dta //打开数据集des //查看数据##结果obs: 630 vars: 59 5 Jun 2007 14:32
---------------------------------------------------------------------------------------------------------------------storage display value
variable name type format label variable label
---------------------------------------------------------------------------------------------------------------------
county int %9.0g county identifier
year byte %9.0g 81 to 87
crmrte float %9.0g crimes committed per person
prbarr float %9.0g 'probability' of arrest
prbconv float %9.0g 'probability' of conviction
prbpris float %9.0g 'probability' of prison sentenc
avgsen float %9.0g avg. sentence, days
polpc float %9.0g police per capita
density float %9.0g people per sq. mile
taxpc float %9.0g tax revenue per capita
west byte %9.0g =1 if in western N.C.
central byte %9.0g =1 if in central N.C.
urban byte %9.0g =1 if in SMSA
pctmin80 float %9.0g perc. minority, 1980
wcon float %9.0g weekly wage, construction
wtuc float %9.0g wkly wge, trns, util, commun
wtrd float %9.0g wkly wge, whlesle, retail trade
wfir float %9.0g wkly wge, fin, ins, real est
wser float %9.0g wkly wge, service industry
wmfg float %9.0g wkly wge, manufacturing
wfed float %9.0g wkly wge, fed employees
wsta float %9.0g wkly wge, state employees
wloc float %9.0g wkly wge, local gov emps
mix float %9.0g offense mix: face-to-face/other
pctymle float %9.0g percent young male
d82 byte %9.0g =1 if year == 82
d83 byte %9.0g =1 if year == 83
d84 byte %9.0g =1 if year == 84
d85 byte %9.0g =1 if year == 85
d86 byte %9.0g =1 if year == 86
d87 byte %9.0g =1 if year == 87
lcrmrte float %9.0g log(crmrte)
lprbarr float %9.0g log(prbarr)
lprbconv float %9.0g log(prbconv)
lprbpris float %9.0g log(prbpris)
lavgsen float %9.0g log(avgsen)
lpolpc float %9.0g log(polpc)
...xtset county year //设置面板数据格式##结果panel variable: county (strongly balanced)time variable: year, 81 to 87delta: 1 unitxtdes //查看数据##结果
county: 1, 3, ..., 197 n = 90year: 81, 82, ..., 87 T = 7Delta(year) = 1 unitSpan(year) = 7 periods(county*year uniquely identifies each observation)Distribution of T_i: min 5% 25% 50% 75% 95% max7 7 7 7 7 7 7Freq. Percent Cum. | Pattern---------------------------+---------90 100.00 100.00 | 1111111---------------------------+---------90 100.00 | XXXXXXX
- 第二步 描述性统计与作图
sum lcrmrte lprbarr lprbconv lprbpris lavgsen lpolpc ldensity lwcon lwtuc lwtrd lwfir lwser lwmfg lwfed lwsta lwloc lpctymle lpctmin west central urban## 结果Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------lcrmrte | 630 -3.609225 .5728077 -6.31355 -1.808895lprbarr | 630 -1.274264 .415897 -2.833214 1.011601lprbconv | 630 -.6929193 .6095949 -2.682732 3.610918lprbpris | 630 -.8786315 .2305144 -1.904239 -.3877662lavgsen | 630 2.153344 .2737295 1.439835 3.251537
-------------+---------------------------------------------------------lpolpc | 630 -6.490637 .5266539 -7.687507 -3.336024ldensity | 630 -.0159271 .7747352 -1.62091 2.177889lwcon | 630 5.462869 .2481783 4.183905 7.751303lwtuc | 630 5.915883 .3702186 3.362377 8.020257lwtrd | 630 5.232423 .2143915 2.82576 7.715457
-------------+---------------------------------------------------------lwfir | 630 5.579433 .2772037 1.257233 6.233362lwser | 630 5.364625 .3600984 .6118253 7.685734lwmfg | 630 5.615181 .2727473 4.623305 6.472115lwfed | 630 5.988757 .1587609 5.542831 6.393507lwsta | 630 5.677787 .1761313 5.153407 6.306275
-------------+---------------------------------------------------------lwloc | 630 5.540139 .1596908 5.097363 5.961237lpctymle | 630 -2.443015 .1967842 -2.77808 -1.29332lpctmin | 630 2.913361 .9546147 .2497076 4.164309west | 630 .2333333 .4232887 0 1central | 630 .3777778 .4852169 0 1
-------------+---------------------------------------------------------urban | 630 .0888889 .2848094 0 1twoway (scatter lcrmrte lprbarr) (lfit lcrmrte lprbarr) //关键变量与被解释变量的散点图并画出回归直线
xtline lcrmrte //关键变量的时间序列图
- 第三步 模型选择
xtivreg lcrmrte lprbconv lprbpris lavgsen ldensity lwcon lwtuc lwtrd lwfir lwser lwmfg lwfed lwsta lwloc lpctymle lpctmin west central urban d82 d83 d84 d85 d86 d87 (lprbarr lpolpc= ltaxpc lmix), fe //双向固定效应的两阶段最小二乘估计 ##结果Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------lcrmrte | 630 -3.609225 .5728077 -6.31355 -1.808895lprbarr | 630 -1.274264 .415897 -2.833214 1.011601lprbconv | 630 -.6929193 .6095949 -2.682732 3.610918lprbpris | 630 -.8786315 .2305144 -1.904239 -.3877662lavgsen | 630 2.153344 .2737295 1.439835 3.251537
-------------+---------------------------------------------------------lpolpc | 630 -6.490637 .5266539 -7.687507 -3.336024ldensity | 630 -.0159271 .7747352 -1.62091 2.177889lwcon | 630 5.462869 .2481783 4.183905 7.751303lwtuc | 630 5.915883 .3702186 3.362377 8.020257lwtrd | 630 5.232423 .2143915 2.82576 7.715457
-------------+---------------------------------------------------------lwfir | 630 5.579433 .2772037 1.257233 6.233362lwser | 630 5.364625 .3600984 .6118253 7.685734lwmfg | 630 5.615181 .2727473 4.623305 6.472115lwfed | 630 5.988757 .1587609 5.542831 6.393507lwsta | 630 5.677787 .1761313 5.153407 6.306275
-------------+---------------------------------------------------------lwloc | 630 5.540139 .1596908 5.097363 5.961237lpctymle | 630 -2.443015 .1967842 -2.77808 -1.29332lpctmin | 630 2.913361 .9546147 .2497076 4.164309west | 630 .2333333 .4232887 0 1central | 630 .3777778 .4852169 0 1
-------------+---------------------------------------------------------urban | 630 .0888889 .2848094 0 1. twoway (scatter lcrmrte lprbarr) (lfit lcrmrte lprbarr). xtline lcrmrte. xtivreg lcrmrte lprbconv lprbpris lavgsen ldensity lwcon lwtuc lwtrd lwfir lwser lwmfg lwfed lwsta lwloc lpctymle l
> pctmin west central urban d82 d83 d84 d85 d86 d87 (lprbarr lpolpc= ltaxpc lmix), feFixed-effects (within) IV regression Number of obs = 630
Group variable: county Number of groups = 90R-sq: Obs per group:within = 0.3587 min = 7between = 0.4442 avg = 7.0overall = 0.4431 max = 7Wald chi2(22) = 368612.24
corr(u_i, Xb) = -0.1867 Prob > chi2 = 0.0000------------------------------------------------------------------------------lcrmrte | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------lprbarr | -0.576 0.802 -0.72 0.473 -2.148 0.997lpolpc | 0.658 0.847 0.78 0.438 -1.002 2.317lprbconv | -0.423 0.502 -0.84 0.399 -1.407 0.561lprbpris | -0.250 0.279 -0.90 0.371 -0.798 0.297lavgsen | 0.009 0.049 0.19 0.853 -0.087 0.105ldensity | 0.139 1.021 0.14 0.891 -1.862 2.141lwcon | -0.029 0.054 -0.54 0.591 -0.134 0.076lwtuc | 0.039 0.031 1.27 0.205 -0.021 0.100lwtrd | -0.018 0.045 -0.39 0.695 -0.107 0.071lwfir | -0.009 0.037 -0.26 0.798 -0.081 0.062lwser | 0.019 0.039 0.48 0.632 -0.057 0.095lwmfg | -0.243 0.420 -0.58 0.562 -1.065 0.579lwfed | -0.451 0.527 -0.86 0.392 -1.484 0.582lwsta | -0.019 0.281 -0.07 0.947 -0.569 0.532lwloc | 0.263 0.312 0.84 0.399 -0.349 0.876lpctymle | 0.351 1.011 0.35 0.728 -1.631 2.333lpctmin | 0.000 (omitted)west | 0.000 (omitted)central | 0.000 (omitted)urban | 0.000 (omitted)d82 | 0.038 0.062 0.61 0.540 -0.083 0.159d83 | -0.044 0.042 -1.05 0.295 -0.127 0.039d84 | -0.045 0.055 -0.82 0.410 -0.153 0.062d85 | -0.021 0.074 -0.28 0.777 -0.166 0.124d86 | 0.006 0.128 0.05 0.961 -0.245 0.257d87 | 0.044 0.216 0.20 0.840 -0.380 0.467_cons | 2.943 2.694 1.09 0.275 -2.337 8.223
-------------+----------------------------------------------------------------sigma_u | .41829289sigma_e | .14923885rho | .88708121 (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(89,518) = 13.93 Prob > F = 0.0000
------------------------------------------------------------------------------
Instrumented: lprbarr lpolpc
Instruments: lprbconv lprbpris lavgsen ldensity lwcon lwtuc lwtrd lwfirlwser lwmfg lwfed lwsta lwloc lpctymle lpctmin west centralurban d82 d83 d84 d85 d86 d87 ltaxpc lmix
------------------------------------------------------------------------------est store FE2SLSxtivreg lcrmrte lprbconv lprbpris lavgsen ldensity lwcon lwtuc lwtrd lwfir lwser lwmfg lwfed lwsta lwloc lpctymle lpctmin west central urban d82 d83 d84 d85 d86 d87 (lprbarr lpolpc= ltaxpc lmix), ec2sls //随机效应的两阶段最小二乘估计##结果
EC2SLS random-effects IV regression Number of obs = 630
Group variable: county Number of groups = 90R-sq: Obs per group:within = 0.4521 min = 7between = 0.8158 avg = 7.0overall = 0.7840 max = 7Wald chi2(26) = 575.73
corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000------------------------------------------------------------------------------lcrmrte | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------lprbarr | -0.413 0.097 -4.24 0.000 -0.604 -0.222lpolpc | 0.435 0.090 4.85 0.000 0.259 0.611lprbconv | -0.323 0.054 -6.03 0.000 -0.428 -0.218lprbpris | -0.186 0.042 -4.44 0.000 -0.269 -0.104lavgsen | -0.010 0.027 -0.38 0.706 -0.063 0.043ldensity | 0.429 0.055 7.82 0.000 0.322 0.537lwcon | -0.007 0.040 -0.19 0.850 -0.085 0.070lwtuc | 0.045 0.020 2.30 0.022 0.007 0.084lwtrd | -0.008 0.041 -0.20 0.844 -0.089 0.073lwfir | -0.004 0.029 -0.13 0.900 -0.060 0.053lwser | 0.006 0.020 0.28 0.780 -0.034 0.045lwmfg | -0.204 0.080 -2.54 0.011 -0.362 -0.046lwfed | -0.164 0.159 -1.03 0.305 -0.476 0.149lwsta | -0.054 0.106 -0.51 0.609 -0.261 0.153lwloc | 0.163 0.120 1.36 0.173 -0.071 0.398lpctymle | -0.108 0.140 -0.77 0.439 -0.382 0.166lpctmin | 0.189 0.041 4.56 0.000 0.108 0.270west | -0.227 0.100 -2.28 0.023 -0.422 -0.032central | -0.194 0.060 -3.24 0.001 -0.311 -0.077urban | -0.225 0.116 -1.95 0.052 -0.452 0.001d82 | 0.011 0.026 0.42 0.677 -0.040 0.061d83 | -0.084 0.031 -2.73 0.006 -0.144 -0.024d84 | -0.103 0.037 -2.79 0.005 -0.176 -0.031d85 | -0.096 0.049 -1.94 0.053 -0.193 0.001d86 | -0.069 0.060 -1.16 0.248 -0.186 0.048d87 | -0.031 0.071 -0.45 0.656 -0.170 0.107_cons | -0.954 1.284 -0.74 0.458 -3.470 1.563
-------------+----------------------------------------------------------------sigma_u | .2145596sigma_e | .14923885rho | .67394424 (fraction of variance due to u_i)
------------------------------------------------------------------------------
Instrumented: lprbarr lpolpc
Instruments: lprbconv lprbpris lavgsen ldensity lwcon lwtuc lwtrd lwfirlwser lwmfg lwfed lwsta lwloc lpctymle lpctmin west centralurban d82 d83 d84 d85 d86 d87 ltaxpc lmix
------------------------------------------------------------------------------est store EC2SLShausman FE2SLS EC2SLS //hausman检验##结果---- Coefficients ----| (b) (B) (b-B) sqrt(diag(V_b-V_B))| FE2SLS EC2SLS Difference S.E.
-------------+----------------------------------------------------------------lprbarr | -.5755052 -.4129264 -.1625788 .7962526lpolpc | .657526 .4347488 .2227773 .8421081lprbconv | -.423144 -.3228871 -.1002569 .4990749lprbpris | -.2502547 -.1863195 -.0639352 .2762967lavgsen | .0090987 -.0101765 .0192752 .0408606ldensity | .139412 .4290282 -.2896162 1.019765lwcon | -.0287308 -.007475 -.0212558 .0360199lwtuc | .0391292 .0454451 -.0063158 .0236726lwtrd | -.0177536 -.0081411 -.0096124 .0184617lwfir | -.0093443 -.0036395 -.0057048 .0223483lwser | .0185855 .0056098 .0129756 .0331904lwmfg | -.2431675 -.2041395 -.039028 .411768lwfed | -.4513386 -.1635112 -.2878273 .5024337lwsta | -.0187447 -.0540496 .0353049 .2601761lwloc | .2632589 .1630526 .1002062 .2885798lpctymle | .3511095 -.1081064 .4592159 1.001351d82 | .037856 .0107451 .0271109 .0560526d83 | -.0443806 -.0837946 .039414 .0292202d84 | -.0451873 -.1034999 .0583125 .040481d85 | -.020942 -.095702 .07476 .0548511d86 | .0063223 -.0688986 .0752209 .1133461d87 | .0435043 -.0314075 .0749118 .2039854
------------------------------------------------------------------------------b = consistent under Ho and Ha; obtained from xtivregB = inconsistent under Ha, efficient under Ho; obtained from xtivregTest: Ho: difference in coefficients not systematicchi2(22) = (b-B)'[(V_b-V_B)^(-1)](b-B)= 19.50Prob>chi2 = 0.6140
- 第四步 报告计量结果
esttab FE FE2SLS EC2SLS ,b(%9.3f) se mtitle( FE FE2SLS EC2SLS) obslast star (* 0.1 ** 0.05 *** 0.01) compress nogap aesttab FE FE2SLS EC2SLS using tabl.rtf ,b(%9.3f) se mtitle( FE FE2SLS EC2SLS) obslast star (* 0.1 ** 0.05 *** 0.01) compress nogap a
浙江大学【面板数据分析与STATA应用】——第三讲内生性与工具变量法相关推荐
- 【初级计量经济学】内生性问题——工具变量法(Stata实现)
目录 1. 数据来源以及变量详目 1.1变量一览表 1.2数据描述性统计 2. 模型设定以及初步回归 2.1 OLS 模型 2.2 回归结果 2.3 回归结果 ...
- 【统计学】基本Stata使用手册(4):工具变量法
本篇是本人总结的基本Stata使用手册(4):工具变量法~ 目录 4 工具变量法 4 工具变量法 二阶段最小二乘法(2SLS) .ivregress 2sls y x1 x2 (x3=z1 z2),r ...
- 面板数据分析及stata应用笔记
动态面板数据模型及估计方法 假说里面不要出现显著 文章目录 (一)面板数据基础知识 **一.面板数据的定义** **二.面板数据的分类** **三.面板数据的优缺点** **四.面板数据模型** ** ...
- stata 工具变量法【计量经济系列(七)】
stata 工具变量法[计量经济系列(七)] 文章目录 1. 内生性 2. 工具变量 3. 2SLS (二阶段最小二乘法) 4. 弱工具变量 5. 工具变量外生性的过度识别检验 6. 豪斯曼检验 6. ...
- 慕课面板数据分析与Stata应用—第一章总结
1.面板数据类型 短.长 平衡.非平衡 静.动态 2.估计方法 2.1 混合回归 特征:认为个体异质性不存在,所有的个体估计方程都一致 2.2固定效应 特征:认为个体异质性与解释变量相关 类别 单向: ...
- stata三天写论文!截面工具变量空间计量模型实战
stata三天写论文!截面工具变量空间计量模型实战
- 计量经济学及Stata应用 陈强 第十章工具变量法习题10.6
10.6生育行为如何影响劳动力供给?具体来说,如果妇女多生一位小孩,其劳动力供给将下降多少?本题使用来自美国1980年人口普查的数据集fertility_small.dta进行估计.此数据集包含美国2 ...
- 计量经济学及Stata应用 陈强 第十章工具变量法习题10.5
10.5使用数据集acemoglu.dta复制Acemoglu et al.(2001)的部分结果.该数据集包含64个曾为欧洲殖民地的国家,主要变量为log pgp95(1995年人均GDP,购买力平 ...
- Stata:工具变量法(IV)也不难呀!
原文链接:https://www.lianxh.cn/news/b4c8cc6e6d1ba.html 目录 引言 1. IV 估计法的基本思想 2. IV 估计式 3. 2SLS 3.1 2SLS 原 ...
最新文章
- SDK Instrumentation创建一个Note的实例
- python 打开文件,读取文件内容
- IntelliJ IDEA连接数据库时报错:服务器返回无效的时区,需要设置 ‘‘serverTimezone‘‘ 属性。
- appium启动app失败_Appium-Desktop Capability 配置及启动App演示
- 表哥的access入门 资源_理想的产品管理系统之二-找到Access
- Hash 函数的现状,2012
- ZStack的VPC特性详解及实战
- Xcap使用教程--创建、发送和分析报文
- windows下Redis多实例部署
- java中Map集合的四种遍历方式
- js高级开发:气泡坦克(js对象,属性)
- wkhtmltopdf工具将html转换为pdf
- Qt::WA_TransparentForMouseEvents 了解一下
- 什么是数据安全,为什么它很重要?
- 奔驰c260语言设置方法图解,奔驰C260L灯光使用方法,C260L灯光开关图解说明
- 1.1 项目经理是干什么的
- WPS表格 下拉列表 两级下拉列表联动 多级下拉列表联动
- Matlab配平操作trim
- C/C++语言问题——某年某月的天数是多少?
- 【Arduino实验02 LED流水灯】