Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: question regarding "merge"


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: question regarding "merge"
Date   Thu, 9 Aug 2007 10:08:50 +0100 (BST)

--- Simon Oertel <[email protected]> wrote:
> I have a question regarding the combination of four datasets. I used
> the -merge- command which worked well for three of them. However, the
> fourth dataset makes me trouble. 
> 
> All datasets have a variable which enables me to combine them (an ID
> that is similar in all datasets). The fourth dataset holds different
> information in different rows for the same ID. My problem is that if
> I merge the datasets, the number of cases in my final dataset will
> increase. 

What you want is to -reshape- file 4 first in wide format, see -help
reshape- and the example below:

*---------- begin example ------------
drop _all
tempfile file4
input ID  VariableY
1   10
2   20
2   25
2   30
3   30
4   40
end

bys ID: gen t = _n
reshape wide VariableY, i(ID) j(t)
sort ID
save `file4'

drop _all
input ID  VariableX
1   40
2   30
3   20
4   10
end
sort ID 
merge ID using `file4'
tab _merge
drop _merge
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! Mail is the world's favourite email. Don't settle for less, sign up for
your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.html 
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index