Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Tomas Lind" <tomas.lind@ki.se> |
To | <statalist@hsphsun2.harvard.edu> |
Subject | SV: st: foreach |
Date | Tue, 29 Jun 2010 17:33:34 +0200 |
Yeas, The variable names are saba_L, saba_B, laba_L, laba_B etc etc. saba and laba are not variable names. The code below works foreach XX in saba laba { tab `XX'_L if `XX'_B != . } /Tomas -----Ursprungligt meddelande----- Från: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] För Martin Weiss Skickat: den 29 juni 2010 16:43 Till: statalist@hsphsun2.harvard.edu Ämne: AW: st: foreach <> So the -foreach- question has been solved, but in combination with "_B" and "_L" the "saba" and "laba" still yield valid -varname-s, right? Otherwise commands inside the loop will complain, I guess... HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Tomas Lind Gesendet: Dienstag, 29. Juni 2010 15:19 An: statalist@hsphsun2.harvard.edu Betreff: SV: st: foreach It works! Yeas, saba, laba etc are not variable names. Thanks a lot!!!!!!!!! /Tomas -----Ursprungligt meddelande----- Från: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] För Richard Goldstein Skickat: den 29 juni 2010 14:51 Till: statalist@hsphsun2.harvard.edu Ämne: Re: st: foreach "saba" and "laba" are, apparently, not variable names so this is not a varlist; try -foreach XX in saba laba {- Rich On 6/29/10 8:44 AM, Tomas Lind wrote: > Dear all, > > I have a lot of variables ending up with _L or _B (for example saba_B, > saba_L, laba_B, laba_L) > > If I simplify my problem I would like to do the following > > foreach XX of varlist saba laba { > tab `XX'_B if `XX'_L != . > } > > But it doesn't work. > > Does anyone have an idea how to fix this? > > > /Tomas * * 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/ * * 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/