| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: merging on same using dataset
The key here I think is to use the -fillin- command to expand the master
dataset and the use a single merge. You can flag the unchosen choices using
the _fillin var. I showed how to change the _merge var based on this.
use master
fillin Indiv choice
sort choice
merge choice using usingdata
replace _merge=2 if _fillin==1
Michael Blasnik
----- Original Message -----
From: "Munro, Cameron" <[email protected]>
To: <[email protected]>
Sent: Friday, February 03, 2006 11:31 AM
Subject: st: merging on same using dataset
I'm building up a choice dataset where I need to read in the
characteristics of the alternatives for each individual. A simplified
example of what I want to happen:
Master data -
Indiv Choice
1 2
2 4
... ...
Using data -
Choice x1 x2 ...
1 10 12
2 14 13
3 17 18
4 43 13
5 12 15
Desired output -
Indiv Choice x1 x2 _merge
1 1 10 12 2
1 2 14 13 3
1 3 17 18 2
1 4 43 13 2
1 5 12 15 2
2 1 10 12 2
2 2 14 13 2
2 3 17 18 2
2 4 43 13 3
2 5 12 15 2
In effect, what I want to do is merge sequentially down each observation
in the master dataset in turn. The only way I can achieve this at the
moment is to create separate files for each obs and then append them
together after running the merge on each separately. But this results in
many files, and is slow. Is there a better way?
Cheers
Cameron.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/