Stata:esttab只显示foreach循环的最后一列?

Stata:esttab只显示foreach循环的最后一列?,stata,Stata,我试图使用用户编写的命令esttab st0085_2来给我一个回归估计表。我下面的代码只给出了最后一列的消耗量。如何更改它,使每列都是列表“结果列表”中不同的从属变量 global outcomelist assets_total output_total expense_total profit_total self_empl income_dep hours_self_age16_65 hours_outside_age16_65 consumption foreach var of

我试图使用用户编写的命令esttab st0085_2来给我一个回归估计表。我下面的代码只给出了最后一列的消耗量。如何更改它,使每列都是列表“结果列表”中不同的从属变量

global outcomelist assets_total output_total expense_total profit_total self_empl income_dep hours_self_age16_65 hours_outside_age16_65 consumption 

foreach var of global outcomelist {
xi: reg `var' i.paire if samplemodel==1 & treatment==1, cluster(demi_paire)
est store est_`var'
global estimates1 est_`var'
}
esttab $estimates1, b(2) se(2) r2 obslast

我在早些时候的评论中写道,但我认为这是对你问题的回答:

看起来每个循环都在宏上写入,所以它只存储最后一个循环

也许可以尝试将全局估计值1 est_u`var更改为全局估计值1$estimates1 est_`var。这样,您将添加到全局文件,而不是覆盖它

我还建议您一般使用本地宏而不是全局宏

我对您所做的工作进行编码的方式如下:

local outcomelist assets_total output_total expense_total profit_total self_empl income_dep hours_self_age16_65 hours_outside_age16_65 consumption 

// reset estimates1 local to empty just in case
local estimates1
foreach var in `outcomelist' {
xi: reg `var' i.paire if samplemodel==1 & treatment==1, cluster(demi_paire)
est store est_`var'
local estimates1 `estimates1' est_`var'
}
esttab `estimates1', b(2) se(2) r2 obslast