Simon,
You should edit the temp2 line in the loop to read:
gen temp2=1 if entry<exit[`i'] & exit>exit[`i']
if you want to exclude have cases of 6's that enter after `i' and exit
before `i'. Again you may wish ">=" depending on how you wish to deal
with exits that occur in the same time period as `i'.
--Carole
gen temp1=(size==6)
gen new=.
local n=_N
qui forvalues i = 1/ `n' {
capture drop temp2
capture drop temp3
gen temp2=1 if entry<exit[`i']
egen temp3=sum(temp1) if temp2==1
replace new=temp3 in `i'
}
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/