全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
112910 78
2013-05-17

进行回归分析往往要看边际影响,
对于线性模型边际影响就是其系数;
但对于许多非线性模型边际影响是不等于系数值的,特别是如:logitprobittobitmlogitologit等模型

stata中求边际影响的命令,早期是用mfx
但到stata11以后,命令为margins(虽然mfx命令也可以用,但是功能不如margins强大);
margins 命令很强大,正因为强大,所以,命令也变的复杂,可以处理许多情况(手册上面有详细的例子),


对于不同的模型采用的参数也是不同的,因此,在用margins求边际影响的时候,一定要查看该命令的帮助,看看该命令可以用哪些参数。


每个模型估计的命令都有postestimation   ,即估计后可以做的。

如:

mlogit 命令就有对应的  postestimation -- Postestimation tools formlogit




几个简单的例子


*例子1:线性回归模型

sysuse auto, clear

reg price weight rep78

margins, dydx(*)    /*对所有变量求*/

margins, dydx(rep78)      /*rep78求边际影响*/

margins, dydx(rep78)    at(weight==2000)  /*rep78求边际影响在weight=1000的时候*/



*****************************************************************************

*例子2 probit 模型

sysuse auto, clear

probit foreign price weight rep78

margins, dydx(*)          /*对所有变量求*/

margins, dydx(rep78)      /*rep78求边际影响*/

margins, dydx(rep78)    at(weight==2000)  /*rep78求边际影响在weight=1000的时候*/


*************************************************************************

*例子3 mlogit 模型

sysuse auto, clear

tab rep78                         /*rep785种值*/

mlogit rep78 mpg displ, base(5)      /*第五个为参照组,具体模型看计量经济学*/


*mlogit回归结果有多个方程,因此,需要计算不同方程的边际影响

*计算rep78分别等于1,2,3时的边际影响

margins, dydx(*) predict(outcome(1))

margins, dydx(*) predict(outcome(2))

margins, dydx(*) predict(outcome(3))



*****************************************************************************

*例子4;ivprobit 模型


webuse laborsup

ivprobit fem_work fem_educ kids (other_inc= male_educ)


*计算平均边际影响: 关键是后面的选项 predict(pr)

* pr calculates the probability of a positive outcome..


margins, dydx(*)  predict(pr)



*****************************************************************************

*例子5;tobit  模型

sysuse auto,clear

generate wgt =weight/100

tobit mpg wgt price,ll(17) ul(24)

margins, dydx(*)

margins, dydx(*)predict(ystar(17,24))

margins, dydx(*)predict(    e(17,24))

*****************************************************************************

*例子6;xtlogit  模型*面板数据的其他命令,也是类似,一定要去查manual里面的介绍
webuse union,clear
xtlogit union age grade i.not_smsa south##c.year

margins,dydx(*)  predict(pu0)


*****************************************************************************





二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-5-19 01:28:07
蓝色版主的学习心得,自然是要支持的。

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-5-19 02:59:41
下面这个link讲了一下关于marginal effect的一点东西

http://www3.nd.edu/~rwilliam/stats3/Margins02.pdf

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-5-22 11:21:00
请问一下,如果用ivprobit回归,然后进行margins, dydx(*)  predict(pr),如何实现outreg2的数据结果导出?
按照help outreg2中显示的,导不出来边际的影响。具体见下面的例子。

. sysuse auto, clear
(1978 Automobile Data)

. ivprobit   foreign  rep78 head (mpg=weight)

Fitting exogenous probit model

Iteration 0:   log likelihood = -42.400729  
Iteration 1:   log likelihood = -24.995592  
Iteration 2:   log likelihood = -24.582512  
Iteration 3:   log likelihood = -24.579895  
Iteration 4:   log likelihood = -24.579895  

Fitting full model

Iteration 0:   log likelihood = -207.15925  
Iteration 1:   log likelihood = -201.15982  
Iteration 2:   log likelihood = -198.77163  
Iteration 3:   log likelihood = -198.51748  
Iteration 4:   log likelihood = -198.51323  
Iteration 5:   log likelihood = -198.51322  

Probit model with endogenous regressors           Number of obs   =         69
                                                  Wald chi2(3)    =      51.30
Log likelihood = -198.51322                       Prob > chi2     =     0.0000

------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         mpg |   .1571301    .033205     4.73   0.000     .0920495    .2222108
       rep78 |   .4777998   .2596776     1.84   0.066    -.0311589    .9867584
    headroom |   .1380609   .2613758     0.53   0.597    -.3742262     .650348
       _cons |  -6.137811   1.308358    -4.69   0.000    -8.702145   -3.573477
-------------+----------------------------------------------------------------
     /athrho |  -1.233284   .2873209    -4.29   0.000    -1.796423   -.6701455
    /lnsigma |   1.227139   .0851257    14.42   0.000     1.060296    1.393982
-------------+----------------------------------------------------------------
         rho |  -.8435293   .0828801                     -.9464343   -.5850756
       sigma |   3.411456   .2904024                      2.887225     4.03087
------------------------------------------------------------------------------
Instrumented:  mpg
Instruments:   rep78 headroom weight
------------------------------------------------------------------------------
Wald test of exogeneity (/athrho = 0): chi2(1) =    18.42 Prob > chi2 = 0.0000

. margins, dydx(*) predict(pr)

Average marginal effects                          Number of obs   =         69
Model VCE    : OIM

Expression   : Probability of positive outcome, predict(pr)
dy/dx w.r.t. : mpg rep78 headroom weight

------------------------------------------------------------------------------
             |            Delta-method
             |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         mpg |   .0330182   .0077151     4.28   0.000     .0178968    .0481395
       rep78 |   .1004013   .0501077     2.00   0.045      .002192    .1986106
    headroom |   .0290111   .0560268     0.52   0.605    -.0807995    .1388217
      weight |          0  (omitted)
------------------------------------------------------------------------------

. outreg2 using myfile333, tstat  bdec(3)   tdec(3) asterisk(tstat) parenthesis(tstat)   ctitle(m
> argins) see
Hit Enter to continue.
dir : seeout

outreg2的输出结果为:(仍然是Ivprobit的结果,而不是margins
的结果),请各位高人指教,这是什么原因?
不胜感激!

v1        v2        v3        v4        v5
        (1)        (2)        (3)        (4)
VARIABLES        foreign        mpg        athrho        lnsigma
                               
mpg        0.157                       
        (4.732)***                       
rep78        0.478        0.571               
        (1.840)*        (1.249)               
headroom        0.138        -0.157               
        (0.528)        (-0.284)               
weight                -0.006               
                (-8.704)***               
Constant        -6.138        36.778        -1.233        1.227
        (-4.691)***        (12.875)***        (-4.292)***        (14.416)***
Observations        69        69        69        69


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-5-22 11:44:28
sysuse auto, clear
ivprobit   foreign  rep78 head (mpg=weight)
outreg2 using d:\ivprobit.xls, excel tstat  bdec(3)   tdec(3) asterisk(tstat) parenthesis(tstat)   ctitle(beta) replace

margins, dydx(*) predict(pr) post
outreg2 using d:\ivprobit.xls, excel tstat  bdec(3)   tdec(3) asterisk(tstat) parenthesis(tstat)   ctitle(margins)


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-5-22 11:45:08
changfang4421 发表于 2013-5-22 11:21
请问一下,如果用ivprobit回归,然后进行margins, dydx(*)  predict(pr),如何实现outreg2的数据结果导出? ...


. sysuse auto, clear
(1978 Automobile Data)

. ivprobit   foreign  rep78 head (mpg=weight)

Fitting exogenous probit model

Iteration 0:   log likelihood = -42.400729  
Iteration 1:   log likelihood = -24.995592  
Iteration 2:   log likelihood = -24.582512  
Iteration 3:   log likelihood = -24.579895  
Iteration 4:   log likelihood = -24.579895  

Fitting full model

Iteration 0:   log likelihood = -207.15925  
Iteration 1:   log likelihood = -201.16016  
Iteration 2:   log likelihood =  -198.7716  
Iteration 3:   log likelihood = -198.51747  
Iteration 4:   log likelihood = -198.51323  
Iteration 5:   log likelihood = -198.51322  

Probit model with endogenous regressors           Number of obs   =         69
                                                  Wald chi2(3)    =      51.30
Log likelihood = -198.51322                       Prob > chi2     =     0.0000

------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         mpg |   .1571301    .033205     4.73   0.000     .0920495    .2222108
       rep78 |   .4777998   .2596776     1.84   0.066    -.0311589    .9867584
    headroom |   .1380609   .2613758     0.53   0.597    -.3742262     .650348
       _cons |  -6.137811   1.308358    -4.69   0.000    -8.702145   -3.573477
-------------+----------------------------------------------------------------
     /athrho |  -1.233284   .2873209    -4.29   0.000    -1.796423   -.6701455
    /lnsigma |   1.227139   .0851257    14.42   0.000     1.060296    1.393982
-------------+----------------------------------------------------------------
         rho |  -.8435293   .0828801                     -.9464343   -.5850756
       sigma |   3.411456   .2904024                      2.887225     4.03087
------------------------------------------------------------------------------
Instrumented:  mpg
Instruments:   rep78 headroom weight
------------------------------------------------------------------------------
Wald test of exogeneity (/athrho = 0): chi2(1) =    18.42 Prob > chi2 = 0.0000

. outreg2 using d:\ivprobit.xls, excel tstat  bdec(3)   tdec(3) asterisk(tstat) parenthesis(tstat)   ctitle(b
> eta) replace
d:\ivprobit.xls
dir : seeout

.
. margins, dydx(*) predict(pr)  post

Average marginal effects                          Number of obs   =         69
Model VCE    : OIM

Expression   : Probability of positive outcome, predict(pr)
dy/dx w.r.t. : mpg rep78 headroom weight

------------------------------------------------------------------------------
             |            Delta-method
             |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         mpg |   .0330182   .0077151     4.28   0.000     .0178968    .0481395
       rep78 |   .1004013   .0501077     2.00   0.045      .002192    .1986106
    headroom |   .0290111   .0560268     0.52   0.605    -.0807995    .1388217
      weight |          0  (omitted)
------------------------------------------------------------------------------

. outreg2 using d:\ivprobit.xls, excel tstat  bdec(3)   tdec(3) asterisk(tstat) parenthesis(tstat)   ctitle(m
> argins)
d:\ivprobit.xls
dir : seeout










 (1)(2)(3)(4)(5)
VARIABLESforeignmpgathrholnsigmamargins
      
mpg0.157


0.033

(4.732)***


(4.280)***
rep780.4780.571

0.100

(1.840)*(1.249)

(2.004)**
headroom0.138-0.157

0.029

(0.528)(-0.284)

(0.518)
weight
-0.006





(-8.704)***



Constant-6.13836.778-1.2331.227


(-4.691)***(12.875)***(-4.292)***(14.416)***








Observations6969696969
z-statistics in parentheses





*** p<0.01, ** p<0.05, * p<0.1




























ivprobit.xls
大小:(8.55 KB)

 马上下载





二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群