Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input float(study_id red yellow green)
 1 16044 16532     .
 2     .     . 21254
 3     . 19516 19213
 4 18359     . 18890
 5     .     . 18438
 6 22042 17578     .
 7     .     . 20036
 8     . 20179     .
 9     .     . 15718
10 18874 22474 19873
end
format %td red
format %td yellow
format %td green
Here's what I need to do: generate 6 new variables.
date1 and color1 will be the date and corresponding variable name (color) for one of the date values here. There should be no missing values for these 2 new variables because every row has at least 1 date in it.
date2 and color2 will be the date and corresponding variable name (color) for the second date value, for those who have one. Those individuals who only had 1 date value (n=4)will be have missing values for these 2 new variables.
date3 and color3 will be the date and corresponding variable name (color) for the third date value, for those who have it. Only 1 individual has 3 dates so this variable will have 9 missing values.

Chronological order doesn't really matter, because I'm going to eventually reshape it to long anyway. So I don't care if date1 is the earliest date or date3 is earliest or if it's in some random order.

I have no idea how to do this so any help would be much appreciated.