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

From |
"Brian Karfunkel" <[email protected]> |

To |
[email protected] |

Subject |
st: Looking up which observation has a particular value |

Date |
Thu, 7 Aug 2008 15:37:57 -0700 |

Hello everyone, If I have a dataset that looks like this: +--------------------+ | name age | |---------------------| 1. | Smith 42 | 2. | Kellog 28 | 3. | McCairn 19 | 4. | Jones 22 | +-------------------+ I want to use a particular value of one variable to look up, and then store in a local (or scalar, if need be) the value of another variable iIN THAT SAME ROW. In other words, I want to do something like this (this is of course pseudocode; I understand that locals don't work like this): - local jones_age = age if name == "Jones" or maybe: - local jones_obs = (some function that returns the row number of the first observation for which name == "Jones") - local jones_age = age in `jones_obs' One thought I had was to either create a variable, say age_jones, and: - gen age_jones = age if name == "Jones" And then maybe -sum- age_jones, using the return code to find the age (which if the obs. is unique should be min, max, and mean), but since my data is actually many more than four observations long, this seems rather cumbersome. For those of you familiar with Excel, I'm looking for something similar to the VLOOKUP and HLOOKUP commands. Any suggestions? Is there a way to create locals from variable values? Thanks for any help you can provide. -Brian Karfunkel * * 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**:**Re: st: Looking up which observation has a particular value***From:*"Sergiy Radyakin" <[email protected]>

- Prev by Date:
**st: RE: Matching Names** - Next by Date:
**st: RE: Compute means of coefficients** - Previous by thread:
**st: Compute means of coefficients** - Next by thread:
**Re: st: Looking up which observation has a particular value** - Index(es):

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