我想使用分类曝光变量运行几个线性回归并将结果输出到 Excel 表。
当曝光连续时,下面的代码可以正常工作。但是,对于分类曝光,代码仅输出第一行结果,而不是永远的曝光级别。
*Code which works for continuous exposures
sysuse auto.dta
describe
summ
postfile temp str40 exp str40 outcome adjusted N beta se lci uci pval using ///
"\test.dta", replace
foreach out in price weight {
foreach exp in i.rep78 {
foreach adjust in 1 {
if `adjust'==1 local adjusted "mpg"
xi: reg `out' `exp' `adjusted'
local N = e(N)
matrix table=r(table)
local beta = table[1,1]
local se = table[2,1]
local lci = table[5,1]
local uci = table[6,1]
local pval=table[4,1]
post temp ("`out'") ("`exp'") (`adjusted') (`N') (`beta') (`se') ///
(`lci') (`uci') (`pval')
}
}
}
postclose temp
use "\test.dta", clear
export excel using "\test.xlsx", firstrow(variables)
上面的代码只产生一行,估计第一级rep78
何时应该产生 4 行(rep78
是一个 5 级分类变量)。