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-)

Subject   Re: st: RE: Graphing multiple cdf's in the same graph (using either -distplot- or -cdfplot-)
Date   Wed, 6 Mar 2013 12:14:44 -0500

Many thanks to all of you for your helpful comments. I wound up using 
cumul to calculate the CDFs, then plotting them using twoway line. But I 
like Nick's suggestion of stacking them into a single variable as well.


Max Livingston
Sr. Research Analyst
Microeconomic Studies
Research and Statistics Group
Federal Reserve Bank of New York
(212) 720-7894

From:   Nick Cox <>
Date:   03/05/2013 02:58 PM
Subject:        Re: st: RE: Graphing multiple cdf's in the same graph 
(using either -distplot- or -cdfplot-)
Sent by:

-distplot- (SJ) can be used with such data as follows


label define vars 1 "var1" 2 "var2"
stack var1 var2, into(vars) clear
drop if missing(vars)
label val _stack vars
distplot vars, over(_stack)

On Tue, Mar 5, 2013 at 10:43 AM, Nick Cox <> wrote:
> Thanks to David for the explanation. However, although -distplot- is
> available from SSC, it
> was first published in the STB and subsequent updates have continued
> in the Stata Journal.


> All that said, no version of -distplot- supports what Max wants, given
> its treatment of missing values and as David and Maarten have
> explained you need to do that otherwise.
> Nick
> On Mon, Mar 4, 2013 at 10:26 PM, David Radwin <> 
>> Please remember to cite sources for user-written programs. -distplot- 
>> by Nick Cox and -cdfplot- is by Adrian Mander. Both are available from
>> SSC.
>> You can create your own CDFs using -cumul- and then plot them using
>> -twoway line-. The following example is based on this message by Nick 
>> sysuse nlsw88, clear
>> gen wageodd=wage if mod(_n,2)==1 // odd-numbered observations
>> gen wageeven=wage if mod(_n,2)==0 // even-numbered observations
>> kdensity wageodd, gen(a b)
>> cumul b, gen(cb)
>> kdensity wageeven, g(c d)
>> cumul d, gen(cd)
>> twoway (line cb b, sort ) (line cd d, sort lpattern(dash))
> Max.Livingston
>>> I'm trying to plot two cdf's on the same axis. -distplot- allows me to
>> do
>>> this (simple example: distplot line var1 var2, lc(red blue)  ) , but
>>> there's a wrinkle in my data that makes this more complicated. The 
>> is
>>> arranged such that var1 and var2 are never both non-missing. That is,
>> for
>>> every observation where var1 exists, var2 is missing, and vice versa. 
>> am
>>> able to graph this using kernel density:
>>> twoway (kdensity var1, lp(solid) lc(blue))
>>>  || (kdensity var2, lp(solid) lc(red))
>>> But I can't seem to find a similar implementation for -distplot- (or
>>> -cdfplot- for that matter). If anyone has any ideas, I would greatly
>>> appreciate it.
*   For searches and help try:

This e-mail message, including attachments, is for the sole use of the intended recipient(s) and may contain confidential or proprietary information.  If you are not the intended recipient, immediately contact the sender by reply e-mail and destroy all copies of the original message.
*   For searches and help try:

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