Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: unsort while merging


From   Ronnie Babigumira <[email protected]>
To   [email protected]
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index