Announcement

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

  • Problem of producing plotting CDF with "cumul" command

    Dear all,

    I have a data containing student's grades, and I want to plot cumulative distributions of grades for two samples of students. I use the following:

    cumul grade_avg, generate(gucum)
    sort gucum
    cumul grade_avg if substr(opc_ed01,1,1)=="6",generate(gufirst)
    twoway (line gucum grade_avg) (line gufirst grade_avg), ytitle(CDF of grade average) ylabel(, angle(horizontal)) xtitle(grade average)

    Then in the graph, the first cdf (blue) fits my expectation, but the second cdf (red) looks very strange, with kinks going down. I thought cumulative distribution should always be non-decreasing?

    For the first cdf, without using "sort gucum" I get similar plot like the red one (with kinks going down). Then I suppose the problem is with sort the value? So how could I combine the two graphs while sorting both gucum and gufirst (on the y-axis)?

    Many thanks in advance.
    Last edited by Li Chen; 02 Nov 2014, 11:30.

  • #2
    This kind of sequence works.

    Code:
    sysuse auto, clear
    sort mpg foreign
    cumul mpg, gen(cu_mpg)
    cumul mpg if foreign, gen(cu_foreign)
    line cu_mpg mpg, c(J) || line cu_foreign mpg, c(J)

    Comment


    • #3
      Originally posted by Nick Cox View Post
      This kind of sequence works.

      Code:
      sysuse auto, clear
      sort mpg foreign
      cumul mpg, gen(cu_mpg)
      cumul mpg if foreign, gen(cu_foreign)
      line cu_mpg mpg, c(J) || line cu_foreign mpg, c(J)
      Thanks a lot!

      Comment

      Working...
      X