Announcement

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

  • Creating percentiles

    Hello.

    I want to create percentiles in Stata and I am using this command xtile pct = variablename, n(100)

    However, I want to see also the distribution of the population in this format
    0,991
    0,992
    0,993
    0,994
    0,995
    0,996
    0,997
    0,998
    0,999
    0,9991
    0,9992
    0,9993
    0,9994
    0,9995
    0,9996
    0,9997
    0,9998
    0,9999
    0,99991
    0,99992
    0,99993
    0,99994
    0,99995
    0,99996
    0,99997
    0,99998
    0,99999
    How can I divide my last percentile as this example?

  • #2
    Like this:
    Code:
    sort variablename
    gen quantile = _n/_N
    by variablename quantile, sort: replace quantile = quantile[_N] // DEAL WITH TIES
    But remember that there is no way to get a fine-grained division into quantiles unless you have a large enough sample. To get a 0.999999 quantile requires a sample size of at least 100,000 observations with distinct values.

    Comment


    • #3
      See also https://www.stata.com/support/faqs/s...ing-positions/

      Clyde Schechter's code doesn't treat tails symmetrically, as a comparison with the above will show. That may not matter if you have an enormous sample size, which is certainly needed to calculate those extreme quantiles accurately.

      Comment

      Working...
      X