mpg | rank |
12 | 1 |
12 | 1 |
14 | 2 |
14 | 2 |
14 | 2 |
15 | 3 |
15 | 3 |
16 | 4 |
17 | 5 |
-
Login or Register
- Log in with
egen rank = group(mpg)
. reshape wide rank , i(pid) j(country) string . list pid rankUS rankGB rankIT rankDE rankGR, sep(0) +--------------------------------------------------+ | pid rankUS rankGB rankIT rankDE rankGR | |--------------------------------------------------| 1. | 1 4 . . . . | 2. | 2 1 2 3 4 5 | 3. | 3 . . . . . | 4. | 4 3 2 . . . | 5. | 5 . 4 . . . | 6. | 6 . . . 2 . | +--------------------------------------------------+
. reshape wide country, i(pid) j(rank) +------------------------------------------------------------+ | pid country1 country2 country3 country4 country5 | |------------------------------------------------------------| 1. | 1 NZ AU CA US TH | 2. | 2 US GB IT DE GR | 3. | 3 DO AW AU ES CH | 4. | 4 ES GB US TH CK | 5. | 5 CA JP AU GB DK | 6. | 6 AL DE | +------------------------------------------------------------+
* Example generated by -dataex-. For more info, type help dataex clear input float(ID data) str11 date float Date str6 month_year float rank 1 50 "1 Jan 2020" 21915 "1_2020" 1 2 40 "4 Feb 2020" 21949 "2_2020" 1 3 70 "7 Jan 2020" 21921 "1_2020" 2 4 55 "15 Feb 2020" 21960 "2_2020" 2 5 65 "17 Feb 2020" 21962 "2_2020" 3 6 80 "18 Jan 2020" 21932 "1_2020" 3 end format %td Date
* Example generated by -dataex-. For more info, type help dataex clear input float(ID data) str11 date 1 50 "1 Jan 2020" 2 40 "4 Feb 2020" 3 70 "7 Jan 2020" 4 55 "15 Feb 2020" 5 65 "17 Feb 2020" 6 80 "18 Jan 2020" end
Comment