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

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

From |
Mike Lacy <Michael.Lacy@colostate.edu> |

To |
statalist-digest@hsphsun2.harvard.edu |

Subject |
st: Find variable with first occurrence of a value in a list of variables |

Date |
Tue, 13 Jul 2010 07:33:46 -0600 |

set obs 10 forval i = 1/5 { gen byte x`i' = (runiform() > 0.6) } local value_of_interest 1 tempvar found gen byte `found' = 0 gen str varname = "" foreach v of varlist x1-x5 { replace varname = "`v'" if (!`found') & (`v' == `value_of_interest') replace `found' = 1 if (`v' == `value_of_interest') } //

Suggestions? Regards, =-=-=-=-=-=-=-=-=-=-=-=-= Mike Lacy, Assoc. Prof. Soc. Dept., Colo. State. Univ. Fort Collins CO 80523 USA

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

**Follow-Ups**:**st: RE: Find variable with first occurrence of a value in a list of variables***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: Find variable with first occurrence of a value in a list of variables***From:*Maarten buis <maartenbuis@yahoo.co.uk>

**st: AW: Find variable with first occurrence of a value in a list of variables***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**Re: st: Multicollinearity test after GLM** - Next by Date:
**Re: st: AW: Re: Identify and Replace Values** - Previous by thread:
**st: Multicollinearity test after GLM** - Next by thread:
**st: AW: Find variable with first occurrence of a value in a list of variables** - Index(es):