Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: Merge two datasets by more than one variable


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: Merge two datasets by more than one variable
Date   Thu, 2 Jul 2009 14:01:03 +0200

<> 



*************
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: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Thomas Cars
Gesendet: Donnerstag, 2. Juli 2009 13:50
An: statalist@hsphsun2.harvard.edu
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/



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