复旦大学stata精华学习笔记(2)

2019-03-04 13:42

工具变量估计 命令格式:

.ivregress esitimator depvar [varlist1] [varlist2=varlist_iv] [if] [in] [weight][,options]

其中,estimator包括2sls,gmm,liml三种。varlist1为模型中的外生变量,varlist2为模型中的内生变量,varlist_iv为模型中的工具变量。 Nonconstant 不包括常数项 Hascons 用户自己设定常数项 CMM 选项:

wmatrix(wmtype) robust,cluster clustvar,hac kernel, unadjusted center 权数矩阵采用中心矩 igmm 采用迭代GMM估计

eps(#) 参数收敛标准。默认值为eps(le-6)

weps(#) 权数矩阵的收敛标准。默认值为w eps(le-6)

Vce(vcetype) unajusted,robust,cluster clustvar,bootstrap,jackknife,hac kernel

level(#)置信区间

First 输出第一阶段的估计结果 Small 小样本下的自由度调整

.estat firststage [,all forcenonrobust]

该命令给出第一阶段的估计结果以及各种统计量,包括排除外生变量的相关性检验。All选项给出所有的拟合优度统计量。如果模型存在多个内生变量,则stata给出R2、偏R2、调整的R2 、F统计量;如果模型存在多个内生变量,则stata给出Shea偏R2和调整的偏R2。

forcenonrobust给出最小特征值统计量及其临界值,即使采用稳健估计(这一检验的假设条件是误差项为独立正态分布)。

estat overid[,lag(#) forceweights forcenonrobust]

该命令给出了过度识别约束检验。如果使用2sls估计估计,则Stata给Sargan’s(1958)和Basman’s(1960)卡方统计量,这也是Wooldridge’(1995)稳健得分检验。如果采用liml估计方法,则stata给出Anderson and Rubin’s(1950) 卡方统计量以及Basmann F统计量;如果采用GMM估计,则stata给出hansen’s(1982)J统计量。Lags(#)用于计算得分检验的HAC(异方差自相

关一致)统计量的过程中进行去噪时设定滞后阶数。如果设定lag(0),则表示不进行去噪处理。默认选择为lag(1)。这一选择仅使用于2sls估计方法和设定vce(hac)选项情况。

Forceweight 表示即使采用aweights,pweights或iweights也进行检验。Stata仅对于fweights的情况进行检验,其他权数所得到临界值可能不准确。 Forcenonrobust 指在2sls或LIML估计中即使采用稳健标准差也进行Sargan and Basmann检验(这一检验的假设的假设条件是误差项为独立正态分布)。 例子:

log(wage)=a+b*educ+c*exper+d*expersq+u

怀疑模型教育(educ)具有内生性问题,利用父母接受教育的年数(fatheduc,motheduc)作educ的工具变量估计上述模型。 (1)利用2SLS估计模型

.ivregress 2sls lwage exper expersq (educ=fatheduc motheduc),first 第一阶段回归结果为:

educhat=9.1+0.19fatheduc+0.16motheduc+0.05exper

(21.34) (5.62) (4.39) (1.12) - 0.001expersq (-0.84) 第二阶段的估计结果为:

lwagehat=0.05+0.06educ+0.04exper-0.001expersq

(0.12) (1.95) (5.29) (-2.24) (2)检验educ的内生性

.quietly ivreg iwage exper expersq {educ=fatheduc motheduc} .est store IV_reg

.quietly regress lwage exper expersq educ .est store LS_reg .hausman IV_reg LS_reg

可以得到hausman估计量=2.7,P值=0.44。接受原假设,即educ是外生的。 (3)进行过度识别的约束检验 .estat overid

可得Sargan统计量=0.38,P值=0.54接受原假设。 面板数据估计

首先对面板数据进行声明: 前面是截面单元,后面是时间标识: tsset company year tsset industry year

产生新的变量:gen newvar=human*lnrd 产生滞后变量Gen fiscal(2)=L2.fiscal 产生差分变量Gen fiscal(D)=D.fiscal

描述性统计:

xtdes :对Panel Data截面个数、时间跨度的整体描述 Xtsum:分组内、组间和样本整体计算各个变量的基本统计量 xttab 采用列表的方式显示某个变量的分布

Stata中用于估计面板模型的主要命令:xtreg

xtreg depvar [varlist] [if exp] , model_type [level(#) ] Model type 模型

be Between-effects estimator fe Fixed-effects estimator re GLS Random-effects estimator pa GEE population-averaged estimator

mle Maximum-likelihood Random-effects estimator

主要估计方法:

xtreg: Fixed-, between- and random-effects, and population-averaged linear models xtregar:Fixed- and random-effects linear models with an AR(1) disturbance xtpcse :OLS or Prais-Winsten models with panel-corrected standard errors xtrchh :Hildreth-Houck random coefficients models

xtivreg :Instrumental variables and two-stage least squares for panel-data models

xtabond:Arellano-Bond linear, dynamic panel data estimator xttobit :Random-effects tobit models

xtlogit : Fixed-effects, random-effects, population-averaged logit models

xtprobit :Random-effects and population-averaged probit models

xtfrontier :Stochastic frontier models for panel-data xtrc gdp invest culture edu sci health social admin,beta

xtreg命令的应用:

声明面板数据类型:tsset sheng t

描述性统计:xtsum gdp invest sci admin 1.固定效应模型估计:

xtreg gdp invest culture sci health admin techno,fe

固定效应模型中个体效应和随机干扰项的方差估计值(分别为sigma u 和sigma e),二者之间的相关关系(rho)

最后一行给出了检验固定效应是否显著的F 统计量和相应的P 值

2.随机效应模型估计:

xtreg gdp invest culture sci health admin techno,re 检验随机效应模型是否优于混合OLS 模型: 在进行随机效应回归之后,使用xttest0

检验得到的P 值为0.0000,表明随机效应模型优于混合OLS 模型 3. 最大似然估计Ml:

xtreg gdp invest culture sci health admin techno,mle

Hausman检验

Hausman检验究竟选择固定效应模型还是随机效应模型: 第一步:估计固定效应模型,存储结果

xtreg gdp invest culture sci health admin techno,fe est store fe

第二步:估计随机效应模型,存储结果

xtreg gdp invest culture sci health admin techno,re est store re

第三步:进行hausman检验 hausman fe

Hausman检验量为:

H=(b-B)′[Var(b)-Var(B)]-1(b-B)~x2(k) Hausman统计量服从自由度为k的χ2分布。当H大于一定显著水平的临界值时,我们就认为模型中存在固定效应,从而选用固定效应模型,否则选用随机效应模型

如果hausman检验值为负,说明的模型设定有问题,导致Hausman 检验的基本假设得不到满足,遗漏变量的问题,或者某些变量是非平稳等等 可以改用hausman检验的其他形式: hausman fe, sigmaless

对于固定效应模型的异方差检验和序列相关检验:

Xtserial gdp invest culture sci health admin techno 异方差检验:

xtreg gdp invest culture sci health admin techno,fe

xttest3 (Modified Wald statistic for groupwise heteroskedasticity in fixed effect model)

随机效应模型的序列相关检验:

xtreg gdp invest culture sci health admin techno,re Xttest1

Xttest1用于检验随机效应(单尾和双尾) 、一阶序列相关以及两者的联合显著 检验结果表明存在随机效应和序列相关,而且对随机效应和序列相关的联合检验也非常显著

可以使用广义线性模型xtgls对异方差和序列相关进行修正:

xtgls gdp invest culture sci health admin techno, panels(hetero),修正异方差

xtgls gdp invest culture sci health admin techno, panels(correlated),修正依横截面而变化的异方差

xtgls gdp invest culture sci health admin techno, panels(hetero) corr(ar1),修正异方差和一阶序列相关ar(1)


复旦大学stata精华学习笔记(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:通用技术会考模拟试卷答案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: