I am trying to add a 45-degree line to my cumulative distribution plot. I couldn't figure out how to do this using the 'distplot' command, as it is not a twoway graph command.
I know that I could compute the cumulative distributions separately for each category, stack them and then create a twoway cumulative distribution plot myself. However, I am looking for a simpler method to add the 45-degree line without having to calculate the cumulative distribution manually.
sysuse auto
distplot price, over(foreign)
I guess what you mean is that you want a reference line that goes from (min, 0) to (max, 1) where min and max are the extremes of the variables in question and 0 and 1 are the extremes of cumulative probability. That won't in general have a slope of 45 degrees. But the point is then to compare the cumulative distribution with that of a uniform (rectangular, flat) distribution with the same range as the data.
You can add a call to twoway function
in the addplot()
option. You would need to be careful about specifying the equation of the line.
Official command quantile
supports such a line. As the author of distplot
and qplot
, community-contributed commands from the Stata Journal, I have never seen much point to adding such lines, even as an option.