Announcement

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

  • sorting by quintiles, in which i decide the parameters

    Hi,

    I am new to state so i apologies if this is a amateur question.

    I am trying to sort my data into quintiles by of one of the variables (KDPI) but i want to set the parameters of the the quintiles.
    It doesn't matter how many of the variables are actually within each quintile parameter.

    so far i have got

    xtile KDPIquintile = KDPI nq (5)

    tabstat age, stat(n mean sd), by (KDPIquintile)


    But this doesn't let me choose which values of KDPI i want to use to split the data into 5 groups

    any help would be great

    thanks


  • #2
    Welcome to Statalist.

    If I understand your question correctly, you don't really care about "statistical quintiles" - what you want is to divide your data into 5 groups based on the value of KDPI, according to values you select. So you don't want to use the xtile command, rather use the recode command.

    In that case, let us suppose that your KDPI are a number between 0 and 10, and you want to break the groups at 2, 4, 6, and 8.
    Code:
    clear
    set seed 42
    set obs 100
    generate age = runiform(21,65)
    generate KDPI = runiform(0,sqrt(10))^2
    recode KDPI (0/2=1) (2/4=2) (4/6=3) (6/8=4) (8/10=5) (else=9), generate(KDPIquintile)
    tabstat age, stat(n mean sd) by(KDPIquintile)
    Code:
    . tabstat age, stat(n mean sd) by(KDPIquintile)
    
    Summary for variables: age
         by categories of: KDPIquintile (RECODE of KDPI)
    
    KDPIquintile |         N      mean        sd
    -------------+------------------------------
               1 |        50   43.3953  11.73866
               2 |        16  43.97833  12.29431
               3 |        15   40.6701  9.678313
               4 |        12  40.58128  13.04458
               5 |         7  48.29676   6.40462
    -------------+------------------------------
           Total |       100  43.08523  11.37912
    --------------------------------------------

    Comment


    • #3
      Thanks for the reply it all makes sense, apart from (else=9) . I was wondering what this means?

      Comment


      • #4
        Just because I expect all the values to be between 0 and 10 is no reason not to check. Anything unexpected becomes 9, if 9 shows up in the tabstat output I know I have a problem. See help recode for more details on the synrax of recode.

        Comment

        Working...
        X