Merging data in STATA, Panel Data problem. A real challenge!


I have one database with companies who did a specific event on a specific date. I also have their company codes. Some of these companies are twice or more in this database because they did this event more then once during the observed period.

In my second database I have other company specific details such as assets for more than 10 years. So for each company code I have information for several years.

Now, how do I merge these 2 datasets in STATA?



TS Contributor
The trick is to recognize that your id is company-year and not company. Here is an example:

// prepare some example data
clear all
tempfile eventdata companydata

input company str10 event
1 "01/12/2013"
1 "15/02/2012"
2 "21/12/2012"
gen date = date(event,"DMY")
format date %td
gen year = year(date)
save `eventdata'

drop _all
input company year employees
1 2012 10
1 2013 11
2 2012 25 
2 2013 24
3 2012 5
3 2013 6
save `companydata'

use `eventdata'

// merge
merge 1:1 company year using `companydata', keep(1 3)

// admire the result