Statalist The Stata Listserver

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

st: RE: Dear statalist,

From   "Nick Cox" <>
To   <>
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" 


pupil friend
Tony  Gordon
Gordon Tony 

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


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:

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