Announcement

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

  • Is there a command for creating deciles by date?

    I understand the command xtile ... , nq(10) can create deciles based on the entire data-set being aggregated, but as far as I am aware, it cannot be used in conjunction with a bysort.

    For example, I want to create deciles based on the month of June, where my data is monthly and ranges from 1990-2000. What would I do in that case?

  • #2


    Code:
    ssc install egenmore
    for an xtile() function with a by() option.

    Comment


    • #3
      You can also use astile.
      Code:
      ssc install astile
      help astile
      
      * Create 5 groups of firms based on their market value in each year 
      
      webuse grunfeld
      
      bys year: astile size5=mvalue, nq(5)
      
      . list in 1/10
      
           +----------------------------------------------------------+
           | company   year   invest   mvalue   kstock   time   size5 |
           |----------------------------------------------------------|
        1. |       5   1935    39.68    157.7    183.2      1       2 |
        2. |       3   1935     33.1   1170.6     97.8      1       4 |
        3. |       1   1935    317.6   3078.5      2.8      1       5 |
        4. |       4   1935    40.29    417.5     10.5      1       4 |
        5. |       9   1935    26.63    290.6      162      1       3 |
           |----------------------------------------------------------|
        6. |       7   1935    24.43      138    100.2      1       1 |
        7. |       8   1935    12.93    191.5      1.8      1       2 |
        8. |      10   1935     2.54    70.91      4.5      1       1 |
        9. |       6   1935    20.36      197      6.5      1       3 |
       10. |       2   1935    209.9   1362.4     53.8      1       5 |
           +----------------------------------------------------------+
      For deciles, just replace nq(5) with nq(10).
      astile is much faster, especially useful in large datasets.

      Note: Since you have mentioned that
      I want to create deciles based on the month of June
      astile also offers qc() option. qc is an abbreviation for quantiles criterion. This option can be used if the quantile breakpoints need to be based on a subset of the data, and then observations in the entire data set (off course in the toused sample as created by the [if] [in] options) are assigned to these breakpoints.

      Last edited by Attaullah Shah; 11 Oct 2019, 23:20.
      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