Hi everyone,

I am currently working on data that shows if respondents of a survey worked part time while they were in school between the age of 15 and 19 years. With some help I was able to create the variable that shows if a person did both part time and school work which is called overlap:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int ID str10 occupation byte(agebegin ageend overlap)
1546 "school"     16 19 1
1546 "part time " 16 16 0
1546 "part time " 18 18 0
1672 "school "    15 19 1
1672 "part time " 19 19 0
1733 "school"     16 19 1
1733 "part time " 16 16 0
1733 "part time " 18 19 0
1989 "school"     15 17 1
1989 "school"     19 19 1
1989 "part time " 17 17 0
1989 "part time " 19 19 0
1368 "school"     15 19 1
1368 "part time " 16 16 0
1368 "part time " 18 19 0
1121 "school"     15 16 1
1121 "school"     18 18 1
1121 "part time " 16 18 0
end
This is just an extract of many cases. You can see that overlap==1 if there is an overlap of the period in which a person did work part time while schooling. Now I want to create a variable, that can calculate the overlapping period in years. 90% of my data consists of cases like ID no 1672 where people answered that they worked once next to schooling - so the new variable "overlapy" should show the number 1 here. In the case of ID no 1733, the person worked at the age of 16,18 and 19 while in school. So "overlapy" should show the number 3. These two examples together with ID 1546 and 1368 represent nearly all of my data. Case 1121 and 1989 are exceptions and only exist once.

Is it somehow possible to create overlapy which should only appear if overlap==1. Later I would like to have one line per ID only if overlap ==1 and therefore overlapy >=1 shows how many years of part time work a person did at schooling age.

Any idea how to approach this?

Thanks a lot!