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   tashi lama <ltashi32@hotmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: unsort while merging
Date   Wed, 18 Jul 2012 17:43:25 +0000

awesome...thanx..

----------------------------------------
> Date: Wed, 18 Jul 2012 12:38:11 -0400
> Subject: Re: st: unsort while merging
> From: f.rios.a@gmail.com
> To: statalist@hsphsun2.harvard.edu
>
> Hi Tashi
> I might suggest an indirect solution.
> Before you merge your master data, you can create an index variable:
> gen n=_n
> so after you merge it, you can just sort it by n, and the final
> version will have a similar (if not the same) structure as it
> originally had.
> Hope this helps
> Fernando
>
> On Wed, Jul 18, 2012 at 12:22 PM, tashi lama <ltashi32@hotmail.com> wrote:
> >
> > 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/
>
> *
> * 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/ 		 	   		  
*
*   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