Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Fwd: Minimum in 24 hours
From
Paul McCabe <[email protected]>
To
Stata List <[email protected]>
Subject
st: Fwd: Minimum in 24 hours
Date
Fri, 17 Feb 2012 14:03:47 +0000
Dear Statalist
I have data relating to admissions to intensive care units with data a
little like this
| id time MV |
|-------------------------------------|
1. | 1128809 26oct2005 04:30:00 11 |
2. | 1128809 26oct2005 05:30:00 7 |
3. | 1128809 26oct2005 06:30:00 8.3 |
4. | 1128809 26oct2005 07:30:00 8.4 |
5. | 1128809 26oct2005 08:30:00 8.4 |
|-------------------------------------|
6. | 1128809 26oct2005 09:30:00 8.1 |
7. | 1128809 26oct2005 10:30:00 8.8 |
8. | 1128809 26oct2005 11:30:00 7.8 |
9. | 1128809 26oct2005 17:30:00 7.6 |
10. | 1128809 26oct2005 18:30:00 8 |
|-------------------------------------|
11. | 1128809 26oct2005 19:30:00 8 |
12. | 1128809 26oct2005 20:30:00 8.1 |
13. | 1128809 26oct2005 21:30:00 9.2 |
14. | 1128809 26oct2005 22:30:00 8.9 |
15. | 1128809 26oct2005 23:30:00 10.4 |
|-------------------------------------|
16. | 1128809 27oct2005 00:30:00 9.6 |
17. | 1128809 27oct2005 01:30:00 7.8 |
18. | 1128809 27oct2005 02:30:00 7.8 |
19. | 1128809 27oct2005 03:30:00 7.7 |
I want the minimum value within the first 24 hours of admission.
However the function min() returns:
gen minMV=min(MV) if time>=time[1] & time<(time[1]+8.64e7) & id==1128809
invalid syntax
r(198);
And while the egen function works with explicit ids, does not allow
explicit subscripting when I try to combine with by:
sort id time
by id:egen minMV=min(MV) if time>=time[1] & time<(time[1]+8.64e7)
8469 missing values generated)
duplicates examples id minMV
Duplicates in terms of id minMV
+--------------------------------------------+
| group: # e.g. obs id minMV |
|--------------------------------------------|
| 1 19 1 1128809 7 |
| 2 593 20 1128809 . |
| 3 22 633 1128817 10 |
| 4 437 613 1128817 . |
| 5 18 1072 1128827 . |
|--------------------------------------------|
| 6 474 1090 1128828 . |
| 7 73 1564 1275019 . |
| 8 118 1637 1613911 . |
| 9 282 1755 1621603 . |
| 10 246 2037 1630155 . |
|--------------------------------------------|
| 11 465 2283 1633930 . |
| 12 356 2748 1660876 . |
| 13 64 3104 1667289 . |
| 14 52 3168 1687505 . |
| 15 754 3220 2109887 . |
|--------------------------------------------|
| 16 46 3974 2124610 . |
| 17 47 4020 2129680 . |
| 18 56 4067 2141764 . |
| 19 149 4123 2147829 . |
| 20 402 4272 2150550 . |
|--------------------------------------------|
| 21 676 4674 2189948 . |
| 22 304 5350 2201604 . |
| 23 955 5654 2202648 . |
| 24 32 6609 2208416 . |
| 25 641 6641 2212494 . |
|--------------------------------------------|
| 26 1229 7282 2217835 . |
+--------------------------------------------+
(ID 1128817 was admitted at the same time as ID1128809 which is why
minMV is created for them)
Can anyone give advice on how to combine a function, by, and the time selection?
Many thanks, and best wishes
Paul (Using Stata SE10.1 for Windows)
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/