Announcement

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

  • Extremes in Stata

    Dear all,

    I have a dataset with 4 variables: year, person_id, work_id, work_score. The id variables are string and work_score is numeric. I want to list the top and bottom 5 jobs based on work_score variable with number of observations in each category of job (category is denoted as work_id). When I use the following command:

    bys year: extremes work_score, frequencies

    It does give me the top and bottom 5 job types with their frequencies but how can it show the work_id alongside the results (in the display window) so that I can identify which job type lies in bottom or top group.

    Thanks in advace!

    Zariab Hossain
    Uppsala University

  • #2
    That is not supported: the point is that the identifiers might (probably will) vary within the groups whose frequencies you're showing. So, the real question is quite what you expect to see as result. Consider

    Code:
    . sysuse auto, clear 
    
    . extremes mpg, frequencies
    
      +-------------+
      | freq:   mpg |
      |-------------|
      |     2    12 |
      |     6    14 |
      |     2    15 |
      |     4    16 |
      |     4    17 |
      +-------------+
    
      +-------------+
      |     2    30 |
      |     1    31 |
      |     1    34 |
      |     2    35 |
      |     1    41 |
      +-------------+
    25 cars are being summarized. Where are the 25 distinct values of make to go?

    Here's some technique for something different:

    Code:
    . sysuse auto, clear 
    (1978 automobile data)
    
    . egen group = group(mpg)
    
    . su group, meanonly 
     
    . local max = r(max)
    
    . sort mpg 
    
    . list group mpg make if group <= 5 | inrange(group, `max' - 4, `max'), sepby(group) noobs 
    
      +---------------------------------+
      | group   mpg   make              |
      |---------------------------------|
      |     1    12   Linc. Mark V      |
      |     1    12   Linc. Continental |
      |---------------------------------|
      |     2    14   Cad. Eldorado     |
      |     2    14   Linc. Versailles  |
      |     2    14   Peugeot 604       |
      |     2    14   Cad. Deville      |
      |     2    14   Merc. XR-7        |
      |     2    14   Merc. Cougar      |
      |---------------------------------|
      |     3    15   Merc. Marquis     |
      |     3    15   Buick Electra     |
      |---------------------------------|
      |     4    16   Olds Toronado     |
      |     4    16   Chev. Impala      |
      |     4    16   Buick Riviera     |
      |     4    16   Dodge Magnum      |
      |---------------------------------|
      |     5    17   Audi 5000         |
      |     5    17   Volvo 260         |
      |     5    17   AMC Pacer         |
      |     5    17   Dodge St. Regis   |
      |---------------------------------|
      |    17    30   Mazda GLC         |
      |    17    30   Dodge Colt        |
      |---------------------------------|
      |    18    31   Toyota Corolla    |
      |---------------------------------|
      |    19    34   Plym. Champ       |
      |---------------------------------|
      |    20    35   Datsun 210        |
      |    20    35   Subaru            |
      |---------------------------------|
      |    21    41   VW Diesel         |
      +---------------------------------+

    Comment


    • #3
      Thanks a lot Nick. I should have been more clear in this case. Actually my work_score has a 1:1 correspondence with work_id that I would like to show in the result window. In your example, you showed the id of each observation that's added up into the frequencies (which is person_id in my case).

      Comment


      • #4
        groups from the Stata Journal should help with a bit of nudging. This should work reasonably in your set-up too:

        Code:
        sysuse auto, clear 
        
        egen group = group(mpg)
        
        su group, meanonly 
        local max = r(max)
        
        forval j = 1/5 { 
            local this = `max' -`j' + 1 
            label def group `this' "-`j'", modify 
        }
        
        label val group group 
        
        groups group mpg make if group <= 5 | inrange(group, `max' - 4, `max'), show(f) sepby(group)
        
          +-----------------------------------------+
          | group   mpg   make                Freq. |
          |-----------------------------------------|
          |     1    12   Linc. Continental       1 |
          |     1    12   Linc. Mark V            1 |
          |-----------------------------------------|
          |     2    14   Cad. Deville            1 |
          |     2    14   Cad. Eldorado           1 |
          |     2    14   Linc. Versailles        1 |
          |     2    14   Merc. Cougar            1 |
          |     2    14   Merc. XR-7              1 |
          |     2    14   Peugeot 604             1 |
          |-----------------------------------------|
          |     3    15   Buick Electra           1 |
          |     3    15   Merc. Marquis           1 |
          |-----------------------------------------|
          |     4    16   Buick Riviera           1 |
          |     4    16   Chev. Impala            1 |
          |     4    16   Dodge Magnum            1 |
          |     4    16   Olds Toronado           1 |
          |-----------------------------------------|
          |     5    17   AMC Pacer               1 |
          |     5    17   Audi 5000               1 |
          |     5    17   Dodge St. Regis         1 |
          |     5    17   Volvo 260               1 |
          |-----------------------------------------|
          |    -5    30   Dodge Colt              1 |
          |    -5    30   Mazda GLC               1 |
          |-----------------------------------------|
          |    -4    31   Toyota Corolla          1 |
          |-----------------------------------------|
          |    -3    34   Plym. Champ             1 |
          |-----------------------------------------|
          |    -2    35   Datsun 210              1 |
          |    -2    35   Subaru                  1 |
          |-----------------------------------------|
          |    -1    41   VW Diesel               1 |
          +-----------------------------------------+

        Comment


        • #5
          Thanks a lot Nick. It solved the problem.

          Comment

          Working...
          X