首页 文章

如何使用coefplot为同一模型中的不同系数设置不同的颜色

提问于
浏览
0

我正在使用 coefplot 绘制分类变量的回归系数 . 我的回归模型是一个简单的线性模型,其中一个分类变量有7种类型(一种城市类型)作为自变量,一个连续变量(种群密度)作为因变量 .

我想以图形方式显示我的回归系数如何根据七种类型的城市变化,使用核心图 . 我可以很容易地使用:

'coefplot density cities'

enter image description here

但是现在我想为我的自变量(城市类型)的每个类别使用不同的颜色自定义我的情节 .

我希望有七种不同颜色的点,而不是只有一个 .

有关如何做的任何建议?

1 回答

  • 0

    这是一种非常笨重的手动方式:

    #delimit;
    sysuse auto, clear;
    label define rep78 1 "One Repair" 2 "Two Repairs" 3 "Three Repairs" 4 "Four Repairs" 5 "Five Repairs";
    lab val rep78 rep78;
    
    reg price ib1.rep78 c.weight;
    est store M1;
    
    coefplot
    (M1, keep(2.rep78) mcolor(navy) ciopts(color(navy)))
    (M1, keep(3.rep78) mcolor(orange) ciopts(color(orange)))
    (M1, keep(4.rep78) mcolor(maroon) ciopts(color(maroon)))
    (M1, keep(5.rep78) mcolor(emerald) ciopts(color(emerald)))
    , legend(off) offset(0) note("Efects Relative to 1 Repair", span);
    

    得到这个:

    enter image description here

    您可以使用以下内容添加常量:

    (M1, keep(_cons) rename(_cons = "One Repair (Base)") mcolor(navy) ciopts(color(navy)))
    

相关问题