我想margins
在一个marginsplot中绘制由命令产生的边距,但来自不同的margins
估计。重要限制:这些系数在相同的最小值和最大值以内,因此是可比较的。我怎么做?
这是一个代码示例:
webuse nhanes2, clear
tnbreg psu weight hdresult iron, iterate(5) // I am using this regression type so I stick with it here
我知道我可以将所有页边距响应图放在一个图中
margins, dydx(*)
marginsplot, horizontal xline(0) yscale(reverse) recast(scatter)
但是实际上我margins
为每个回归器分别运行三个命令,因为如果该回归器发生变化,我想比较效果。因此,代码是
foreach var in weight hdresult iron {
* Procedure to get the numbers for margins right
quietly summarize `var '
local max = r(max)
local step = round(r(max)/6)
quietly margins, at(`cvar'=(1(`step')`max'))
marginsplot, title("") ytitle("")
}
这给了我三个单独的文件。但是,我当然希望所有图形都在一个单独的图中以不同的颜色显示。
有什么建议怎么做?
基于@RobertoFerrer的使用建议,combomarginsplot
我现在正在欺骗该程序包(感谢Nicholas Winter):
webuse nhanes2, clear
* Run regressions
foreach var in weight hdresult iron {
* Trick: always regress on the same variable
gen testvar = `var'
* Any regression where testvar enters first - the identical variable will be omitted
tnbreg psu ///
testvar weight hdresult iron, iterate(5)
* Procedure to get the numbers for margins right
quietly summarize testvar
local max = r(max)
local step = round(r(max)/6)
* Margins post estimation
quietly margins, at(testvar=(1(`step')`max')) saving(margins_`var', replace)
* Drop testvar so that it can be reassigned within the loop
drop testvar
}
* Combine the margins graph information
combomarginsplot margins_weight margins_hdresult margins_iron, labels("Weight" "HDrestul" "Iron")
当然,只比较相同范围内的变量系数才有意义。此限制不是我原来的答案的一部分-对此感到抱歉。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句