Stata:在 Excel 输出中将不同回归的结果排列在彼此下方
Stata: Arrange results of different regressions below each other in Excel output
我是 运行 一堆双变量回归,我想在 Excel 文件中报告。生成的 table 目前看起来像这样:
var1 coef1a coef1b
(tvalue1a)(tvalue1b)
var2 coef2a coef2b
(tvalue2a) (tvalue2b) ...
其中...
代表另外50个变量。我知道这对 outreg
有很多要求,但是有什么方法可以得到像这样的输出:
var1 coef1a coef1b
(tvalue1a)(tvalue1b)
var2 coef2a coef2b
(tvalue2a) (tvalue2b)
...
虽然这两个系数来自不同的回归?
我只对系数和 t 值感兴趣,不需要记录其他统计数据(常数、R2 等)。
可重现的例子:
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'
}
您是否尝试过来自 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
我是 运行 一堆双变量回归,我想在 Excel 文件中报告。生成的 table 目前看起来像这样:
var1 coef1a coef1b
(tvalue1a)(tvalue1b)
var2 coef2a coef2b
(tvalue2a) (tvalue2b) ...
其中...
代表另外50个变量。我知道这对 outreg
有很多要求,但是有什么方法可以得到像这样的输出:
var1 coef1a coef1b
(tvalue1a)(tvalue1b)
var2 coef2a coef2b
(tvalue2a) (tvalue2b)
...
虽然这两个系数来自不同的回归?
我只对系数和 t 值感兴趣,不需要记录其他统计数据(常数、R2 等)。
可重现的例子:
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'
}
您是否尝试过来自 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