如何使用outreg2

时间:2019-06-26 17:02:57

标签: stata

我进行了两个回归分析,我想展示它们的r-squared

logit y c.x1 c.x2
quietly est store e1
local r1 = e(r2_p)

logit y c.x1 c.x2 c.x3
quietly est store e2
local r2 = e(r2_p)

我试图创建一个矩阵来填充它,但是没有成功:

mat t1=J(1,2,0) //Defining empty matrix with 2 columns 1 row
local rsq `r*'  //Trying to store r1 and r2 as numeric

local a=1
forval i=1/2{
    mat t1[`i'+1,`a']= `r*' // filling each row, one at a time, this fails
    loc ++a
}
mat li t1

最终,我想使用社区贡献的 Stata命令outreg2导出结果:

outreg2 [e*] using "myfile", excel replace addstat(Adj. R^2:, `rsq') 

1 个答案:

答案 0 :(得分:1)

以下对我有用:

webuse lbw, clear

logit low age smoke
outreg2 using "myfile.txt", replace addstat(Adj. R^2, e(r2_p)) 

logit low age smoke ptl ht ui
outreg2 using "myfile.txt", addstat(Adj. R^2, e(r2_p)) append

type myfile.txt

        (1)     (2)
VARIABLES       low     low

age     -0.0498 -0.0541
        (0.0320)        (0.0339)
smoke   0.692** 0.557
        (0.322) (0.339)
ptl             0.679**
                (0.344)
ht              1.408**
                (0.624)
ui              0.817*
                (0.451)
Constant        0.0609  -0.168
        (0.757) (0.806)

Observations    189     189
Adj. R^2        0.0315  0.0882
Standard errors in parentheses          
*** p<0.01, ** p<0.05, * p<0.1