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
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
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!
0 Response to How do I combine observations within a dataset?
Post a Comment