Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Listing var1 if var* equals X
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Listing var1 if var* equals X
Date
Tue, 31 Jan 2012 15:04:38 +0100
-- on Tue, Jan 31, 2012 at 2:32 PM, Lars Folkestad wrote:
>>> 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
--- Den 31/01/12 14.48 skrev "Maarten Buis" :
>>list if inlist("X2", hospital1, hospital2, hospital3)
--- On Tue, Jan 31, 2012 at 2:51 PM, Lars Folkestad wrote:
> This helps, but i have 147 hospitals.
> Is it possible without having to write them all down?
Not using -inlist-. I would probably end up using a loop in your case.
Something like:
gen byte hasX2 = 0
forvalues i = 1/147 {
replace hasX2 = hasX2 + ( hospital`i' == "X2" )
}
list if hasX2>0
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/