[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Merge question
Rohit Sonika <email@example.com>
st: Merge question
Sat, 30 Mar 2013 20:53:39 +0000
I think I managed to figure it out.
I first created a variable count as follows:
bys id year: gen count = _n
This creates a count of observations per id-year, which also forms the 'j' option in -reshape-. After this, -reshape- works as follows:
reshape wide return exdate, i(id year) j(count)
Thanks for helping me out with this.
On 30 Mar 2013, at 18:40, Rohit Sonika <firstname.lastname@example.org> wrote:
> I am afraid -reshape- wouldn't work if the using dataset has multiple observations per id-year.
> On 30 Mar 2013, at 18:12, Rohit Sonika <email@example.com> wrote:
>> Dear Statalist,
>> I have a rather odd question concerning -merge-.
>> I am trying to do a -merge 1:m- using two datasets. I understand that when using the 1:m command, I am asking for duplicate matches to be added below other matches. However, is it possible to, instead of creating duplicate rows, add extra columns for vars in keepusing options?
>> For instance, if I am trying to match two datasets based on id and year while only keeping return and exdate from the using file, the merge command would look something like this:
>> merge 1:m id year using "XXXX", keepusing(return exdate)
>> Depending on the number of additional matches per id and year, is it possible to create extra variables like return1, return2, etc. and exdate1, exdate2, etc. rather than duplicate the entire observation? Hence, if for a given id and year there are 3 matches, it should create two additional return and exdate variables (return1, return2, exdate1 and exdate2) for the two additional matches (the first match being stored in return and exdate).
>> Thanks a lot for your help.
* For searches and help try: