Dear all,
I hope everything going well with you.
Recently I am working on medication prescription data and I am facing a problem with coding missing variables between first (first medication supply date) and last date (last medication supply date). Data looks similar as below:
input byte(id aspirin2006 clopidogrel2006 heparin2006 aspirin2007 clopidogrel2007 heparin2007 aspirin2008 clopidogrel2008 heparin2008 aspirin2009 clopidogrel2009 heparin2009 aspirin2010 clopidogrel2010 heparin2010) int str12 first_date last_date
1 . . . 1 0 0 . . . . . . 0 0 1 2007 2010
2 0 0 1 . . . 0 1 0 . . . 0 1 0 2006 2010
3 . . . 0 1 0 . . . . . . 1 0 0 2007 2009
end
I've tried the following command:
foreach d of varlist aspirin2008-heparin2010 {
replace `d'=0 if first_date==2007 & last_date==2010 & `d'==.
}
But this one is not working and I think there is something wrong (replacing missing variables before first date).
I would really appreciate If you may help me solving the problem.
Thank you in advance
Sincerely
Oyunchimeg
I hope everything going well with you.
Recently I am working on medication prescription data and I am facing a problem with coding missing variables between first (first medication supply date) and last date (last medication supply date). Data looks similar as below:
input byte(id aspirin2006 clopidogrel2006 heparin2006 aspirin2007 clopidogrel2007 heparin2007 aspirin2008 clopidogrel2008 heparin2008 aspirin2009 clopidogrel2009 heparin2009 aspirin2010 clopidogrel2010 heparin2010) int str12 first_date last_date
1 . . . 1 0 0 . . . . . . 0 0 1 2007 2010
2 0 0 1 . . . 0 1 0 . . . 0 1 0 2006 2010
3 . . . 0 1 0 . . . . . . 1 0 0 2007 2009
end
I've tried the following command:
foreach d of varlist aspirin2008-heparin2010 {
replace `d'=0 if first_date==2007 & last_date==2010 & `d'==.
}
But this one is not working and I think there is something wrong (replacing missing variables before first date).
I would really appreciate If you may help me solving the problem.
Thank you in advance
Sincerely
Oyunchimeg
Comment