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

Re: st: multiple if??


From   Nick Cox <n.j.cox@durham.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: multiple if??
Date   Sun, 11 May 2003 19:52:03 +0100

Vimalanand S. Prabhu <prabhu@unc.edu>

> 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
> ...
> 
> and so on
> 
> Is there any easy way (or a single command) to do this

The easiest way which springs to mind is 

gen dem1 = . 
forval i = 1/10 { 
	qui replace dem1 = demand`i' if index == `i' 
} 	


Nick
n.j.cox@durham.ac.uk
*
*   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/