Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Listing var1 if var* equals X |
Date | Tue, 31 Jan 2012 13:57:21 +0000 |
What you are doing wrong is that wildcards indicating varlists are not allowed in expressions. Also, you must use == not = to test for equality. You could try this ... if inlist(X2, hospital1, hospital2, hospital3) but there are limits on the number of arguments allowed. Next up in complexity is to use -egen, anymatch()- to create an indicator for use with integer codes. If your code is string and you have lots of hospitals, if you do not map to integers you may need to do something more like gen OK = 0 qui foreach v of var hospital* { replace OK = 1 if `v' == "X2" } list ... if OK Also, the Seventh Law of Stata is that most things are easier with a long structure than with a wide structure. Nick On Tue, Jan 31, 2012 at 1:32 PM, Lars Folkestad <lfolkestad@health.sdu.dk> wrote: > Dear List > > I am sure there is a quick fix for this, but i have my data in a wide format and have the following data > > Id hospital1 hospital2 hospital3 … hospitalN > > I would like to list the id if any of the hospital* equals a given code fx X2 > > I have tried > . list id if hospital* = X2 > But that dos not work. > > What am i doing wrong? * * 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/