Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: Graphing multiple cdf's in the same graph (using either -distplot- or -cdfplot-)

From   Travis Smith <>
Subject   Re: st: RE: Graphing multiple cdf's in the same graph (using either -distplot- or -cdfplot-)
Date   Tue, 5 Mar 2013 10:29:05 -0600

Hi Max,

Here is an example of what I use.  The key is to use -scatter- with
the "stairstep" option -c(J)- and there is no need to plot the markers
so I use the additional option -ms(none)-.

I added a bonus for you: the KS test.

********************* Start *********************
* Plotting two CDFs:
sysuse nlsw88, clear
* sortting may be unnecessary
sort wage union
* store F(wage) values for union
cumul wage if union == 1, generate(Fx) equal
* ... and non-union workers
cumul wage if union == 0, generate(Gx) equal

twoway (scatter Fx wage, sort c(J) ms(none)) ///
(scatter Gx wage, sort c(J) ms(none)), ///
ytitle("Density") xtitle("Hourly Wage") ///
legend( pos(5) ring(0) col(1) ///
label(1 "Union") label(2 "Non-union") )

* BONUS!!  Are the CDFs significantly different?
ksmirnov wage, by(union)
* Yes, reject the null of equality.

********************* End *********************

Hope that helps you out,
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index