Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Dear statalist,


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Dear statalist,
Date   Thu, 10 May 2007 13:44:21 +0100

If the ids are numeric, then 

gen both = string(min(pupil, friend)) + " " + string(max(pupil, friend)) 

and if they are string, then 

gen both = cond(pupil < friend, pupil, friend) + " " + cond(pupil < friend, friend, pupil) 

Now search for -duplicates- on both. 

Suppose "Tony" names "Gordon" as his best friend, and vice versa. 
It is true that "Gordon" < "Tony" as inequalities with strings are 
based on alphanumeric order. 

Either way, 

pupil friend 
42 24
24 42

will both be mapped to "24 42" 

and 

pupil friend
Tony  Gordon
Gordon Tony 

will both be mapped to "Gordon Tony". Then, as said, look for
-duplicates-. 

Nick 
[email protected] 

Phillip Sinclair PhD (Lond) MSc BSc
 
> I have a data list of the following form:
> 
> 1. pupil id ... friend id
> 2. pupil id ... friend id
> 3. etc
> 
> Each pupil can have several friends, each listed as a 
> separate case i.e. there can be several cases with the same 
> pupil id each case identifying a separate friend.
> I wish to create a new variable to identify reciprocated 
> friendship choices  e.g. where pupil A names pupil B as a 
> friend and pupil B names pupil A as a friend.
> Please can you tell me of a simple way of doing this in STATA.
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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