Announcement

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

  • Create four quartiles

    I have a longitudinal data set that contains data from 2013, 2014 and 2015. There is one variable that contains the number of employed physicians. I would like to create a separate categorical variable that contains 4 quartiles on the number of employed physicians. Please help and let me know how can I do that. Thank you.
    Last edited by Soumya Upadhyay; 30 Mar 2017, 16:29.

  • #2
    -help pctile-

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      -help pctile-
      I wrote the following code:
      pctile hsp_quartile=ftehsp,nquantiles(4)

      But, it doesn't work. I am looking to create a categorical variable that contains 0,1,2,3 as four categories that represent four quartiles on ftehsp variable. Please help.

      Comment


      • #4
        Part of your confusion is terminological. What you really want is a variable identifying quantile groups, not quantiles. Remember: there are 3 quantiles -- the 3 values that define 4 quantile groups. (Similarly, there are 9 deciles defining 10 decile groups, and so on.) Whatever, Clyde Schechter directed you to exactly the right place, i.e. help pctile. Look at the discussion for xtile.

        Comment


        • #5
          Originally posted by Soumya Upadhyay View Post

          I wrote the following code:
          pctile hsp_quartile=ftehsp,nquantiles(4)

          But, it doesn't work. I am looking to create a categorical variable that contains 0,1,2,3 as four categories that represent four quartiles on ftehsp variable. Please help.
          Just do:

          Code:
          xtile hsp_quartile=ftehsp,n(4)
          and if you're married to using 0 as start number just do some replace'ing of hsp_quartile

          Comment


          • #6
            If you have a large data set and want some speed advantage, you can use astile from SSC. astile is much faster compared to Stata's official xtile
            Code:
            ssc install astile
            astile hsp_quartile=ftehsp,nq(4)
            And if you want to decrement quantile categories by one, then after generating hsp_quartile, do the following
            Code:
            replace hsp_quartile = hsp_quartile -1
            Regards
            --------------------------------------------------
            Attaullah Shah, PhD.
            Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
            FinTechProfessor.com
            https://asdocx.com
            Check out my asdoc program, which sends outputs to MS Word.
            For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

            Comment

            Working...
            X