Stata将回归系数保存为Excel表格

时间:2017-02-07 11:50:19

标签: stata

运行回归后,我想在Excel电子表格中保存输出(变量名称,系数,标准误差和P值)。当我尝试这样做时,我只得到系数。这是我的尝试。请注意我使用的是无法访问互联网的计算机,因此无法使用外部库。

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

1 个答案:

答案 0 :(得分:1)

e(b)矩阵仅包含系数,而矩阵r(table)具有所有必需的信息。

使用Stata的lbw玩具数据集考虑以下玩具示例:

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

以下内容将在output_table Excel电子表格中写入所有内容,包括变量名称​​

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