I'm running Stata 17.0.
I have several (7) datasets that I would like to merge on an ID variable that I generated from two different (but compatible) ID variables.
In particular, some of my datasets contain a variable CookID while others contain bookingID. While the bookingID is always 11 digits in length, the CookID ranges from 6 to 9 digits.
When the CookID is 6 digitis, bookingID is the first two digits of the year followed by three zeros followed by the CookID.
When the CookID is 7 digitis, bookingID is the first two digits of the year followed by two zeros followed by the CookID.
When the CookID is 8 digitis, bookingID the first two digits of the year followed by one zeros followed by the CookID.
When the CookID is 9 digitis, bookingID first two digits of the year followed by the CookID.
For example, line 1 below Aaimn Crockron's CookID is 190710039 and his BookingId is 20190710039.
Can y'all help me figure out how to generate bookingID from CookID so that I can merge the data using this variable?
I appreciate any insight!
Best,
Tre
Dataset 1
CookID | name | year |
190710039 | AAIMN CROCKRON | 2011 |
181230137 | AALIAH HUDSON | 2015 |
180902170 | AALIAYAH GLOVER | 2001 |
180629089 | AALIYAH BROWN | 2020 |
Dataset 2
bookingID | name_first | name_last | Race | gender |
20190710039 | Aaimr | Crockron | 1 | 1 |
20181230137 | Aaliah | Hudson | 1 | 0 |
20180902170 | AALIAYAH | GLOVER | 1 | 0 |
20160202140 | AALIYAH | FOSTER | 1 | 0 |
20180629089 | Aaliyah | Brown | 1 | 0 |
0 Response to generating compatible ID variables
Post a Comment