Bellinda,
There are several ways to accomplish that. If you have just three variables,
the simplest seems to be
keep if substr(icd10_1,1,3)=="E11" | substr(icd10_2,1,3)=="E11" |
substr(icd10_3,1,3)=="E11"
If you were to keep variables where E11 appears anywhere within the string, not
just the first three characters, you would have to use
keep if index(icd10_1, "E11") | index(icd10_2, "E11") | index(icd10_3, "E11")
Also, if you want to eyeball which observations were flagged by Stata before
deleting them, you can type
gen e11=1 if index(icd10_1, "E11") | index(icd10_2, "E11") | index(icd10_3,
"E11")
keep if e11==1
Hope this helps.
rafal
Quoting "King, Belinda L" <[email protected]>:
> Hi Everyone,
>
> I am wanting to create a variable that tells me whether the patient has an
> ICD10 starting with E11. I am not interested in the numbers after the dots,
> nor am I interested in any of the other ICD10 codes and I am wanting to drop
> patients who do not have E11 in one of the ICD10 columns. I have tried
> playing with foreach, but this side of things is new for me and I just keep
> getting messages telling me the syntax is incorrect. I would greatly
> appreciate any hints someone could give me, thank you in advance.
>
> +----------------------------------+
> | id icd10_1 icd10_2 icd10_3 |
> |----------------------------------|
> 1. | 1 K61.3 Z86.43 F05.9 |
> 2. | 2 B95.8 Z06.2 Z86.43 |
> 3. | 3 E11.69 R40.2 E11.9 |
> 4. | 4 Z86.43 Z95.8 E87.6 |
> 5. | 5 K59.0 K59.0 Z93.1 |
> |----------------------------------|
> 6. | 6 E11.65 E11.66 R63.4 |
> 7. | 7 E11.22 E66.9 E11.23 |
> 8. | 8 E11.9 E78.0 K63.50 |
> 9. | 9 E78.0 E11.65 D50.9 |
> 10. | 10 E11.65 K59.0 Z93.0 |
> +----------------------------------+
>
> Cheers,
> Bellinda
>
>
>
>
>
> *
> * For searches and help try:
> * http://www.stata.com/support/faqs/res/findit.html
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
================
Rafal Raciborski
Graduate student
Department of Political Science
Emory University
301 Tarbutton Hall
1555 Dickey Drive
Atlanta, GA 30322
404-378-9826 (home)
[email protected] (e-mail)
www.roofoos.net
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/