Out of a data set of one patient, I'm trying to locate the first date and set it as a value 1 in a new colum(episodestart)
Then I want to go through each row in order and figure out if it's within 30 days of the previous episodestart column record that was a 1 and mark it with a 0.. If it is over 30 days it will need to be marked as a 1 and the process starts over again.
Example below should help. Any ideas?
So I have a data set that looks like this:
id Pid did ddate cdate
99999 52388 15230 2012-05-13 2012-05-15
99999 52388 16609 2012-05-19 2012-05-21
99999 52388 23890 2012-06-19 2012-06-21
99999 52388 24940 2012-06-24 2012-06-26
99999 52388 38048 2012-08-20 2012-08-22
99999 52388 39755 2012-08-28 2012-08-30
99999 52388 42062 2012-09-07 2012-09-09
99999 52388 48094 2012-10-02 2012-10-04
99999 52388 48917 2012-10-06 2012-10-08
My desired results would look like thisadded episodestart colum)
id Pid did ddate cdate EpisodeStart
99999 52388 15230 2012-05-13 2012-05-15 1
99999 52388 16609 2012-05-19 2012-05-21 0
99999 52388 23890 2012-06-19 2012-06-21 1
99999 52388 24940 2012-06-24 2012-06-26 0
99999 52388 38048 2012-08-20 2012-08-22 1
99999 52388 39755 2012-08-28 2012-08-30 0
99999 52388 42062 2012-09-07 2012-09-09 0
99999 52388 48094 2012-10-02 2012-10-04 1
99999 52388 48917 2012-10-06 2012-10-08 0
Then I want to go through each row in order and figure out if it's within 30 days of the previous episodestart column record that was a 1 and mark it with a 0.. If it is over 30 days it will need to be marked as a 1 and the process starts over again.
Example below should help. Any ideas?
So I have a data set that looks like this:
id Pid did ddate cdate
99999 52388 15230 2012-05-13 2012-05-15
99999 52388 16609 2012-05-19 2012-05-21
99999 52388 23890 2012-06-19 2012-06-21
99999 52388 24940 2012-06-24 2012-06-26
99999 52388 38048 2012-08-20 2012-08-22
99999 52388 39755 2012-08-28 2012-08-30
99999 52388 42062 2012-09-07 2012-09-09
99999 52388 48094 2012-10-02 2012-10-04
99999 52388 48917 2012-10-06 2012-10-08
My desired results would look like thisadded episodestart colum)
id Pid did ddate cdate EpisodeStart
99999 52388 15230 2012-05-13 2012-05-15 1
99999 52388 16609 2012-05-19 2012-05-21 0
99999 52388 23890 2012-06-19 2012-06-21 1
99999 52388 24940 2012-06-24 2012-06-26 0
99999 52388 38048 2012-08-20 2012-08-22 1
99999 52388 39755 2012-08-28 2012-08-30 0
99999 52388 42062 2012-09-07 2012-09-09 0
99999 52388 48094 2012-10-02 2012-10-04 1
99999 52388 48917 2012-10-06 2012-10-08 0