Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Fwd: Mergeing datasets


From   Lars Ängquist <[email protected]>
To   <[email protected]>
Subject   Re: st: Fwd: Mergeing datasets
Date   Sat, 30 Apr 2011 01:49:51 +0200

Dear Thomas.

This seems to be solved by an application of the - reshape long - functionality. Try, with respect to the former dataset, stating

   reshape long id, i(master) j(nbr)

and you are already there (without even considering the latter id-based dataset). However, if the latter one additionally includes other variables of interest then you can simply apply a - merge - as a second step

   use data1, clear
   merge 1:1 id using data2

where the former and latter datasets here are referred to as 'data1' and 'data2' respectively. Moreover, I have here assumed that the id:s originally distributed over id1-id4 are unique within the corresponding data matrix (though this is in principle not important; if not being true, simply use - merge 1:m - or - merge m:1 - instead). One may also note that the derived variable 'nbr' will, prepared to being used if needed, hold the information on from which original id-variable each id-value originates (here through integers 1-4).

I hope this will help you solving your problem.

With best wishes & regards  /  Lars Ängquist

-------- Original Message --------
Subject: Mergeing datasets
Date: Tue, 26 Apr 2011 16:17:47 -0600
From: Thomas Speidel <[email protected]>
To: <[email protected]>
Reply-To: [email protected]


I have a dataset containing mappings of various id's used in a study. The truly unique person identifier is the variable master. A person may then be assigned an id:
   master   id1   id2   id3   id4
      106   708   673     .   676
      110   713   696     .   704
      122   721   721     .     .
      123   749   722     .   728
      129   789   789   734     .
      134   739   739     .     .
      144   800   752     .   763
      145   808   753     .   780
      151   797   764     .   781
      158   811   771     .   779


I have a working dataset containg id. The id may come from id1, id2, id3, or id4 above:
. list id in 1/10, clean noobs

     id
   2014
   2030
   2038
   2041
   2042
   2054
   2055
   2058
   2061
   2065


I need to merge(?) the two so that I can get the master id for each id, regardless of whether they came from id1 id2 id3 id4. I thought this was a job for merge, but did not find a mention for this type of situations in the manual. I suppose I could do four sequential merges. Any suggestion on how to best proceed?
Thanks.

--
Thomas Speidel
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index