答案 0 :(得分:3)
您可以使用collapse
命令来获取所需的内容:
clear
input patient observation
17133 2.2
17133 2.3
17154 3.2
17154 1.2
17154 2.2
end
collapse (max) observation, by(patient)
list, abbreviate(15)
+-----------------------+
| patient observation |
|-----------------------|
1. | 17133 2.3 |
2. | 17154 3.2 |
+-----------------------+
输入help collapse
以获得更多详细信息。
编辑:
如果您也想保留date
:
clear
input patient observation str10 date1
17133 2.2 "01jul1965"
17133 2.3 "30jun1965"
17144 4.1 "01jul1965"
17144 3.2 "30jun1965"
17144 1.5 "30jun1965"
17154 3.2 "30jun1965"
17154 1.2 "01jul1965"
17154 2.2 "01jul1965"
end
generate date2 = daily(date1, "DMY")
format %tdDDMonCCYY date2
bysort patient (observation): keep if _n == _N
list patient observation date2, abbreviate(15)
+-----------------------------------+
| patient observation date2 |
|-----------------------------------|
1. | 17133 2.3 30Jun1965 |
2. | 17144 4.1 01Jul1965 |
3. | 17154 3.2 30Jun1965 |
+-----------------------------------+