coefplot 可能有更优雅的方法来执行此操作,但在有人发布该解决方案之前:您可以使用矩阵强制 coefplot 以您想要的方式行事。具体来说,定义与唯一协变量一样多的矩阵,每个矩阵的维度是#眼镜x 3. 每行将包含特定模型规格的协变量估计系数、较低 CI 和较高 CI。
这是有效的,因为 coefplot 将相同的颜色分配给与关联的所有数量plot(由coefplot 的帮助文件定义)。plot通常是来自estimates store 的存储模型,但通过使用矩阵技巧,我们已经转移plot等效于特定的协变量,为所有模型规格的协变量提供相同的颜色。 coefplot 然后查看矩阵的行以找到标记轴的“分类”信息。在这种情况下,我们矩阵的行对应于一个存储的模型,为我们提供轴标签的规范。
// (With macros for the specification names + # of coefficient
// matrices, for generalizability)
clear *
webuse auto
// Declare model's covariates
local covariates trunk mpg
// Estimate the various model specifs
local specNm = "" // holder for gph axis labels
forval v=2/5 {
// Estimate the model
reg price `covariates' if rep78==`v'
// Store specification's name, for gph axis labels
local specNm = "`specNm' reg_`v'"
// For each covariate, pull its coefficient + CIs for this model, then
// append that row vector to a new matrix containing that covariate's
// b + CIs across all specifications
matrix temp = r(table)
foreach x of local covariates{
matrix `x' = nullmat(`x') (temp["b","`x'"], temp["ll","`x'"], temp["ul","`x'"])
}
}
// Store the list of 'new' covariate matrices, along w/the
// column within this matrix containing the coefficients
global coefGphList = ""
foreach x of local covariates{
matrix rownames `x' = `specNm'
global coefGphList = "$coefGphList matrix(`x'[,1])"
}
// Plot
coefplot $coefGphList, ci((2 3)) vertical