楼主: 蓝色
101925 75

[学习心得] 关于求边际影响mfx和margins的命令   [推广有奖]

贵宾

泰斗

33%

还不是VIP/贵宾

-

TA的文库  其他...

统计软件和图书资源

Stata FAQ and Econometrics

威望
13
论坛币
1096771 个
通用积分
77228.5828
学术水平
3447 点
热心指数
3906 点
信用等级
2743 点
经验
469733 点
帖子
11687
精华
5
在线时间
20148 小时
注册时间
2004-7-15
最后登录
2024-4-24

初级热心勋章 初级信用勋章 初级学术勋章 中级学术勋章 中级热心勋章 中级信用勋章 高级热心勋章 高级信用勋章

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

进行回归分析往往要看边际影响,
对于线性模型边际影响就是其系数;
但对于许多非线性模型边际影响是不等于系数值的,特别是如: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)


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





二维码

扫码加我 拉你入群

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

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

关键词:Margins margin 边际影响 Mar Probability 模型 回归分析 影响

已有 17 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
李龙华 + 1 + 1 + 1 精彩帖子
神仙科学家f + 1 + 1 + 1 精彩帖子
oasises + 1 + 5 + 5 + 5 精彩帖子
蟾宫客1020 + 1 + 1 精彩帖子
奇犽dsp + 100 + 5 + 5 + 3 观点有启发
xddlovejiao1314 + 100 + 5 + 5 + 5 精彩帖子
NullFace + 5 + 1 + 1 + 1 热心帮助其他会员
平凡的平凡 + 1 精彩帖子
clayone + 1 精彩帖子
LIXUANHANK + 5 精彩帖子

总评分: 经验 + 220  论坛币 + 131  学术水平 + 38  热心指数 + 36  信用等级 + 33   查看全部评分

本帖被以下文库推荐

沙发
h3327156 发表于 2013-5-19 01:28:07 |只看作者 |坛友微信交流群
蓝色版主的学习心得,自然是要支持的。

已有 1 人评分热心指数 收起 理由
cherry_wyj + 1 我很赞同

总评分: 热心指数 + 1   查看全部评分

使用道具

藤椅
fgleric 发表于 2013-5-19 02:59:41 |只看作者 |坛友微信交流群
下面这个link讲了一下关于marginal effect的一点东西

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

已有 1 人评分热心指数 收起 理由
crystal8832 + 1 热心帮助其他会员

总评分: 热心指数 + 1   查看全部评分

使用道具

板凳
changfang4421 发表于 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)


已有 3 人评分经验 学术水平 热心指数 信用等级 收起 理由
Sunknownay + 2 + 2 + 2 热心帮助其他会员
crystal8832 + 10 + 1 + 1 热心帮助其他会员
peyzf + 20 + 1 pretty cool

总评分: 经验 + 30  学术水平 + 3  热心指数 + 4  信用等级 + 2   查看全部评分

使用道具

地板
蓝色 发表于 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)



使用道具

7
changfang4421 发表于 2013-5-22 13:47:27 |只看作者 |坛友微信交流群
谢版主,学习了!

使用道具

8
chensongcc 在职认证  发表于 2013-6-25 16:41:25 |只看作者 |坛友微信交流群
请问在tobit回归模型中,在求边际效应时,margins,dydx(*) predict(ystar(17,24))和margins, dydx(*)predict(    e(17,24)),这两个命令的含义由什么差别?

使用道具

9
蓝色 发表于 2013-6-26 00:34:29 |只看作者 |坛友微信交流群
chensongcc 发表于 2013-6-25 16:41
请问在tobit回归模型中,在求边际效应时,margins,dydx(*) predict(ystar(17,24))和margins, dydx(*)predic ...
你需要看看计量经济学理论关于tobit模型的边际影响有三种的greene等人计量经济学书上都有介绍
      e(a,b)        E(y|a < y < b)
      ystar(a,b)    E(y*),y* = max{a, min(y,b)}


stata的manual上面有介绍e(a,b) ystar(a,b)的含义


Title

    [R] tobit postestimation -- Postestimation tools for tobit


Description

    The following postestimation commands are available after tobit:

    Command          Description
    -----------------------------------------------------------------------------------------------------------------------------
        contrast     contrasts and ANOVA-style joint tests of estimates
        estat        AIC, BIC, VCE, and estimation sample summary
        estat (svy)  postestimation statistics for survey data
        estimates    cataloging estimation results
        hausman      Hausman's specification test
        lincom       point estimates, standard errors, testing, and inference for linear combinations of coefficients
        linktest     link test for model specification
    (1) lrtest       likelihood-ratio test
        margins      marginal means, predictive margins, marginal effects, and average marginal effects
        marginsplot  graph the results from margins (profile plots, interaction plots, etc.)
        nlcom        point estimates, standard errors, testing, and inference for nonlinear combinations of coefficients
        predict      predictions, residuals, influence statistics, and other diagnostic measures
        predictnl    point estimates, standard errors, testing, and inference for generalized predictions
        pwcompare    pairwise comparisons of estimates
        suest        seemingly unrelated estimation
        test         Wald tests of simple and composite linear hypotheses
        testnl       Wald tests of nonlinear hypotheses
    -----------------------------------------------------------------------------------------------------------------------------
    (1) lrtest is not appropriate with svy estimation results.


Syntax for predict

        predict [type] newvar [if] [in] [, statistic nooffset]

        predict [type] {stub*|newvar_reg newvar_sigma} [if] [in] , scores

    statistic       Description
    -----------------------------------------------------------------------------------------------------------------------------
    Main
      xb            linear prediction; the default
      stdp          standard error of the linear prediction
      stdf          standard error of the forecast
      pr(a,b)       Pr(a < y < b)
      e(a,b)        E(y|a < y < b)
      ystar(a,b)    E(y*),y* = max{a, min(y,b)}

    -----------------------------------------------------------------------------------------------------------------------------
    These statistics are available both in and out of sample; type predict ... if e(sample) ... if wanted only for the estimation  sample.
    stdf is not allowed with svy estimation results.

    where a and b may be numbers or variables; a missing (a > .) means minus infinity, and b missing (b > .) means plus infinity;
      see missing.


Pages from 计量经济分析(第五版)威廉-H-格林_Page_1.jpg Pages from 计量经济分析(第五版)威廉-H-格林_Page_2.jpg Pages from 计量经济分析(第五版)威廉-H-格林_Page_3.jpg Pages from 计量经济分析(第五版)威廉-H-格林_Page_4.jpg Pages from 计量经济分析(第五版)威廉-H-格林_Page_5.jpg



已有 4 人评分经验 学术水平 热心指数 信用等级 收起 理由
blueena + 1 + 1 热心帮助其他会员
Sunknownay + 2 + 2 + 2 热心帮助其他会员
crystal8832 + 10 + 1 + 1 热心帮助其他会员
chensongcc + 1 + 1 + 1 热心帮助其他会员

总评分: 经验 + 10  学术水平 + 5  热心指数 + 5  信用等级 + 3   查看全部评分

使用道具

10
chensongcc 在职认证  发表于 2013-6-26 10:16:04 |只看作者 |坛友微信交流群
蓝色 发表于 2013-6-26 00:34
你需要看看计量经济学理论关于tobit模型的边际影响有三种的greene等人计量经济学书上都有介绍
      e(a ...
谢谢。。。

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 14:48