Stata中一个marginsplot中多个边距的图形
我希望在一个marginsplot中绘制由Stata中一个marginsplot中多个边距的图形,plot,stata,margins,Plot,Stata,Margins,我希望在一个marginsplot中绘制由margins命令生成的边距,但不同的margins估计。重要限制:这些系数在相同的最小值和最大值范围内,因此具有可比性。我该怎么做 下面是一个代码示例: webuse nhanes2, clear tnbreg psu weight hdresult iron, iterate(5) // I am using this regression type so I stick with it here 我知道我可以把所有的利润率响应图放在一个图中 m
margins
命令生成的边距,但不同的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)
但事实上,我分别为每个回归器运行了三个边距命令,因为我想比较回归器变化时的效果。因此,守则是
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("")
}
这给了我三个独立的文件。但我希望所有的线条都在一个图形中,当然是不同的颜色
有什么建议吗?使用combomarginsplot
(以及帮助文件):
combomarginsplot
是用户编写的命令,由Nicholas Winter编写。您可以在运行时安装它
ssc install combomarginsplot
使用combomarginsplot
(以及帮助文件中的内容):
combomarginsplot
是用户编写的命令,由Nicholas Winter编写。您可以在运行时安装它
ssc install combomarginsplot
基于@RobertoFerrer使用combomarginsplot
的建议,我现在正在欺骗该软件包(感谢Nicholas Winter):
当然,比较所有在同一范围内的变量的系数才有意义。这个限制不是我最初回答的一部分-对此表示抱歉。基于@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")