Goal: Plot kernel densities for two samples with confidence intervals.
Following the documentation of 'kdens' at http://fmwww.bc.edu/repec/bocode/k/kdens.html I am able to plot kernel densities for two subsamples in the following two ways (using Stata 14 MP on macOS Mojave):
I am also able to use 'kdens' to plot one kernel density with its confidence interval:
Unfortunately, the combination of these approaches is unsuccessful.
The second approach can be modified for partial success. The following plots both kernels and the confidence interval only for the primary 'kdens':
I believe that a solution is possible by analogy to this discussion of a similar problem using 'lpoly' on Statalist in 2008:
https://www.stata.com/statalist/arch.../msg00675.html
Following the documentation of 'kdens' at http://fmwww.bc.edu/repec/bocode/k/kdens.html I am able to plot kernel densities for two subsamples in the following two ways (using Stata 14 MP on macOS Mojave):
Code:
use http://www.stata-press.com/data/r7/trocolen.dta generate byte g = uniform()<.5 * first alternative: twoway kdens length if g==1 || kdens length if g==0 * second alternative: kdens length if g==1, addplot(kdens length if g==0)
Code:
kdens length if g==0 , ci
Code:
. twoway kdens length if g==1, ci || kdens length if g==0, ci option ci not allowed r(198); . kdens length if g==1, ci addplot(kdens length if g==0, ci) (n2() set to 316) (bandwidth = 51.439651) option ci not allowed r(198);
Code:
kdens length if g==1, ci addplot(kdens length if g==0)
https://www.stata.com/statalist/arch.../msg00675.html
Comment