Dear All,
I'm trying to run a loop after sorting by group_id, the following is my code.
I'm getting error by stata as follows: 'forvalues may not be combined with by'
Any idea about an alternative to get this code working??
Many thanks,
I'm trying to run a loop after sorting by group_id, the following is my code.
I'm getting error by stata as follows: 'forvalues may not be combined with by'
Any idea about an alternative to get this code working??
Many thanks,
by patientid: forvalues i = 1/`=_N' {
// Store the current start date and patient ID
local current_patient = patientid[`i']
local current_date = StartDate[`i']
// Check if there is an "MTX" in any subsequent record
replace coadmin_mtx = 1 if patientid == `current_patient' & ///
drugname == "Methotrexate" & StartDate > `current_date'
}
// Store the current start date and patient ID
local current_patient = patientid[`i']
local current_date = StartDate[`i']
// Check if there is an "MTX" in any subsequent record
replace coadmin_mtx = 1 if patientid == `current_patient' & ///
drugname == "Methotrexate" & StartDate > `current_date'
}
Comment