0
votes

After running a regression, I want to save the output (variable names, coefficients, standard errors and P values) in an Excel spreadsheet. However, when I attempt to do this, I just get the coefficients.

Below is my code attempt:

local regressors x1 x2 x3
logit y `regressors'
putexcel set output_table.xlsx, replace
putexcel A1 = matrix(e(b))

Please note that I am using a computer that does not have access to the internet, so I cannot use external libraries.

1

1 Answers

1
votes

The e(b) matrix only contains the coefficients, whereas matrix r(table) has all the required information.

Consider this toy example using Stata's lbw toy dataset:

webuse lbw, clear
logit low age lwt i.race smoke

matrix list e(b)

e(b)[1,7]
           low:        low:        low:        low:        low:        low:        low:
                                    1b.          2.          3.                        
           age         lwt        race        race        race       smoke       _cons
y1  -.02250707  -.01250169           0     1.23121   .94359458   1.0544326   .33012671

matrix list r(table)

r(table)[9,7]
               low:        low:        low:        low:        low:        low:        low:
                                        1b.          2.          3.                        
               age         lwt        race        race        race       smoke       _cons
     b  -.02250707  -.01250169           0     1.23121   .94359458   1.0544326   .33012671
    se   .03416876   .00638428           .   .51710617   .41620012   .37997875   1.1076071
     z  -.65870331  -1.9581978           .   2.3809618   2.2671656   2.7749778   .29805398
pvalue   .51008631   .05020681           .    .0172675   .02338011   .00552055   .76566196
    ll   -.0894766  -.02501465           .   .21770056   .12785734   .30968791  -1.8407433
    ul   .04446246   .00001128           .   2.2447195   1.7593318   1.7991772   2.5009968
    df           .           .           .           .           .           .           .
  crit    1.959964    1.959964    1.959964    1.959964    1.959964    1.959964    1.959964
 eform           0           0           0           0           0           0           0

The following will write everything in the output_table Excel spreadsheet, including the variable names:

matrix A = r(table)
matrix A = A[1..2,1...] \ A[4,1...]
matrix coleq A = ""

matrix list A

A[3,7]
                                        1b.          2.          3.                        
               age         lwt        race        race        race       smoke       _cons
     b  -.02250707  -.01250169           0     1.23121   .94359458   1.0544326   .33012671
    se   .03416876   .00638428           .   .51710617   .41620012   .37997875   1.1076071
pvalue   .51008631   .05020681           .    .0172675   .02338011   .00552055   .76566196

putexcel set output_table.xlsx, replace
putexcel A1 = matrix(A), names