Announcement

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

  • Collapse a variable for every percentile

    Hi,

    I have a dataset of wages at the individual level. I want to collapse this dataset at every percentile.

    I could simply code

    collapse p(1) p1wage=wage p(2) p2wage=wage p(3) ... p(98) p98wage = wage p(99) p99wage = wage,

    but I am looking for a more efficient way to do so, if it exist.

    Thank you in advance,

    Étienne

  • #2
    Have you considered something like:

    Code:
    pctile pc=wage, nq(100) gen(newp)
    drop if mi(pc)
    keep pc newp
    Last edited by Carole J. Wilson; 21 Jan 2019, 09:46.
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      It seems to me that the collapsing you use simply would produce the 1-100 percentiles of your data.

      If this is what you want to calculate, the 1-100 percentiles of your data, a simpler way to obtain the calculation is :

      Code:
      centile wage , centile(1/100)

      Comment


      • #4
        Note that pctile and centile will produce the same result only if you add the option -altdef- to pctile.
        Stata/MP 14.1 (64-bit x86-64)
        Revision 19 May 2016
        Win 8.1

        Comment


        • #5
          That is indeed what I'm looking for, thanks a lot!

          Comment


          • #6
            Originally posted by Carole J. Wilson View Post
            Note that pctile and centile will produce the same result only if you add the option -altdef- to pctile.
            Thank you for this very useful clarification, Carole !

            I did notice that the results -centile- produces are slightly different from the results -summarize, detail- produces at few percentiles.

            Comment

            Working...
            X