Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: unsort while merging


From   Ronnie Babigumira <rb.glists@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: unsort while merging
Date   Wed, 18 Jul 2012 19:37:49 +0300

One way to is to generate a "sort" variable before merging and then sort on this variable after -merge-

clear
input id str10 name
1 Tom
2 Jack
3 Micheal
end
gen f1sorder = _n
tempfile a
save `a'

clear
input str1 location id
A 1
A 2
A 3
B 2
B 1
C 1
C 3
end
gen f2sorder = _n
tempfile b
save `b'

merge m:1 id using `a', keep(match)

* You can now unsort by sorting on f1sorder or f2sorder as you please.

Ronnie 

-- 
010100100110111101101110011011100110100101100101




On Wednesday, July 18, 2012 at 7:22 PM, tashi lama wrote:

> Using dataset
> 
> id name
> 
> 1 Tom
> 
> 2 Jack
> 
> 3 Micheal
> 
> 
> Master dataset
> 
> location id
> 
> A 1
> 
> A 2
> 
> A 3
> 
> B 2
> 
> B 1
> C 1
> C 3



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index