Bookmark and Share

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: identifying observations where multiple conditions are met


From   Richard Goldstein <[email protected]>
To   [email protected]
Subject   Re: st: identifying observations where multiple conditions are met
Date   Wed, 13 Nov 2013 16:25:51 -0500

sorry for my typo - should be -egen- rather than -gen-

Rich

On 11/13/13, 4:22 PM, Michael McCulloch wrote:
> Thanks Richard, when I enter the first line of code:
> 
> . gen byte mintype=min(type), by(id)
> 
> I get "invalid syntax
> r(198);"
> 
> I'm using:
> Stata/IC 13.0 for Mac (64-bit Intel)
> Revision 07 Oct 2013
> 
> Is there a command I need to download?
> 
> Best wishes,
> Michael McCulloch
> 
> --
> Pine Street Foundation, since 1989
> 124 Pine Street | San Anselmo | California | 94960-2674  
> P: (415) 407-1357 | F: (206) 338-2391 | http://www.PineStreetFoundation.org
> 
> On Nov 13, 2013, at 12:26 PM, Richard Goldstein wrote:
> 
>> if I understand what you are asking for correctly, I would do the following:
>>
>> gen byte mintype=min(type), by(id)
>> gen byte maxtype=max(type), by(id)
>> ta id if mintype==0 & maxtype==1
>>
>> note that if there are a maximum of 2 occurrences of the id there are
>> ways to do this in one statement, but from what you said it appears that
>> id can occur more than 2 times
>>
>> Rich
>>
>> On 11/13/13, 3:14 PM, Michael McCulloch wrote:
>>> Hello,
>>> I have data of the structure:
>>> 	id 		(range 1 to 300)
>>> 	type 	(for each -id-, should equal only one of two values: 0 or 1).
>>>
>>> In manual inspection of the data, I see instances exist where, for the same -id-, 
>>> 	some records have type==0, and  
>>> 	other records have type==1.
>>>
>>> If I enter 
>>> 	. tab id if type==0 & type==1
>>> obviously "no observations" is returned.
>>>
>>> How would I write a command in which I can tabulate all -id- for which some 
>> observations exist where type==0, and others where type==1? (At data entry,
>> -type- should have unique for each -id-.)
>>>
>>>
>>> Best wishes,
>>> Michael McCulloch
>>>
>>> --
>>> Pine Street Foundation, since 1989
>>> 124 Pine Street | San Anselmo | California | 94960-2674  
>>> P: (415) 407-1357 | F: (206) 338-2391 | http://www.PineStreetFoundation.org
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index