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 |
"MacLennan, Graeme" <g.maclennan@abdn.ac.uk> |

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

Subject |
st: RE: create local with specific value of a variable |

Date |
Wed, 20 Feb 2013 15:54:35 +0000 |

Pablo asked: Sometimes I need to save in a local a specific value of a variable and I cannot do it because creating a local does not support "if" neither "in" conditions. For instances, let's suppose that I have two variables: "x" and "y". Variable "x" goes from 1 to 100 and "y" is a random vector. Now, how can I save in a local the value of "y" when "x" is, for example, 50? In other words, I would like to do something like this: local y50 = y if x == 50 Something like this perhaps? *** example start *** * This assumes that y is constant within categories of x clear sysuse auto local num = 41 summ mpg if mpg == `num' local mpg`num' = r(mean) di "`mpg41'"*** example end *** *** example end *** HTH, Graeme. Graeme MacLennan Senior Statistician Health Services Research Unit Health Sciences Building University of Aberdeen Foresterhill Aberdeen AB25 2ZD Tel: +44 (0)1224 438147 Fax +44 (0)1224 438165 Email: g.maclennan@abdn.ac.uk Web: www.abdn.ac.uk/hsru Sometimes I need to save in a local a specific value of a variable and I cannot do it because creating a local does not support "if" neither "in" conditions. For instances, let's suppose that I have two variables: "x" and "y". Variable "x" goes from 1 to 100 and "y" is a random vector. Now, how can I save in a local the value of "y" when "x" is, for example, 50? In other words, I would like to do something like this: local y50 = y if x == 50 I know that is not possible and it is actually a "heresy" in Stata language but it might give you an idea of what I need. Thank you so much for your help and any idea is more that welcome. Best ---- Pablo Bonilla * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/ The University of Aberdeen is a charity registered in Scotland, No SC013683. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**References**:**st: create local with specific value of a variable***From:*Pablo Bonilla <pablo.bonilla1234@gmail.com>

- Prev by Date:
**Re: st: create local with specific value of a variable** - Next by Date:
**Re: st: create local with specific value of a variable** - Previous by thread:
**st: Sampling question: whether to stratify** - Next by thread:
**Re: st: create local with specific value of a variable** - Index(es):