Stata如何绘制峰峦图和小提琴图?

除了Stata社区命令joyplot,巴德学院利维经济研究所的Fernando Rios-Avila也开发了类似的Stata社区命令joy_plot,用以快捷绘制峰峦图,它还可以绘制小提琴图。
安装Stata社区命令joy_plot的Stata代码如下:


ssc install joy_plot, replace
*安装依赖命令
ssc install color_style, replace

准备数据


use http://fmwww.bc.edu/RePEc/bocode/o/oaxaca.dta,clear
gen mstatus=single+2*married+3*divorced
label define mstatus 1 Single 2 Married 3 Divorced
label values mstatus mstatus


绘制上图的Stata代码如下:


joy_plot lnwage, over(mstatus) dadj(1) legend(cols(3))  violin legend(off) iqr

绘制上图的Stata代码如下:


qui:color_style, list  // <--- This Loads the palettes into memory
joy_plot lnwage, over(educ) dadj(3)  /// as before, with 3x the hight adjusment
bwadj2(.5) right /// setting text to the right, and using half of the automatic bandwidth
colorpalette(vangogh1, opacity(80)) lcolor(white) // and using custome palette vangogh1