Statalist


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

Re: st: question regarding "merge"


From   fultonb@berkeley.edu
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: question regarding "merge"
Date   Thu, 9 Aug 2007 02:07:36 -0700 (PDT)

Hi Simon,

Before merging your fourth dataset, try the following:

bysort id: gen index=_n
reshape wide VariableY, i(id) j(index)

Brent Fulton


> Dear Stata Users,
>
> 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. To illustrate my problem better, I will give you a quick
> example:
>
> 1st dataset before "merge":
>
> ID  VariableX
> 1   40
> 2   30
> 3   20
> 4   10
>
>
> 4th dataset before "merge":
>
> ID  VariableY
> 1   10
> 2   20
> 2   25
> 2   30
> 3   30
> 4   40
>
>
> The results of my combined dataset looks like that:
>
> ID  VariableX  VariableY
> 1   40         10
> 2   30         20
> 2   30         25
> 2   30         30
> 3   20         30
> 4   10         40
>
>
> And finally I would like them to look like that:
>
> ID  VariableX  VariableY1  VariableY2  VariableY3
> 1   40         10
> 2   30         20          25          30
> 3   20         30
> 4   10         40
>
>
> I really appreciate your help and I am thankful for any suggestions.
> Simon
>
> *
> *   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/
>


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index