Hi all,

I appended two datasets based on ID. I was not able to merge these datasets, because ID did not identify individual observations. So,I ended with a dataset that looks like the one below.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long ID float(date1 date2 duplicate)
1 20737     . 1
1     . 20438 2
2     . 20775 1
2 20930     . 2
2 21129     . 3
3 20796     . 1
3 21157     . 2
4     . 20873 1
4     . 20180 2
4 20858     . 3
end
format %td date1
format %td date2
I would like to modify the dataset above, to look like the one below.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long ID float(date1 date2 duplicate)
1 20737 20438 1
2 20930 20775 2
2 21129 20775 3
4 20858 20873 1
4 20858 20180 2
end
format %td date1
format %td date2
In other words, I would like to keep observations identified by ID that have both date1 and date2, but the combinations of ID date1 and date2 vary.
ID 1 has one date1 and one date2. These just need to be combined into one observation.
ID 2 has two date1 and one date2. In this case I need to combine the observations into two distinct observations, the firsts with one date1 and date2, and the second with the other date1 and date2 again.
ID 3 only has date1, these must be dropped.
ID 4 has one date1 and two date2. Similar to ID 2, in this case I need to combine the observations into two distinct observations, the first with date1 and one date2, and the second with date1 and date2 again.

Thank you very much!