2017-04-04 110 views
0

我想用用戶編寫的命令esttab(st0085_2)給我一個迴歸估計表。我下面的代碼只給出最後一列(消費)。我該如何改變它,以便每列都是來自列表'outcomelist'的不同因變量?Stata:esttab只顯示foreach循環的最後一列嗎?

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

我在評論之前寫的,但我認爲這構成了回答你的問題:

它看起來像你寫在每一個循環宏,所以它只會儲存最後一。

也許試着改變global estimates1 est_`var'global estimates1 $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