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: Fwd: Nested Foreach Comparing too Many Variables
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Fwd: Nested Foreach Comparing too Many Variables
Date
Fri, 22 Mar 2013 10:06:55 +0000
Yes. You will kick yourself.
forval j = 1/5 {
replace complex_severity=1 ///
if inlist(Diagnosis`j',"710","714","715","720","725","733")
& inrange(Severity`j', 2, .)
}
-inrange()- is another way to handle your second comparison. What you
had is fine; I just showed you another way.
Nick
On Fri, Mar 22, 2013 at 9:57 AM, William Sankey <[email protected]> wrote:
> I am running the following nested foreach and am afraid I am comparing
> too many things:
>
> local DIAG "Diagnosis1 Diagnosis2 Diagnosis3 Diagnosis4 Diagnosis5"
> local SEV "Severity1 Severity2 Severity3 Severity4 Severity5"
>
> foreach X of varlist `DIAG' {
> foreach Y of varlist `SEV' {
> replace complex_severity=1 if
> inlist(`X',"710","714","715","720","725","733") & (`Y'>=2 & `Y' !=.)
> }
> }
>
> I would like to compare Diagnosis1 with Severity1 but fear the code is
> comparing Diagnosis1 with every severity level.
>
> Could you recommend a better way of achieving the goal; something
> along the lines of a different array?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/