[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

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 Your idea could be made to work like this: 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/

**References**:**st: RES: RE: make use of values of some variables to identify another variable***From:*"Maria Dolores Montoya Diaz" <madmdiaz@usp.br>

- Prev by Date:
**st: Case Sensitive filenames and filepaths** - Next by Date:
**Re: st: Definition of strata and PSUs when svysetting** - Previous by thread:
**st: RES: RE: make use of values of some variables to identify another variable** - Next by thread:
**[no subject]** - Index(es):

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