Dear Stata,
I have been using the following command to deal with overlaps:
bysort pat_id (admindate3 disdate5): gen adm_tag=_n
gen curadm=admindate3
format curadm %d
// carry admission date forward if last discharge if after current admission
bys pat_id (admindate3 disdate5) : replace curadm = curadm[_n-1] if admindate3<=disdate5[_n-1] & adm_tag!=1
// discharge is largest discharge date with current admission.
bys pat_id curadm (disdate5) : gen curdis=disdate5[_N]
format curdis %d
However, this code doesnt seem to work for a dataset that looks like the data below:
I wanted the datset to replace all the dates that overlap and give the dataset below:
If I wanted the above results then I would have to create a new variable each time and replace the dates SEE BELOW.
I would be greatful for any advice or help.
I have been using the following command to deal with overlaps:
bysort pat_id (admindate3 disdate5): gen adm_tag=_n
gen curadm=admindate3
format curadm %d
// carry admission date forward if last discharge if after current admission
bys pat_id (admindate3 disdate5) : replace curadm = curadm[_n-1] if admindate3<=disdate5[_n-1] & adm_tag!=1
// discharge is largest discharge date with current admission.
bys pat_id curadm (disdate5) : gen curdis=disdate5[_N]
format curdis %d
However, this code doesnt seem to work for a dataset that looks like the data below:
Patient | Start date | End date |
A | 03/06/2010 | 29/06/2010 |
A | 04/06/2010 | 04/06/2010 |
A | 05/06/2010 | 05/06/2010 |
A | 06/06/2010 | 06/06/2010 |
A | 07/06/2010 | 07/06/2010 |
A | 08/06/2010 | 08/06/2010 |
A | 09/06/2010 | 09/06/2010 |
A | 10/06/2010 | 10/06/2010 |
A | 11/06/2010 | 11/06/2010 |
A | 12/06/2010 | 12/06/2010 |
A | 13/06/2010 | 13/06/2010 |
Patient | Start date | End date | Start date2 | End date 2 |
A | 03/06/2010 | 29/06/2010 | 03/06/2010 | 29/06/2010 |
A | 04/06/2010 | 04/06/2010 | 03/06/2010 | 29/06/2010 |
A | 05/06/2010 | 05/06/2010 | 03/06/2010 | 29/06/2010 |
A | 06/06/2010 | 06/06/2010 | 03/06/2010 | 29/06/2010 |
A | 07/06/2010 | 07/06/2010 | 03/06/2010 | 29/06/2010 |
A | 08/06/2010 | 08/06/2010 | 03/06/2010 | 29/06/2010 |
A | 09/06/2010 | 09/06/2010 | 03/06/2010 | 29/06/2010 |
A | 10/06/2010 | 10/06/2010 | 03/06/2010 | 29/06/2010 |
A | 11/06/2010 | 11/06/2010 | 03/06/2010 | 29/06/2010 |
A | 12/06/2010 | 12/06/2010 | 03/06/2010 | 29/06/2010 |
A | 13/06/2010 | 13/06/2010 | 03/06/2010 | 29/06/2010 |
Patient | Start date | End date | Start date_1 | End date_1 | Start date_1 | End date_1 |
A | 03/06/2010 | 29/06/2010 | 03/06/2010 | 29/06/2010 | 03/06/2010 | 29/06/2010 |
A | 04/06/2010 | 04/06/2010 | 03/06/2010 | 29/06/2010 | 03/06/2010 | 29/06/2010 |
A | 05/06/2010 | 05/06/2010 | 05/06/2010 | 05/06/2010 | 03/06/2010 | 29/06/2010 |
A | 06/06/2010 | 06/06/2010 | 06/06/2010 | 06/06/2010 | 06/06/2010 | 06/06/2010 |
A | 07/06/2010 | 07/06/2010 | 07/06/2010 | 07/06/2010 | 07/06/2010 | 07/06/2010 |
A | 08/06/2010 | 08/06/2010 | 08/06/2010 | 08/06/2010 | 08/06/2010 | 08/06/2010 |
A | 09/06/2010 | 09/06/2010 | 09/06/2010 | 09/06/2010 | 09/06/2010 | 09/06/2010 |
A | 10/06/2010 | 10/06/2010 | 10/06/2010 | 10/06/2010 | 10/06/2010 | 10/06/2010 |
A | 11/06/2010 | 11/06/2010 | 11/06/2010 | 11/06/2010 | 11/06/2010 | 11/06/2010 |
A | 12/06/2010 | 12/06/2010 | 12/06/2010 | 12/06/2010 | 12/06/2010 | 12/06/2010 |
A | 13/06/2010 | 13/06/2010 | 13/06/2010 | 13/06/2010 | 13/06/2010 | 13/06/2010 |
I would be greatful for any advice or help.
Comment