For the last two months I´ve been working on a dataset of antibiotic-resistant infections. The definition of the dicotomical variable "case" is an entry which is the first of an id within 2 months of the last entry from the same id.
My code for that is :
bysort id (date): gen firstcase = _n == 1
bysort id (date): gen difdays = date - date[_n-1]
gen case = 1 if difdays > 120 & firstcase[_n-1] == 1
recode case . = 0
That way i code for which infection cases i´m interested in and the ones i´m not; 1 for a case 0 if not.
Then comes my problem. the dataset has data for if an entry is a colonization (the bacteria is just vibin there) or if it is an infection. If two entries happen on the same day (the patient arrives at the hospital and several samples are taken, some may be colonizations other may be infections) In that case i want the infection entry to prevail over the colonization one.
Right now i´ve created a variable called InfectionYN, which classify dicotomically if a patient presents an infection or not, then i apply the next code lines:
generate newcase= case
replace newcase= 1 if difdays == 0 & InfectionYN == 1
replace newcase= 0 if difdays == . & InfectionYN== 2 ("." here means an entry that was classified as a case, & InfectionYN== 2 means a colonization)
with these i´ve selected the cases of infection that happened on the first day and had an infection, and also changed the colonization ones to 0. The problem is that by changing the colonization ones i´ve discarded valuable cases that had no simultaneous infection.
Which modifications should i do to my code? Are there some function i can apply in this situation?
thank you in advance.
My code for that is :
bysort id (date): gen firstcase = _n == 1
bysort id (date): gen difdays = date - date[_n-1]
gen case = 1 if difdays > 120 & firstcase[_n-1] == 1
recode case . = 0
That way i code for which infection cases i´m interested in and the ones i´m not; 1 for a case 0 if not.
Then comes my problem. the dataset has data for if an entry is a colonization (the bacteria is just vibin there) or if it is an infection. If two entries happen on the same day (the patient arrives at the hospital and several samples are taken, some may be colonizations other may be infections) In that case i want the infection entry to prevail over the colonization one.
Right now i´ve created a variable called InfectionYN, which classify dicotomically if a patient presents an infection or not, then i apply the next code lines:
generate newcase= case
replace newcase= 1 if difdays == 0 & InfectionYN == 1
replace newcase= 0 if difdays == . & InfectionYN== 2 ("." here means an entry that was classified as a case, & InfectionYN== 2 means a colonization)
with these i´ve selected the cases of infection that happened on the first day and had an infection, and also changed the colonization ones to 0. The problem is that by changing the colonization ones i´ve discarded valuable cases that had no simultaneous infection.
Which modifications should i do to my code? Are there some function i can apply in this situation?
thank you in advance.
Comment