Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to overlay empirical cumulative distribution over histogram?

    I am able to get a histogram as well as the empirical cumulative distribution as two separate graphs using the below commands:

    Code:
    hist continuous_variable, freq
    and

    Code:
    cumul continous_variable, gen(ecdf) equal

    However, I have not been able to figure out a way to overlay them on the same plot. I would be grateful for your advice.

    An example of my intended output graph (example sourced from google photos) is appended here:

  • #2
    Some technique:


    Code:
    sysuse auto, clear 
    
    set scheme s1color 
    
    sort mpg 
    
    cumul mpg, gen(cdf)
    
    twoway histogram mpg, width(1) yaxis(1) || line cdf mpg, c(J) yaxis(2)

    Comment


    • #3
      See also https://journals.sagepub .com/doi/pdf/10.1177/1536867X211045583

      Comment


      • #4
        Thanks Nick Cox, works great.

        Comment

        Working...
        X