|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: merging dataset
--- Rima Chakravarty <[email protected]> wrote:
> Wondering if anybody can help me with this. I want to merge two
> dataset (AA and BB) based on ID.
>
> Dataset AA
> ID Var 1 Var 2 Var 3
> 12 785 . 748
> 45 74 2 63
> 74 789 0 7485
>
>
> Dataset BB
> ID Var 1 Var 2 Var 3
> 12 . 45 748
> 94 41 78 74
> 74 789 0 7485
>
> I have used the merge command but the problem with that is that the
> dataset BB has missing value for ID =12 (Var 1). I want to replace
> the non-missing value in the merged dataset with the missing value
> and I think the merge command do not do that. Everything else did
> correctly.
*--------------- begin example ------------------
drop _all
input id aavar1 aavar2 aavar3
12 785 . 748
45 74 2 63
74 789 0 7485
end
sort id
tempfile aa
save `aa'
drop _all
input id bbvar1 bbvar2 bbvar3
12 . 45 748
94 41 78 74
74 789 0 7485
end
sort id
merge id using `aa'
drop _merge
forvalues i = 1/3 {
replace bbvar`i' = aavar`i' if bbvar`i' == .
rename bbvar`i' var`i'
drop aavar`i'
}
list
*--------------- end example ---------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )
Hope this helps,
Maarten
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/
*
* 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/