Announcement

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

  • Deciles and re-scale variables

    Hi,

    Does anyone know how to first rank firms into deciles based on a certain variable and re-scale them to range between zero and one?

    Thanks!!

  • #2
    If you are doing these deciles within some grouping of firms (say an industry, or certain years) then you can either install the -egenmore- package from SSC and use -by grouping_variable: egen decile = xtile(certain_variable), nq(10)-, or you can install -runby- and write a little program that uses the -xtile- command to calculate the deciles in a single group, and then -runby- that program -by(grouping_variable)-.

    If this is just an overall calculatoin of deciles for the entire data set, with no grouping variables, then the -xtile- command by itself will suffice.

    To re-scale them to range between 0 and 1,

    Code:
    gen scaled_decile = (decile-1)/9

    Comment


    • #3
      Thank you very much!! It works perfectly

      Comment


      • #4
        For deciles over a grouping variable, you can use astile (from SSC). Unlike Stata's official xtile, astile is byable. astile handles by-group calculations super efficiently. For example, the difference in time when used with bys and without bys is usually a few seconds in a million observations and 1000 groups.

        Code:
        * Download from SSC
        
        ssc instll astile
        
        help astile
        
        * An example of deciles over groups
        * Download example dataset
        
            . webuse grunfeld
         
        * create 10 groups of firms based on their market value in each year 
         
        bys year: astile size10=mvalue, nq(10)
        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