Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: multiple if


From   Christopher Baum <[email protected]>
To   [email protected]
Subject   st: multiple if
Date   Sun, 11 May 2003 18:42:35 -0400

>Hi,
>
>I have the following problems
>
>I have variable index which takes values from 1-10
>
>I have variables demand1 - demand10
>depending upon the value of index, I have to select the value of demand 1
>
>i.e.
>
>if index==1, dem1 = demand1
>if index==2, dem1 = demand2
>if index==3, dem1 = demand3

Not in one statement, but...

g dem1=0
forv i=1/10 {
replace dem1=dem1+(index==`i')*demand`i'
}

Kit



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index