Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
arne.weiss@uni-erfurt.de |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: using value of one variable to read value of specific other variable out of a list of variables |

Date |
Mon, 09 May 2011 19:52:33 +0200 |

Nick Cox schrieb:

gen z = cond(y == 1, x1, cond(y == 2, x2, x3))Nickn.j.cox@durham.ac.ukarne.weiss@uni-erfurt.deI want to create a variable (z) that contains the value from onevariable out of a list of variables (say x1 - x3) depending on thevaluable of another variable (y). The list of variables is a) named in away that the value of y could be used to refer to the correct name ofthe variable and b) ordered so that the value of y could also be used alocational reference (as the offset command does in Excel). I don'tthink b) could work in STATA, but I couldn't find a solution for a)either. See below an example. Therein, z in the first row is supposed tobe 1 and in the second row 5 (if y = 2, z is supposed to have the valueof x2).x1 x2 x3 y 1 2 3 1 0 5 4 2Here is the closest I came towards a solution:local a = y gen z = x`a'This command, however, only does half the job as the value of the locala is not being rest for every row. I would be very happy for any advice.* * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

Best Arne -- Dr. Arne Robert Weiß

Fax: +49 361 737 4569

* * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: using value of one variable to read value of specific other variable out of a list of variables***From:*arne.weiss@uni-erfurt.de

**st: RE: using value of one variable to read value of specific other variable out of a list of variables***From:*Nick Cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**RE: st: nokey for spearman** - Next by Date:
**st: RE: RE: using value of one variable to read value of specific other variable out of a list of variables** - Previous by thread:
**st: RE: using value of one variable to read value of specific other variable out of a list of variables** - Next by thread:
**st: RE: RE: using value of one variable to read value of specific other variable out of a list of variables** - Index(es):