Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: is ordering with -bysort- unique?

From   Jose Luis Negrin Muñoz <>
To   <>
Subject   st: RE: is ordering with -bysort- unique?
Date   Tue, 10 Jun 2003 16:56:34 -0500


I have used the following small program to get rid of duplicates

	sort ref;
	by ref: gen dup=_n;
	gsort ref -mesini dup;
	drop if dup>1;

where ref is a reference code and mesini is a variable related to time
(1, 2...j); these are the variables I am sorting my data by. So I will
keep only the oldest data with each particular reference code

I hope this example is useful.


-----Mensaje original-----
[] En nombre de Radu Ban
Enviado el: Martes, 10 de Junio de 2003 03:30 PM
Asunto: st: is ordering with -bysort- unique?

dear all,

i'm cleaning a dataset and i encounter repeated ids. i want to keep them

unique, but the problem is that for some repeated ids the variables
i want to keep just one of the repeated ids. so i'm using:

bysort id: keep if _n == 1

now i would like to know if this will keep the same id whenever the
is run. or does the ordering change?

sorry for such a basic question but right now i don't have access to the


thanks so much,

radu ban

*   For searches and help try:

*   For searches and help try:

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