I have 5 subjects who had 5 visits at different dates, I want to create a new variable that has the number of days elapsed since the date of first visit of each subject
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str11 usubjid float visdat byte visnam1 "494" 21571 1 "494" 21599 2 "494" 21677 3 "494" 21851 4 "494" 22097 5 "787" 21579 1 "787" 21606 2 "787" 21690 3 "787" 21858 4 "787" 22103 5 "068" 21587 1 "068" 21615 2 "068" 21698 3 "068" 21868 4 "068" 22131 5 "246" 21594 1 "246" 21620 2 "246" 21704 3 "246" 21872 4 "246" 22167 5 "468" 21656 1 "468" 21679 2 "468" 21756 3 "468" 21931 4 "468" 22195 5 end format %td visdat
for each line, I want to have a variable that has the number of days elapsed between the visit date at that line and the date when visnam is 1 for the subject
In other words for subject 494, the value of the new variable for the first observation will be : visdat - itself so it will be 0, but in the next line the new variable should be number of days between visdat at visit 2 - visdat at visit 1 , and so on.
so it always has to be days between date of visit at that line and the date of visit at visit number 1 for the subject.
I hope this makes sense and I hope I have made my self clear.
Many thanks for your time in advance.
0 Response to counting days between date and another date
Post a Comment