Hi Statalist
I am new to STATA, but fortunately come with some syntax experience from previous programs and work.
My situation:
I have a dataset which contains diagnostic codes. Each record (6000 records) can have up to 100 diagnosis codes. Each diagnosis code is set up as an individual variable (not by me, it is how the dataset came), ie diag01 diag 02…. I am setting up a do file where I want a loop to check through all of the diagnosis variable (diag01 – diag100) and check to see if certain diagnosis codes have been recorded.
Code:
gen aAB100=0
quietly forval i=1(1)100 {
replace aAB100=1 if substr(Diag`i',1,5)=="AB100"
}
label variable aAB100 "Diagnosis"
label define Diagnosis 1 "Yes" 0 "No"
label values aAB100 Diagnosis
Output:
I am receiving a r(109) mismatch error. I assume the error has to do with the string containing both letters and numbers, however can’t seem to get a straight answer by looking over manuals and discussion forums. Any advice on a better method would be appreciated. Interestingly aAB100 output does occur with correct results, so it appears that the error occurs at the end of everything.
Thank you
Court
I am new to STATA, but fortunately come with some syntax experience from previous programs and work.
My situation:
I have a dataset which contains diagnostic codes. Each record (6000 records) can have up to 100 diagnosis codes. Each diagnosis code is set up as an individual variable (not by me, it is how the dataset came), ie diag01 diag 02…. I am setting up a do file where I want a loop to check through all of the diagnosis variable (diag01 – diag100) and check to see if certain diagnosis codes have been recorded.
Code:
gen aAB100=0
quietly forval i=1(1)100 {
replace aAB100=1 if substr(Diag`i',1,5)=="AB100"
}
label variable aAB100 "Diagnosis"
label define Diagnosis 1 "Yes" 0 "No"
label values aAB100 Diagnosis
Output:
I am receiving a r(109) mismatch error. I assume the error has to do with the string containing both letters and numbers, however can’t seem to get a straight answer by looking over manuals and discussion forums. Any advice on a better method would be appreciated. Interestingly aAB100 output does occur with correct results, so it appears that the error occurs at the end of everything.
Thank you
Court
Comment