Announcement

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

  • Error in xtile command-

    Hi all. Please help on the following error.

    I run the following commands to generate variables x1_q to create 5 equal quintiles of x1.

    sort x1
    xtile x1_q=x1, nq(5)


    It should create 5 quantiles based on the variable x1, however, when I browse the data I only firnd 1 2 3 and 5 quintiles. Quintile 4 is missing. Please help. Thanks.

  • #2
    The answer will not be a program error, but a misconception about what xtile can do in the face of ties.

    Consider the examples below. In one case, there are only 3 distinct values, so that is all xtile can do.

    In another case, there are many more distinct values, but xtile can only return 2 quantile bins given the frequency distribution.

    You don't show us your data, but I promise that

    Code:
    tab x1 x1_q
    will underline the difficulty.


    Code:
    . webuse nlswork
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . xtile race5=race, nq(5)
    
    . tab race race5
    
               |       5 quantiles of race
          race |         1          4          5 |     Total
    -----------+---------------------------------+----------
         white |    20,180          0          0 |    20,180 
         black |         0      8,051          0 |     8,051 
         other |         0          0        303 |       303 
    -----------+---------------------------------+----------
         Total |    20,180      8,051        303 |    28,534 
    
    
    . xtile wks_ue5=wks_ue
    
    . tab wks_ue wks_ue5
    
         weeks |
    unemployed | 2 quantiles of wks_ue
     last year |         1          2 |     Total
    -----------+----------------------+----------
             0 |    17,394          0 |    17,394 
             1 |         0        659 |       659 
             2 |         0        704 |       704 
             3 |         0        447 |       447 
             4 |         0        582 |       582 
             5 |         0        207 |       207 
             6 |         0        253 |       253 
             7 |         0        131 |       131 
             8 |         0        307 |       307 
             9 |         0        137 |       137 
            10 |         0        172 |       172 
            11 |         0         72 |        72 
            12 |         0        241 |       241 
            13 |         0        134 |       134 
            14 |         0         59 |        59 
            15 |         0         69 |        69 
            16 |         0         98 |        98 
            17 |         0         71 |        71 
            18 |         0         78 |        78 
            19 |         0         29 |        29 
            20 |         0         89 |        89 
            21 |         0         31 |        31 
            22 |         0         65 |        65 
            23 |         0         15 |        15 
            24 |         0         36 |        36 
            25 |         0         36 |        36 
            26 |         0        117 |       117 
            27 |         0         37 |        37 
            28 |         0         40 |        40 
            29 |         0         26 |        26 
            30 |         0         41 |        41 
            31 |         0         20 |        20 
            32 |         0         50 |        50 
            33 |         0         23 |        23 
            34 |         0         21 |        21 
            35 |         0         33 |        33 
            36 |         0         31 |        31 
            37 |         0         17 |        17 
            38 |         0         14 |        14 
            39 |         0         13 |        13 
            40 |         0         32 |        32 
            41 |         0          9 |         9 
            42 |         0         18 |        18 
            43 |         0         10 |        10 
            44 |         0         23 |        23 
            45 |         0          9 |         9 
            46 |         0         18 |        18 
            47 |         0         12 |        12 
            48 |         0         19 |        19 
            49 |         0          9 |         9 
            50 |         0         18 |        18 
            51 |         0          8 |         8 
            52 |         0         34 |        34 
            53 |         0          3 |         3 
            54 |         0          1 |         1 
            55 |         0          2 |         2 
            56 |         0          2 |         2 
            62 |         0          1 |         1 
            73 |         0          1 |         1 
            75 |         0          1 |         1 
            76 |         0          1 |         1 
    -----------+----------------------+----------
         Total |    17,394      5,436 |    22,830

    Comment


    • #3
      Thank you, Nick Cox, for your detailed and very helpful response. Yes, I do encounter the second case you have mentioned. Thanks.

      Comment

      Working...
      X