. qui: reg lwage educ exper. . est store m1. . est table m1 Variable m1 educ .08756591 exper .0233035 _cons 7.6413948 . . qui: reg lwage educ exper male. . est store m2. . est table m1 m2 Variable m1 m2 educ .08756591 .08600261 exper .0233035 .02173852 male .15604851 _cons 7.6413948 7.6038077 . . est stats m1 m2 Model Obs ll(null) ll(model) df AIC BIC m1 9518 -10853.26 -10033.71 3 20073.41 20094.89 m2 9518 -10853.26 -9976.242 4 19960.48 19989.13 Note: N=Obs used in calculating BIC; see [R] BIC note. . est table m1 m2, b(%9.4f) se stats(N r2 F ll) Variable m1 m2 educ 0.0876 0.0860 0.0025 0.0025 exper 0.0233 0.0217 0.0008 0.0008 male 0.1560 0.0145 _cons 7.6414 7.6038 0.0361 0.0360 N 9518 9518 r2 0.1582 0.1683 F 894.0682 641.7474 ll -1.00e+04 -9.98e+03 legend: b/se
31
一个更好的结果呈现命令:esttab,是用户写的非官方命令,用时需要先安装。 esttab [ namelist ] [ using filename ] [ , options ] qui: reg lwage educ exper, vce(robust)
estadd scalar pvalue=Ftail(e(df_r), e(df_m), e(F)) est store m1
qui: reg lwage educ exper male, vce(robust) estadd scalar pvalue=Ftail(e(df_r), e(df_m), e(F)) est store m2
esttab m1 m2 using result.rtf, replace b(.4f) scalars(F pvalue) mtitles star(* .10 ** .05 *** .01)
. esttab m1 m2 (1) (2) lwage lwage educ 0.0876*** 0.0860*** (35.44) (34.96) exper 0.0233*** 0.0217*** (30.35) (27.98) male 0.156*** (10.75) _cons 7.641*** 7.604*** (211.76) (210.98) N 9518 9518 t statistics in parentheses* p<0.05, ** p<0.01, *** p<0.001
esttab m1 m2, scalar(N r2 F ll) star(* .1 ** .05 *** .01)
32
. esttab m1 m2, scalar(N r2 F ll) star(* .1 ** .05 *** .01) (1) (2) lwage lwage educ 0.0876*** 0.0860*** (35.44) (34.96) exper 0.0233*** 0.0217*** (30.35) (27.98) male 0.156*** (10.75) _cons 7.641*** 7.604*** (211.76) (210.98) N 9518 9518 r2 0.158 0.168 F 894.1 641.7 ll -10033.7 -9976.2 t statistics in parentheses* p<.1, ** p<.05, *** p<.01
estimate drop 将内存中的保存的估计结果清除掉。
estpost tabstat wage lwage age male educ exper, by(ownership) statistics(n mean sd) columns(statistics) listwise eststo sum1
esttab sum1, main(mean) aux(sd) nostar unstack noobs nonote nomtitle nonumber
33
3.3 预测
predict [type] newvar [if] [in] [, single_options] xb 预测值
residual残差,在使用预测命令时,最好加上条件if e(sample)以保证预测时所使用的样本和估计时使用的一样。 比较命令 predict y, xb
predict yhat if e(sample), xb 的不同
. predict y(option xb assumed; fitted values)(74 missing values generated). predict yhat if e(sample)(option xb assumed; fitted values)(587 missing values generated). sum y yhat Variable Obs Mean Std. Dev. Min Max y 10031 9.110567 .3162193 7.603807 10.24171 yhat 9518 9.124406 .3104919 7.603807 10.24171
边际效应(marginal effects)
margins [marginlist] [if] [in] [weight] [, response_options options]
response_options Description Main predict(pred_opt) estimate margins for predict, pred_opt expression(pnl_exp) estimate margins for pnl_exp dydx(varlist) estimate marginal effect of variables in varlist eyex(varlist) estimate elasticities of variables in varlist dyex(varlist) estimate semielasticity -- d(y)/d(lnx) eydx(varlist) estimate semielasticity -- d(lny)/d(x) continuous treat factor-level indicators as continuous
options Description 用于求解边际影响,可以用于求解导数、弹性、半弹性等,特别适用非线性模型边际效应的计 Main算。用于线性回归或非线性回归之后。 grand add the overall margin; default if no marginlist At at(atspec) estimate margins at specified values of covariates atmeans estimate margins at the means of covariates asbalanced treat all factor variables as balanced if/in/over over(varlist) estimate margins at unique values of varlist subpop(subspec) estimate margins for subpopulation Within within(varlist) estimate margins at unique values of the nesting factors in34 varlist SE vce(delta) estimate SEs using delta method; the default vce(unconditional) estimate SEs allowing for sampling of covariates nose do not estimate SEs
. margins, dydx(educ exper male)Average marginal effects Number of obs = 9518Model VCE : OLSExpression : Linear prediction, predict()dy/dx w.r.t. : educ exper male Delta-method dy/dx Std. Err. z P>|z| [95% Conf. Interval] educ .0860026 .0024601 34.96 0.000 .0811808 .0908244 exper .0217385 .000777 27.98 0.000 .0202156 .0232615 male .1560485 .0145154 10.75 0.000 .1275988 .1844982
老版本命令mfx
mfx [compute] [if] [in] [, options] mfx replay [, level(#)] options Description Model predict(predict_option) calculate marginal effects (elasticities) for predict_option varlist(varlist) calculate marginal effects (elasticities) for varlist dydx calculate marginal effects; the default eyex calculate elasticities in the form of d(lny)/d(lnx) dyex calculate elasticities in the form of d(y)/d(lnx) eydx calculate elasticities in the form of d(lny)/d(x) nodiscrete treat dummy (indicator) variables as continuous nose do not calculate standard errors
mfx
mfx, varlist(educ) mfx, eyex
3.4 Stata 资源
关键参考资料:[U] User’s Guide 和 [R] regress, [R] regress postestimation, [R] estimates, [R] predict, [R] test。
用户自写程序estout。
35