Dear Statalist-Community,

first of all I would like to thank you all for the very helpful discussions I´ve read on here! They are of great assistance for my master thesis.

I want to count the number of active borrowers per industry-year, assuming that a borrower is active for the whole duration of a loan. Please see the code below:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long YEAR str3 SIC3 long(gvkey facilitystartdate facilityenddate)
1990 "010"  2249 19900123 19950123
1990 "010"  2812 19901220 19910320
1990 "010" 12349 19900426 19920131
1990 "020" 16566 19901120 19901220
1990 "100" 11993 19900208 20100201
1990 "104"  1231 19900411 19901031
1990 "104"  1856 19901002 19910930
1990 "104"  9726 19900930 19950930
1990 "104"  9726 19900103 19940331
1990 "104" 12139 19900126 19921231
1990 "104" 12139 19900126 19921231
1990 "104" 22730 19900223 19910320
1990 "109" 15240 19900524 19960331
1990 "109" 15240 19900524 19960331
1991 "010"  2812 19911201 19941201
1991 "010"  2812 19910108 19950108
1991 "010" 10884 19910615        .
1991 "010" 14002 19910601 19930430
1991 "010" 14002 19910601 19930430
1991 "070" 24614 19911122 19921031
1991 "070" 24614 19910301 19960401
1991 "070" 24614 19910301 19951201
1991 "070" 24614 19910301 19960401
1991 "104"  9726 19910313 19920301
1991 "104" 13566 19910326 19980326
end
Explanation of my variables:
SIC3 - industries are defined by three digit SIC codes
gvkey - a unique firm identifier
YEAR - Year in that loan was given out
facilitystartdate - exact date when loan started
facilityenddate - exact date when loan ended (in some cases no date is indicated)

In my example there are 3 active borrowers in the year 1990 in industry 010 and 5 active borrowers in industry 104 (7 entries, but I do not count reoccuring gvkey's)
For the year 1991 there are 6 active borrowers in industry 010 (2249, 2812 and 12349 received loans in 1990, but they are still active in 1991 ; 2812, 10884 and 14002 received new loans)

Please let me know, if anyone knows how to realize the counting in Stata.

Looking forward to your replies and thanks in advance,

Niklas Zinn