Announcement

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

  • How to estimate a percentile difference

    I want to take a difference between the 5th and 95th percentile of the variable.

  • #2
    Code:
    summ variable, detail
    display "Difference = "  =`r(p95)' - `r(p5)'

    Comment


    • #3
      How can I do this for each separate group? Can I use bysort ?

      Comment


      • #4
        Code:
        help egen
        Here's an example.

        Code:
        . sysuse auto, clear
        (1978 automobile data)
        
        . egen p95 = pctile(mpg), p(95) by(foreign)
        
        . egen p5 = pctile(mpg), p(5) by(foreign)
        
        . gen p95Mp5 = p95 - p5
        
        . tabdisp foreign, c(p95 p5 p95Mp5)
        
        ----------------------------------------------
        Car       |
        origin    |        p95          p5      p95Mp5
        ----------+-----------------------------------
         Domestic |         29          14          15
          Foreign |         35          17          18
        ----------------------------------------------

        Comment


        • #5
          How can I do this for each separate group?
          To avoid wasting your own time and that of others, it is best to ask the question you really want answered in the first place, not a simplified version that may draw a simplified, but not useful answer.

          Comment

          Working...
          X