Dear Statalists,
I am working on a loop aimed at plotting overlying kernel density plots for all the categories of some variables in my dataset. I managed to make it in this way:
foreach var in v1 v2 v3 v4 {
levelsof(`var'), local(levels`var')
foreach l of local levels`var' {
local call`var' `call`var'' (kdensity y if `var'==`l', bwidth(3))
}
twoway `call`var'', ytitle(Density) ylab(0(0.01)0.05, grid) graphregion(color(white)) xlabel(0(10)100, grid)
}
I have, however, two questions. First, do you think there are more efficient way to produce the same results? And second, I would like to modify the legend of my twoway kernel graph to have the labels of the variables' categories, do you have any suggestion on how to do it? Thanks!
I am working on a loop aimed at plotting overlying kernel density plots for all the categories of some variables in my dataset. I managed to make it in this way:
foreach var in v1 v2 v3 v4 {
levelsof(`var'), local(levels`var')
foreach l of local levels`var' {
local call`var' `call`var'' (kdensity y if `var'==`l', bwidth(3))
}
twoway `call`var'', ytitle(Density) ylab(0(0.01)0.05, grid) graphregion(color(white)) xlabel(0(10)100, grid)
}
I have, however, two questions. First, do you think there are more efficient way to produce the same results? And second, I would like to modify the legend of my twoway kernel graph to have the labels of the variables' categories, do you have any suggestion on how to do it? Thanks!
Comment