In the following, I did not enter the duplicated id number. This can be done
with the following change in on line of code
Replace
replace dup = 1 if f`i'==f`j' & f`i' != .
With
replace dup = f`i' if f`i'==f`j' & f`i' != .
Of course, if the person duplicated more than one id, then only the most
recent one will be identified with this particular code. You could count the
duplicates by the following code
drop dup
gen dup = 0
forvalues j = 2/9 {
local k = `j' - 1
forvalues i = 1/`k' {
replace dup = dup+1 if f`i'==f`j' & f`i' != .
}
}
Peter J. Burke
Professor
Department of Sociology
University of California
Riverside, CA 92521-0419
Phone: 951/827-7004
Fax: 951/827-3330
[email protected]
http://wat2146.ucr.edu
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Peter J. Burke
Sent: Tuesday, October 24, 2006 2:54 PM
To: [email protected]
Subject: st: RE: duplicate values of variables
Carter,
Here is a code snippet that worked in a quick example for the
following data
+--------------------------------------------------------+
| aid f1 f2 f3 f4 f5 f6 f7 f8 f9 dup |
|--------------------------------------------------------|
1. | 22 12 23 23 44 . . . . . 1 |
2. | 33 33 67 90 . 78 99 . . . . |
3. | 44 56 89 90 88 . . . . . . |
4. | 55 34 34 35 . 34 67 89 90 77 1 |
5. | 66 65 . . . . . . . . . |
+--------------------------------------------------------+
drop dup
gen dup = .
forvalues j = 2/10 {
local k = `j' - 1
forvalues i = 1/`k' {
replace dup = 1 if f`i'==f`j' & f`i' != .
}
}
Peter J. Burke
Professor
Department of Sociology
University of California
Riverside, CA 92521-0419
Phone: 951/827-7004
Fax: 951/827-3330
[email protected]
http://wat2146.ucr.edu
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Carter Rees
Sent: Tuesday, October 24, 2006 12:47 PM
To: [email protected]
Subject: st: duplicate values of variables
Statalist,
I have a data set in which the unit of analysis is the survey respondent.
Each respondent was asked to nominate up to ten friends and enter a unique
id for those friends in the variables friend1-friend10. What I would like
to do is run a search through friend1-10 for each respondent to identify if
the respondent nominated any of the friends more than once by mistake. If
they did I would like to be able to create a variable(s) which let me know
the id of the duplicated friend.
Aid f1 f2 f3 f4 f5 f6 f7 f8 f9 f10
22 12 23 23 44 . . . . .
.
33 33 67 90 . 78 99 . . .
.
44 56 89 90 88 . . . . .
.
55 34 35 35 . 34 67 89 90 77
66
Cheers,
Carter
*
* 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/
*
* 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/
*
* 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/