[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: foreach commands |

Date |
Tue, 14 Apr 2009 15:30:50 +0100 |

A few days ago, I posted some generic advice within <http://www.hsph.harvard.edu/cgi-bin/lwgate/STATALIST/archives/statalist.0904/date/article-217.html> Some of that applies here: Experiment with simple cases ============================ If you're unsure about what a definition implies, experiment with simple cases. Let Stata tell you. Illustrate your problem with mutually accessible data ===================================================== We don't have your data, which makes it harder to get to the position you are in. Don't say "it didn't work"; say what happened ============================================= I have an evolving private document detailing (so far) 19 different senses of "didn't work", collected from Statalist postings. Even Stata experts familiar with what you are doing often can't tell what you mean when you say "it didn't work". My own experiments don't indicate anything wrong with Nigussie's approach: . sysuse auto (1978 Automobile Data) . foreach w of var price- rep78 { 2. foreach x of var trunk-length { 3. di "`w' `x'" 4. } 5. } price trunk price weight price length mpg trunk mpg weight mpg length rep78 trunk rep78 weight rep78 length So, what didn't work, precisely? Nick n.j.cox@durham.ac.uk nigussie Tefera I want to generate variables containing lnpindexprice11-lnpindexprice111 and multiply them by wrfoodexpy11-wrfoodexpy111 and replace lnpindexprce*, respectively. I used foreach commond as follows but it works only for the first column i.e lnpindexprice11 but not for the other. Would you assist me please foreach w of varlist wrfoodexpy11- wrfoodexpy111 { foreach x of varlist pindexprice11-pindexprice111 { gen l`x'=ln(`x') gen lt`x'=l`x'*`w' } drop `x' } * * 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/ * * 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: AW: RE: foreach commands***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**References**:**st: foreach commands***From:*nigussie Tefera <nitefera@yahoo.com>

- Prev by Date:
**st: New Stata package -saswrapper- on SSC that runs SAS code from within Stata** - Next by Date:
**Re: st: AW: summarize variables without collapsing** - Previous by thread:
**st: AW: foreach commands** - Next by thread:
**st: AW: RE: foreach commands** - Index(es):

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