How could I create a variable called
test_index to enumerate (from 1 to ...) the tests for each
record_id ?
And then create another variable called
days_since_prior_test to calculate the difference in elapsed days between the
test_date for that particular row and the
test_date for the row with the same
record_id and
test_index - 1 ?
This would be simple if my data were in wide format i.e. one patient per row but it's not and I'd rather not reshape if unless necessary.
Thanks,
Jonathan
record_id |
test_date |
test_index |
days_since_prior_test |
ID-072 |
2009-07-16 |
|
|
ID-072 |
2009-07-29 |
|
|
ID-073 |
2009-07-22 |
|
|
ID-073 |
2009-08-03 |
|
|
ID-074 |
2004-06-08 |
|
|
ID-074 |
2009-02-18 |
|
|
ID-074 |
2010-03-09 |
|
|
ID-074 |
2012-08-17 |
|
|
ID-076 |
1999-01-07 |
|
|
ID-076 |
2009-06-08 |
|
|
ID-076 |
2009-07-30 |
|
|
ID-076 |
2012-11-09 |
|
|
ID-077 |
2009-07-29 |
|
|
ID-077 |
2009-07-31 |
|
|
ID-086 |
2009-12-16 |
|
|
|
0 Response to How to create an index variable and analyze i vs. i - 1 (long data)
Post a Comment