如何使用estadd通过边距获得估算的p值?

时间:2014-10-30 00:33:57

标签: stata

这个问题与另一个问题有关,我问CrossValidated
我正在Stata中运行多个逻辑模型,并希望使用margins存储模型的结果和一些后估计。使用ado estout有两种相对简单的可能性(参见documentation)。但是,两者都缺少z统计或某些摘要统计。这是一个例子:

. webuse acmemanuf, clear

. // estadd
. eststo est1: qui logit acceptable i.temp y

. qui estadd margins, dydx(*)

. eststo est2: qui logit acceptable i.temp y i.pressure

. qui estadd margins, dydx(*)

. // margins, post
. qui logit acceptable i.temp y, nolog

. eststo est3: qui margins, dydx(*) post

. qui logit acceptable i.temp y i.pressure, nolog

. eststo est4: qui margins, dydx(*) post

. // Wrong t-statistics using "estadd"
. esttab est1 est2, cells("margins_b t") margin pr2 aic    
----------------------------------------------------------------
                      (1)                       (2)             
               acceptable                acceptable             
                margins_b            t    margins_b            t
----------------------------------------------------------------
acceptable                                                      
1.temp                  0            .            0            .
2.temp            .122275     .8468373     .2366358     1.448193
3.temp           .1028261     .6194538     .0930619     .6025044
y                .0171374     2.752288     .0202188     2.993524
1.pressure                                        0            .
2.pressure                                -.2384807    -1.454117
----------------------------------------------------------------
N                      49                        49             
pseudo R-sq         0.233                     0.271             
AIC                 55.48                     55.10             
----------------------------------------------------------------
Marginal effects

. // Loosing summary statistics using "margins, post" 
. esttab est3 est4, cells("b t") margin pr2 aic

----------------------------------------------------------------
                      (1)                       (2)             

                        b            t            b            t
----------------------------------------------------------------
1.temp                  0            .            0            .
2.temp            .122275     .8600932     .2366358     1.723335
3.temp           .1028261     .6322357     .0930619     .6126009
y                .0171374     4.103384     .0202188     5.118546
1.pressure                                        0            .
2.pressure                                -.2384807    -1.729937
----------------------------------------------------------------
N                      49                        49             
pseudo R-sq                                                     
AIC                     .                         .             
----------------------------------------------------------------
Marginal effects

我想有一个表格,显示第一个表格中的汇总统计数据和上面示例第二个表格中的z统计数据。

修改
我写了一个小型本地程序来完成这项工作,其结果可以由esttab捕获。请注意,对于生成t统计信息而不是z统计信息的模型,必须稍微修改程序代码。如果有人可以将estadd中的程序集成到webuse acmemanuf, clear program define margzp tempname rtab tempname tmargins_z tempname tmargins_p mat `rtab' = r(table) mat `tmargins_z' = `rtab'["z", 1..(colsof(`rtab')-1)] mat `tmargins_p' = `rtab'["pvalue", 1..(colsof(`rtab')-1)] estadd matrix margins_z = `tmargins_z' estadd matrix margins_p = `tmargins_p' end eststo: logit acceptable i.temp y estadd margins, dydx(*) margzp * eststo: logit acceptable i.temp y i.pressure estadd margins, dydx(*) margzp * esttab, cells((margins_b(fmt(3) star pvalue(margins_p)) /// margins_z)) pr2 aic bic star(+ 0.10 * 0.05 ** 0.01 *** 0.001) /// postfoot(`"{hline @width}"' /// `"Marginal effects, standard errors in parentheses"' `"@starlegend"') /// 的子例程中,我很想听到它,因为我只是成功地添加了线性回归模型的结果。这是我的文件:

----------------------------------------------------------------------
                      (1)                          (2)                
               acceptable                   acceptable                
                margins_b       margins_z    margins_b       margins_z
----------------------------------------------------------------------
acceptable                                                            
1.temp              0.000               .        0.000               .
2.temp              0.122           0.847        0.237           1.448
3.temp              0.103           0.619        0.093           0.603
y                   0.017**         2.752        0.020**         2.994
1.pressure                                       0.000               .
2.pressure                                      -0.238          -1.454
----------------------------------------------------------------------
N                      49                           49                
pseudo R-sq         0.233                        0.271                
AIC                 55.48                        55.10                
BIC                 63.05                        64.56                
----------------------------------------------------------------------
Marginal effects, standard errors in parentheses
+ p<0.10 * p<0.05, ** p<0.01, *** p<0.001

其中给出了下表:

{{1}}

1 个答案:

答案 0 :(得分:1)

这是一个例子。我并非100%确定我合并了你想要的一切。如果没有,请添加您希望表格显示的示例:

. sysuse auto
(1978 Automobile Data)

. eststo, title(Index): logit foreign price mpg

Iteration 0:   log likelihood =  -45.03321  
Iteration 1:   log likelihood = -36.627434  
Iteration 2:   log likelihood = -36.462562  
Iteration 3:   log likelihood =  -36.46219  
Iteration 4:   log likelihood = -36.462189  

Logistic regression                               Number of obs   =         74
                                                  LR chi2(2)      =      17.14
                                                  Prob > chi2     =     0.0002
Log likelihood = -36.462189                       Pseudo R2       =     0.1903

------------------------------------------------------------------------------
     foreign |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       price |    .000266   .0001166     2.28   0.022     .0000375    .0004945
         mpg |   .2338353   .0671449     3.48   0.000     .1022338    .3654368
       _cons |  -7.648111   2.043673    -3.74   0.000    -11.65364   -3.642586
------------------------------------------------------------------------------
(est1 stored)

. eststo, title(AMEs): margins, dydx(*) post

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

Expression   : Pr(foreign), predict()
dy/dx w.r.t. : price mpg

------------------------------------------------------------------------------
             |            Delta-method
             |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       price |   .0000428   .0000166     2.57   0.010     .0000102    .0000754
         mpg |   .0376126   .0074022     5.08   0.000     .0231045    .0521207
------------------------------------------------------------------------------
(est2 stored)

. esttab, drop(_cons)

--------------------------------------------
                      (1)             (2)   
                  foreign                   
--------------------------------------------
main                                        
price            0.000266*      0.0000428*  
                   (2.28)          (2.57)   

mpg                 0.234***       0.0376***
                   (3.48)          (5.08)   
--------------------------------------------
N                      74              74   
--------------------------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001