Statalist The Stata Listserver


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

Re: st: duplicate values of variables


From   Jeph Herrin <jherrin@flyingbuttress.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: duplicate values of variables
Date   Tue, 24 Oct 2006 17:49:47 -0400

Correction, it's called -sortrows- (note the 's') and you'll
have to type "findit sortrows".

Jeph

Jeph Herrin wrote:
I think you want to get -sortrow- (type 'search sortrows');
once you create sorted rows, then it is easy:

sortrow f1-f10, gen(sf)
gen tmp=0           /* assuming no friends are zeroes... */
gen flag=0
forv f=1/10 {
    replace flag=1 if sf`f'==tmp
    replace tmp=nf`f' if sf`f'>tmp&sf`f'<.
}

every obs with two same values in a row gets -flag-ged.

hth,
Jeph



Carter Rees wrote:
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/



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