Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Re: Challenging foreach problem


From   [email protected]
To   [email protected]
Subject   Re: st: Re: Challenging foreach problem
Date   Sun, 13 Nov 2011 20:53:05 +0000

Sent via BlackBerry® from Vodafone

-----Original Message-----
From: daniel klein <[email protected]>
Sender: [email protected]
Date: Sun, 13 Nov 2011 14:41:30 
To: <[email protected]>
Reply-to: [email protected]
Subject: st: Re: Challenging foreach problem

Anwar,

I am not entirely sure, what exactly you are trying to do, partly
because this is not my field. From your code I understand, that you
want to create a number of indicator variables. Probabaly you want
something like:

loc A `""350.2", "352.12", "368.58""'
loc B `""354.15" "387.89" "369.56""'

loc i 0
foreach x in A B {
    foreach v of varlist pdx-sdx8 {
        g byte `v'disease_`x' = inlist(`v', ``x'')
    }
}

Note the underscore "_" in "`v'disease_`x'" replacing the embedded
space in your code, which is not allowed in variable names.

Best
Daniel

-- 

Dear Statlist reader ,


I am working on a patient dataset  with patients identification code
observation( each row), and 15 variables containing ICD9 diagnosis
codes ( string varaibles) .Part of the dataset if posted below

For diseases of my interest
1)disease A with icd9 codes "350.2" "352.12" "368.58"
2)disease B("354.15" "387.89" "369.56") ]

 I am using the foreach command

foreach x in pdx sdx1 sdx2 sdx3 sdx4 sdx5 sdx6 sdx7 sdx8{
icd9 gen `x'disease A=`x', range"350.2" "352.12" "368.58")
}

foreach x in pdx sdx1 sdx2 sdx3 sdx4 sdx5 sdx6 sdx7 sdx8{
icd9 gen `x'disease B=`x', range"354.15" "387.89" "369.56")
}

[...]
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index