<>
*************
clear*
input ID documentid rownumber str6 (date Time)
1 35 1 "080101" 12.10
1 35 2 "080201" 13.10
1 35 3 "080301" 14.00
2 12 1 "080101" 12.20
2 12 2 "080401" 13.10
3 11 1 "080501" 15.10
3 11 2 "080601" 16.00
3 11 3 "080601" 17.10
end
/*
gen date2=date(date, "DM20Y")
format date2 %tdMonth_DD,_CCYY
*/
save A, replace
drop _all
input ID documentid rownumber str25 Drug
1 35 1 "Metoprolol "
1 35 2 "Atenolol "
1 35 3 "Bisoprolol "
2 12 1 "Salicylic Acid "
2 12 2 "Remicade "
3 11 1 "Folic Acid "
3 11 2 "Enalapril "
3 11 3 "Metoprolol "
end
compress
save B, replace
//merger
u A, clear
merge ID documentid /*
*/ rownumber using "C:\Users\martin\Documents\Stata\B.dta",/*
*/ unique sort
drop _merge
list, noobs
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Thomas Cars
Gesendet: Donnerstag, 2. Juli 2009 13:50
An: [email protected]
Betreff: st: Merge two datasets by more than one variable
Hi,
I would like to merge two datasets by three variables:
Example:
Dataset1:
Id document-id row-number date Time
1 35 1 080101 12.10
1 35 2 080201 13.10
1 35 3 080301 14.00
2 12 1 080101 12.20
2 12 2 080401 13.10
3 11 1 080501 15.10
3 11 2 080601 16.00
3 11 3 080601 17.10
Dataset2:
ID document-id row-number Drug
1 35 1 Metoprolol
1 35 2 Atenolol
1 35 3 Bisoprolol
2 12 1 Salicylic Acid
2 12 2 Remicade
3 11 1 Folic Acid
3 11 2 Enalapril
3 11 3 Metoprolol
I would now like to combine the two datasets above with the result:
Id document-id row-number date Time Drugs
1 35 1 080101 12.10 Metoprolol
1 35 2 080201 13.10 Atenolol
1 35 3 080301 14.00 Bisoprolol
2 12 1 080101 12.20 SalicylAcid
2 12 2 080401 13.10 Remicade
3 11 1 080501 15.10 Folic Acid
3 11 2 080601 16.00 Enalapril
3 11 3 080601 17.10 Metoprolol
Is it possible to do a merge like: merge pat document-id
rownumber using dataset2?
Hope anyone can help me?
Thomas
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/