instruction: What is the total number of patients admitted before the year 2166 who were treated with drug loperamide
response: SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE demographic.admityear < "2166" AND prescriptions.drug = "Loperamide"