Hello,
Im kindly requesting on guidance on the issue below.
I have data in long format ie IDs of patients with their dates of LP. Each observation indicates a different date of LP and the variable DateLp shows the difference.
I want to be able to generate a variable DayOfLP which basically counts the number of days from the first date of LP. e.g if DateLP=12SEP2021 and DayOfLP is 1, then DateLP of 14SEP2021 would result to DayOfLP being 3.
An example dataset is below.
I have tried the code
but this generates numbers that are like tags for the duplicates (starting from 0 onwards)
I'd be grateful if some guidance is given.
Thanks.
Im kindly requesting on guidance on the issue below.
I have data in long format ie IDs of patients with their dates of LP. Each observation indicates a different date of LP and the variable DateLp shows the difference.
I want to be able to generate a variable DayOfLP which basically counts the number of days from the first date of LP. e.g if DateLP=12SEP2021 and DayOfLP is 1, then DateLP of 14SEP2021 would result to DayOfLP being 3.
An example dataset is below.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str6 PatId int DateLP "64-001" 19475 "64-001" 19478 "64-002" 19478 "64-004" 19492 "64-004" 19495 "64-004" 19499 "64-004" 19507 "64-006" 19505 "64-006" 19507 "64-006" 19512 end format %td DateLP
Code:
quiet by PatId: gen DayOfLP=(_N-_n) if DateLP!=.
I'd be grateful if some guidance is given.
Thanks.

Comment