首页 文章

Stata:在Excel输出中将不同回归的结果排列在彼此之下

提问于
浏览
0

我正在运行一堆双变量回归,我想在Excel文件中报告 . 此时生成的表格如下所示:

var1    coef1a    coef1b
        (tvalue1a)(tvalue1b)
var2                          coef2a     coef2b
                              (tvalue2a) (tvalue2b) ...

... 代表另外50个变量 . 我知道这要问 outreg ,但是有一些方法可以获得如下输出:

var1  coef1a    coef1b
      (tvalue1a)(tvalue1b)
var2  coef2a     coef2b
      (tvalue2a) (tvalue2b) 
...

虽然这两个系数来自不同的回归?

我只对系数和t值感兴趣,不需要记录其他统计数据(常量,R2等) .

Reproducible example:

clear all
ssc install outreg2
sysuse auto

local path yourpath
cd "`path'"
local vars mpg rep78 headroom trunk weight length
local replace replace

foreach i of local vars{
reg price `i'
outreg2 using "$path\example.xls", ctitle("var1") long `replace'
local replace
reg price `i', robust
outreg2 using "$path\example.xls", ctitle("var1") long `replace'
}

1 回答

  • 1

    你有没有试过SSC的 ESTOUT 模块?

    sysuse auto, clear
    
    eststo: quietly regress price weight mpg
    eststo: quietly regress price weight mpg foreign
    
    esttab
    

    您可以保存为.csv文件 . 例如,参见

    http://repec.org/bocode/e/estout/esttab.html#esttab010

    这有更多的例子 .

    编辑

    ESTOUT 的作者Ben Jann编写了一个程序,可以将模型结果与 esttab 一起使用 . 程序下面有例子:

    . capt prog drop appendmodels
    
    . *! version 1.0.0  14aug2007  Ben Jann
    . program appendmodels, eclass
      1.     // using first equation of model
    .     version 8
      2.     syntax namelist
      3.     tempname b V tmp
      4.     foreach name of local namelist {
      5.         qui est restore `name'
      6.         mat `tmp' = e(b)
      7.         local eq1: coleq `tmp'
      8.         gettoken eq1 : eq1
      9.         mat `tmp' = `tmp'[1,"`eq1':"]
     10.         local cons = colnumb(`tmp',"_cons")
     11.         if `cons'<. & `cons'>1 {
     12.             mat `tmp' = `tmp'[1,1..`cons'-1]
     13.         }
     14.         mat `b' = nullmat(`b') , `tmp'
     15.         mat `tmp' = e(V)
     16.         mat `tmp' = `tmp'["`eq1':","`eq1':"]
     17.         if `cons'<. & `cons'>1 {
     18.             mat `tmp' = `tmp'[1..`cons'-1,1..`cons'-1]
     19.         }
     20.         capt confirm matrix `V'
     21.         if _rc {
     22.             mat `V' = `tmp'
     23.         }
     24.         else {
     25.             mat `V' = ///
    >             ( `V' , J(rowsof(`V'),colsof(`tmp'),0) ) \ ///
    >             ( J(rowsof(`tmp'),colsof(`V'),0) , `tmp' )
     26.         }
     27.     }
     28.     local names: colfullnames `b'
     29.     mat coln `V' = `names'
     30.     mat rown `V' = `names'
     31.     eret post `b' `V'
     32.     eret local cmd "whatever"
     33. end
    
    . sysuse auto
    (1978 Automobile Data)
    
    . eststo b1: quietly regress price weight
    
    . eststo b2: quietly regress price mpg
    
    . eststo b3: quietly regress price foreign
    
    . eststo bivar: appendmodels b1 b2 b3
    
    . esttab b1 b2 b3 bivar, mtitles
    

    资料来源:http://repec.org/bocode/e/estout/advanced.html#advanced901

相关问题