Thank you Eric, that worked perfectly!!!
-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Eric G. Wruck
Sent: Tuesday, 26 April 2005 1:33 PM
To: [email protected]
Subject: Re: st: gen new variable from string variables
Hi Belinda:
If I understood your problem correctly, this seems to do the trick:
. gen e11 = 0
. foreach var of varlist icd10* {
2. replace e11 = 1 if substr(`var',1,3) == "E11"
3. }
(5 real changes made)
(1 real change made)
(0 real changes made)
. l
+----------------------------------------+
| id icd10_1 icd10_2 icd10_3 e11 |
|----------------------------------------|
1. | 1 K61.3 Z86.43 F05.9 0 |
2. | 2 B95.8 Z06.2 Z86.43 0 |
3. | 3 E11.69 R40.2 E11.9 1 |
4. | 4 Z86.43 Z95.8 E87.6 0 |
5. | 5 K59.0 K59.0 Z93.1 0 |
|----------------------------------------|
6. | 6 E11.65 E11.66 R63.4 1 |
7. | 7 E11.22 E66.9 E11.23 1 |
8. | 8 E11.9 E78.0 K63.50 1 |
9. | 9 E78.0 E11.65 D50.9 1 |
10. | 10 E11.65 K59.0 Z93.0 1 |
+----------------------------------------+
. drop if e11 == 0
(4 observations deleted)
. l
+----------------------------------------+
| id icd10_1 icd10_2 icd10_3 e11 |
|----------------------------------------|
1. | 3 E11.69 R40.2 E11.9 1 |
2. | 6 E11.65 E11.66 R63.4 1 |
3. | 7 E11.22 E66.9 E11.23 1 |
4. | 8 E11.9 E78.0 K63.50 1 |
5. | 9 E78.0 E11.65 D50.9 1 |
|----------------------------------------|
6. | 10 E11.65 K59.0 Z93.0 1 |
+----------------------------------------+
Eric
>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
>>
--
===================================================
Eric G. Wruck
Econalytics
2535 Sherwood Road
Columbus, OH 43209
ph: 614.231.5034
cell: 614.327.4182
fax: 614.231.5039
eFax: 614.573.6639
eMail: [email protected]
website: http://www.econalytics.com
====================================================
*
* 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/
*
* 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/