Dear all,
I have a dataset that has multiple visits for each person. However each person had a differing number of visits
The dataset is demonstrated below
id visit value
1 1 70
1 2 70
1 3 68
1 4 58
2 1 55
2 2 35
3 1 57
4 1 67
4 2 55
5 1 59
5 2 52
5 3 32
I had a few queries to working on this dataset
1. Is there a command that would allow me to identify:
a) the visit with the lowest value for each id (i.e visit 1 for
b) the value corresponding to the last visit (i.e visit 4 for id 1, visit 3 for id 5) for each id
c) the change and direction of change between the highest and lowest value for each id (i.e for visit 5, the change would be negative 27 over 3 visits)
2. After establishing the above,
Is there a command that would
a) allow me to drop the other visits apart from the desired visit in question - be it the visit with the lowest value, last visit,
b) such that the dataset becomes one visit per id?
I would be grateful for your help with these queries.
Thank you very much
0 Response to How to sort data for distinct IDs with multiple visits and multiple values
Post a Comment