# st: RE: RES: RE: make use of values of some variables to identify another variable

 From "Nick Cox" <[email protected]> To <[email protected]> Subject st: RE: RES: RE: make use of values of some variables to identify another variable Date Tue, 8 Apr 2008 18:49:24 +0100

```Good. Note that once you have looked up all the values, you need not do that all over again. Thus, your test
could be just

if !mi(`var1', `var2', `var3', `var4') {
replace variable_new = cod_`var1'`var2'`var3'`var4'* sqrt(var5) in `i'
}

Maria Dolores Montoya Diaz

Dear Nick, thank you very much!!! It�s not the most efficient solution but
it functions very well. Besides, I�ve introduced an if condition to
eliminate problems with missing values. So the final version:

gen variable_new = .
qui forval i = 1/`=_N' {
local var1 = var1[`i']
local var2 = var2[`i']
local var3 = var3[`i']
local var4 = var4[`i']
if mi(var1[`i'], var2[`i'] ,var3[`i'] , var4[`i'] )==0 {
replace variable_new = cod_`var1'`var2'`var3'`var4'* sqrt(var5) in `i'
}
}

Nick Cox

gen variable_new = .

qui forval i = 1/`=_N' {
local var1 = var1[`i']
local var2 = var2[`i']
local var3 = var3[`i']
local var4 = var4[`i']
replace variable_new = cod_`var1'`var2'`var3'`var4' * sqrt(var5) in
`i'
}

That's not going to be very fast, but it's perhaps more transparent than
alternatives.

Maria Dolores Montoya Diaz

I�m trying  to make use of the combination of the values of four variables
(var1-var4) to identify another variable among a big list, which content
will be part of another operation. The situation is:

var1   var2  var3      var4 ...   cod_0001     cod_0002
.....  cod_1032
obs 1         1          0        3          2    ...    0.2435
0.5572       .....    0.3453
obs 2         0          0        0          1    ...    0.0632
0.1023       .....    0.5532
:

So, for obs 1, the variable selected will be cod_1032, for obs 2, cod_0001,
and so on. I need to do something like this:

gen variable_new = cod_`var1'`var2'`var3'`var4' *  sqrt(var5)

*
*   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/
```