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]

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/

**References**:**st: unsort while merging***From:*tashi lama <ltashi32@hotmail.com>

**Re: st: unsort while merging***From:*Fernando Rios Avila <f.rios.a@gmail.com>

- Prev by Date:
**RE: st: unsort while merging** - Next by Date:
**Re: st: q-q plots, theoretical distribution with values higher than the sample's cutoff point** - Previous by thread:
**Re: st: unsort while merging** - Next by thread:
**Re: st: unsort while merging** - Index(es):