Hello all,

Please I have a dataset where patients have several episodes of the disease. I am seeking to count a patient once within a 14 day window period and provide a clean dataset for analysis. I want to use loop programming.
Thanks for the help

Please find a sample of my data below

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input long pateid byte(sex ageatevent) int eventdate str5 read_4or5_code str30 description
 420431 0  3 16883 "H2z.." "Pneumonia or influenza NOS"    
 420431 0  3 16887 "H2..." "Pneumonia and influenza"       
 420431 0  3 16891 "H2z.." "Pneumonia or influenza NOS"    
3438114 1 12 16475 "H25.." "Bronchopneumonia,organism unsp"
3438114 1 12 16478 "H25.." "Bronchopneumonia,organism unsp"
3438114 1 12 16511 "H25.." "Bronchopneumonia,organism unsp"
3438114 1 12 16519 "H25.." "Bronchopneumonia,organism unsp"
3438455 0  1 16066 "H26.." "Pneumonia, organism unspecif." 
3438455 0  2 16077 "H26.." "Pneumonia, organism unspecif." 
3438455 0  2 16124 "H26.." "Pneumonia, organism unspecif." 
3438455 0  2 16127 "H26.." "Pneumonia, organism unspecif." 
3438455 0  2 16197 "H26.." "Pneumonia, organism unspecif." 
3440095 0  0 16429 "H25.." "Bronchopneumonia,organism unsp"
3440095 0  1 16461 "H25.." "Bronchopneumonia,organism unsp"
3440095 0  1 16593 "H25.." "Bronchopneumonia,organism unsp"
3440095 0  1 16628 "H25.." "Bronchopneumonia,organism unsp"
3440095 0  1 16727 "H25.." "Bronchopneumonia,organism unsp"
3440095 0  1 16729 "H25.." "Bronchopneumonia,organism unsp"
3440095 0  1 16736 "H25.." "Bronchopneumonia,organism unsp"
3440095 0  1 16742 "H25.." "Bronchopneumonia,organism unsp"
end
format %dD/N/CY eventdate
label values sex sexlbl
label def sexlbl 0 "Female", modify
label def sexlbl 1 "Male", modify