Announcement

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

  • egen cut acting up?

    I am trying to create income quintiles, by creating 5 approximately equal groups for my income variable. For some reason, when I use the cut function with the egen command, with 5 groups as option, Stata only create 4 groups, with the first group having approximately 40% of the observations (rather than 20% as it should be with quintiles). I am not sure why this is happening, maybe I am missing something obvious, but I would appreciate some help. As an aside, when I ask Stata to create quartiles (by using the group(4) option), Stata behaves correctly, creating four quartiles. Below is the relevant portion of the log file. Thanks.


    Code:
    . desc rincome
    
    Variable      Storage   Display    Value
        name         type    format    label      Variable label
    ------------------------------------------------------------------------------------------------
    rincome         float   %9.0g                 Real Yearly Wage Income Last Year
    
    . egen incomecat = cut(rincome), group(5)
    (135,486 missing values generated)
    
    . tab incomecat
    
      incomecat |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |     92,950       39.99       39.99
              2 |     46,410       19.97       59.96
              3 |     46,565       20.04       80.00
              4 |     46,483       20.00      100.00
    ------------+-----------------------------------
          Total |    232,408      100.00

  • #2
    Quantile binning often disappoints, the main reason being that observations with the same values must be placed in the same bin.

    This has often been discussed and explained here on Statalist and also in the Stata Journal, e.g. https://journals.sagepub.com/doi/pdf...867X1201200413 (Section 4) and https://journals.sagepub.com/doi/pdf...867X1801800311 (Section 6).

    To understand what is to blame here, we need to know more about your data. I suggest running commands like these and showing us the results.

    Code:
    su rincome if missing(incomecat), detail 
    
    tabstat rincome, by(incomecat) s(n min max) 
    
    clonevar incomecat2 = incomecat 
    replace incomecat2 = 5 if missing(incomecat2) 
    
    scatter incomecat2 rincome

    Comment


    • #3
      OK, thanks, Nick, I appreciate this. I forgot that there are a bunch of zeros in the data, and actually the observations with zeros are slightly above 20% (the first quintile) which I believe causes the problem as Stata, correctly, does not want to split the zeros in two different bins. I paste the log below just if anyone is interested:

      Code:
      . sum rincome
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
           rincome |    232,408     39178.3    52457.73          0   577626.9
      
      . scalar totobsincome = r(N)
      
      . count if rincome == 0
        48,707
      
      . scalar incomezero = r(N)
      
      . 
      . di "The Share of Observations with Zero Income is " round(100*incomezero/totobsincome,.01) "%"
      The Share of Observations with Zero Income is 20.96%

      Comment

      Working...
      X