I am working with a dataset that contains names, the frequency of a name according to gender, and the year in which this data was recorded. It looks like this:
Array


My problem is that I want to create a variable that simultaneously looks for the earliest occurrence in which a name is recorded and checks that bothmale and female are above zero. I've done a bit of searching beforehand and know how to do each step individually, but not together. That is to say, I know that I can generate a variable recording the earlist occurrence using something like

Code:
 egen earliestyear = min(year), by(name)
I know I can also generate a variable recording if female and male meet certain conditions by writing something along the lines of

Code:
gen examplevariable = whatever if male > 0 & female > 0
But how can I tell STATA to generate a variable in which the gender conditions are met in the earliest name a year is recorded? I've tried using conditionals within the egen function, but am getting nonsense results.

Code:
egen examplevariable2 = min(year & female > 0 & male > 0), by(name)
is probably telling STATA to find the minimum frequencies of the gender conditions, which is not what I'm looking to do. All help is appreciated.