Stata 将逻辑回归输出写入文本文件

Stata 将逻辑回归输出写入文本文件,stata,logistic-regression,Stata,Logistic Regression,我正在Windows 7上使用Stata 12运行逻辑回归 我想将优势比、p>|z |和[95%配置间隔]输出值写入文本文件 下面您可以找到我尝试过的代码: use "http://dss.princeton.edu/training/Panel101.dta" , clear file open TABLES using "values.txt", write replace //create temporary text file write TABLES "the_var ,Odds

我正在Windows 7上使用Stata 12运行逻辑回归

我想将
优势比
p>|z |
[95%配置间隔]
输出值写入文本文件

下面您可以找到我尝试过的代码:

use "http://dss.princeton.edu/training/Panel101.dta" , clear

file open TABLES using "values.txt", write replace //create temporary text 
file write TABLES "the_var ,Odds , P_value, 95%CI" _n // columns headers

logistic y_bin x1 // run the model

matrix list e(b) //list the coficients output
mat values = e(b) //attach the coeficient matrix to a matrix values

local the_var= "x1" // get the variable name
local logODD=values[1,1] //get the log odds

//the problem is extracting these values
local P_value=P>|z|
local  95%CI= [95% Conf. Interval]

file write TABLES "`the_var' , `Odds' , `P_value' ,  `95%CI'"  _n

我也尝试过社区贡献的命令
estout
esttab
,但没有成功,因为返回的
e(b)
矩阵不包含我想要的结果。

您需要的结果由
r()中的
logistic
命令返回:

通过一些操作和
esttab
的帮助,很容易导出所有内容:

matrix A = ( A[1, 1...] \ A[4..6, 1...] )'

esttab matrix(A) using A.txt, mlabels(none)

type A.txt
----------------------------------------------------------------
                        b       pvalue           ll           ul
----------------------------------------------------------------
y_bin                                                           
x1               1.637293     .4443672     .4628176     5.792192
_cons            2.951956     .0246714     1.148056     7.590261
----------------------------------------------------------------
另一种方法是社区贡献的命令
mat2text

mat2txt, matrix(A) saving(A) 

type A.txt
        b       pvalue  ll      ul      
y_bin:x1          1.637293       .44436718       .46281759        5.792192      
y_bin:_cons      2.9519564       .02467141       1.1480562       7.5902614      
您可以按如下方式下载和使用这两种软件:

ssc install estout

ssc install estout
ssc install mat2txt