Hi
This is my first attempt at using dataex


Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input float id int(op_dato diag_dato bcc_date1) double bcc_time1 str34 bcc_name1 double bcc_value1 int bcc_date2 double bcc_time2 str34 bcc_name2 double bcc_value2 int bcc_date3 double bcc_time3 str34 bcc_name3 double bcc_value3
 1  20559 20542 20542 -1893415328999.9995 "Ferritin"     95 20542 -1893415328999.9995 "Hæmoglobin" 8.4 20542 -1893415328999.9995 "TSAT"        .19
 2  20598 20583 20198      -1.8934164e+12 "Hæmoglobin" 9.3 20583      -1893418260000 "Ferritin"     74 20583      -1893418260000 "Hæmoglobin" 8.7
 3  19829 19807 19802      -1893408540000 "Hæmoglobin"   8 19806      -1.8933993e+12 "Ferritin"     49 19806      -1.8933993e+12 "Hæmoglobin" 7.8
 4  19842 19820 19659      -1.8933822e+12 "Hæmoglobin" 5.9 19793      -1.8934101e+12 "Ferritin"      4 19793      -1.8934101e+12 "Hæmoglobin" 3.9
 5  20936 20936 20936      -1893443074000 "Hæmoglobin"   9 20936      -1893443340000 "Hæmoglobin" 8.8 20936      -1.8934401e+12 "Hæmoglobin" 7.8
 6  21410 21395 20780      -1893422640000 "Ferritin"    121 20780      -1893422640000 "Hæmoglobin" 8.4 20780      -1893422640000 "TSAT"        .22
 7  20393 20393 20385      -1.8933903e+12 "Hæmoglobin" 8.1 20386 -1893431160000.0002 "Hæmoglobin" 7.8 20387 -1893429305999.9998 "Hæmoglobin" 8.1
 8 -21915 19855 19481 -1893446699999.9998 "Hæmoglobin" 8.9 19481       -1.893429e+12 "Hæmoglobin" 8.3 19481      -1.8934338e+12 "Hæmoglobin" 8.3
 9  20144 20020 20020      -1.8934155e+12 "Ferritin"    127 20020      -1.8934155e+12 "Hæmoglobin" 8.3 20020      -1.8934155e+12 "TSAT"        .27
10      .     . 21619 -1893410940000.0002 "Hæmoglobin"   5 21624 -1893393600000.0002 "Hæmoglobin" 5.2 21223 -1893415799999.9998 "Hæmoglobin" 8.4
11      .     . 19808 -1893417660000.0002 "Hæmoglobin" 8.8 20185 -1893408479999.9998 "Hæmoglobin" 8.9 20558 -1893415560000.0002 "Hæmoglobin" 9.4
12      .     . 20899      -1893418620000 "Hæmoglobin" 9.2 20950      -1893419280000 "Hæmoglobin" 9.9 20968      -1.8934308e+12 "Ferritin"    971
end
format %td op_dato
format %td diag_dato
format %td bcc_date1
format %tcHH:MM:SS bcc_time1
format %td bcc_date2
format %tcHH:MM:SS bcc_time2
format %td bcc_date3
format %tcHH:MM:SS bcc_time3
It is a dataset of an id-number followed by two dates. The remaining "bcc*" variables are grouped in four containing the date, time, name and value of a blood-sample. The actual dataset contains op to "bcc group" 64 but I have limited the dataset for dataex

I need for each id number to find the lowest bcc_date that is >= to diag_dato (also a date) and where the corresponding bcc_name is "Ferritin".

I tried the egen with rowmin but got stuck not knowing how to specify the terms.

Any suggestions or do you need additional input from me?

Best regards Magnus