0
votes

I run two regressions for which I would like to show the 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)

I tried to create a matrix to fill it but was not successful:

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

Ultimately, I would like to export the results with the community-contributed Stata command outreg2:

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

1 Answers

0
votes

The following works for me:

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