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]

st: unsort while merging


From   tashi lama <[email protected]>
To   <[email protected]>
Subject   st: unsort while merging
Date   Wed, 18 Jul 2012 16:22:36 +0000

Hello, 

     Stata sorts the variable after merging. I have a situation where I want to keep it the way it is(unsorted) after merge. Here is my dataset 

 

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

   

when I do   merge m:1 id using file1, keep(match)

 

         location   id      name        _merge |
     |---------------------------------------|
  1. |        B    1       Tom   matched (3) |
  2. |        C    1       Tom   matched (3) |
  3. |        A    1       Tom   matched (3) |
  4. |        B    2      Jack   matched (3) |
  5. |        A    2      Jack   matched (3) |
     |---------------------------------------|
  6. |        A    3   Michael   matched (3) |
  7. |        C    3   Michael   matched (3) |


 

As can be seen, the master dataset is grouped by location. After merge the group is broken since merge has sorted id. Immediate thought is to merge by group but merge doesn't allow by. I don't care much if it sorts inside the group location like follows. Any idea...

 

A   1     Tom

A   2      Jack  

A   3      Michael

B   1      Tom

B   2      Jack

C   1      Tom 
C   3      Michael

 

Thanx..

 

  		 	   		  
*
*   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