Announcement

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

  • Keeping observations by year

    I am working with three variables company, income, and year (2007 and 2017). How can I keep first 20 observations, based on income (descending order), by year ?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double year str40 company float income
    2017 "VN000000TCB8"   6445595
    2017 "VN000000VPB6"   6294328
    2017 "VN000000BID9"   5122230
    2017 "VN000000MBB5"   3519627
    2017 "ID1000113707"   3027466
    2017 "ID1000092703"   2412458
    2017 "ID1000094402"   2175824
    2017 "COT29PA00025"   2169839
    2017 "COB01PA00030"   2064130
    2017 "KR7086790003"   2017741
    2017 "ID1000099302"   1804031
    2017 "COB51PA00076"   1275266
    2017 "ID1000118508"   1220886
    2017 "KR7024110009"   1219904
    2017 "ID1000123904"   1159370
    2017 "VN000000VIB1"   1124279
    2017 "COT23PA00010"   1059992
    2017 "VN000000TPB0"    938780
    2017 "ID1000098205"    748433
    2017 "LB0000010415"    747337
    2017 "LB0000033441"    726701
    2017 "JP3885780001"    603544
    2017 "CLP1506A1070"    564815
    2017 "JP3699200006"  506691.2
    2017 "KR7138930003"  391170.2
    2017 "COB23PA00067"    360712
    2017 "JP3946750001"    312264
    2017 "KR7139130009"    302208
    2017 "ID1000128507" 263753.38
    2017 "LB0000010530" 235525.05
    2017 "COB02PA00012"    219998
    2017 "LB0000010613"    200059
    2017 "VN000000KLB8"    187711
    2017 "KR7175330000" 185062.63
    2017 "NGZENITHBNK9"    177614
    2017 "JP3117700009"    158455
    2017 "ID1000095508" 140495.53
    2017 "ID1000103609"    135279
    2017 "KR7192530004" 129014.34
    2017 "ID1000100407"    121534
    2017 "RU000A0JP5V6"    110400
    2017 "UG0000000147"    106892
    2017 "CLP102411004"    106006
    2017 "CL0001692673"    103299
    2017 "ID1000107402"     86140
    2017 "GB0005405286"  85517.19
    2017 "CLP8716M1101"  83134.05
    2017 "NGUBA0000001"     76046
    2017 "LB0000010332"  70045.25
    2017 "ID1000128200" 69497.195
    2007 "ZW0009011249"  53725208
    2007 "ZW0009011967"  36635152
    2007 "ID1000118201"   4838001
    2007 "ID1000109507"   4489252
    2007 "ID1000095003"   4346224
    2007 "KR7105560007"   2757316
    2007 "KR7055550008"   2475513
    2007 "VN000000VCB4"   2397667
    2007 "KR7053000006"   2201994
    2007 "ID1000094204"   2116915
    2007 "VN000000ACB8"   1732396
    2007 "VN000000CTG7"   1149442
    2007 "COB07PA00078"   1086923
    2007 "KR7004940003"    960945
    2007 "ID1000096605"    897928
    2007 "ID1000098007"    770481
    2007 "ID1000093701"    737905
    2007 "JP3500610005"    645233
    2007 "ID1000052400"    520719
    2007 "VN000000EIB7"    463417
    2007 "JP3890350006"    428400
    2007 "ID1000093800"    420302
    2007 "ID1000115702"    370667
    2007 "VN000000HBB5"    365632
    2007 "CLP0939W1081"  242287.7
    2007 "HU0000061726"    208208
    2007 "ID1000109101"  192751.5
    2007 "KR7192520005"    160974
    2007 "CLP321331116"  135375.8
    2007 "VN000000SHB9" 126889.05
    2007 "COB52PA00017"    121152
    2007 "COB14PA00025"  116555.2
    2007 "JP3892100003"    108315
    2007 "RU0009029540"    106024
    2007 "JP3405000005"    103820
    2007 "JP3711200000"     79345
    2007 "IS0000001469"     70020
    2007 "CNE100000742"     69053
    2007 "JP3305990008"     66289
    2007 "JP3932800000"     64595
    2007 "INE062A01020"   63643.8
    2007 "KZ000A0KFFC1"     61354
    2007 "CNE000001N05"     56248
    2007 "KR7025610007"     54691
    2007 "UG0000000386"  53017.36
    2007 "KR7007800006"     52797
    2007 "ID1000056302"  49554.09
    2007 "KR7007200009"     45104
    2007 "CNE100000RJ0"     43787
    2007 "ID1000055205"  40744.45
    end

  • #2
    not completely sure I understand, but try this:
    Code:
    gsort year -income
    by year: keep if _n<=20

    Comment


    • #3
      Thanks Rich Goldstein . The code does the job!

      Comment

      Working...
      X