Dear Statlisters,

Why can't I reproduce the results after this lines of code. I am working with longitudinal data in long format. uuid is the unique identifier

bysort uuid -dispensing_date : egen max_duration = max(duration)
gen startdate = dispensing_date

sort uuid -dispensing_date

by uuid: gen stopdate = dispensing_date[_n+1]

noisily: sum duration

replace stopdate = date("1/7/2020", "DMY", 2009) if stopdate == .

gen time = stopdate - startdate

drop if duration != max_duration

noisily: sum duration

drop if time == 0

noisily: sum duration // this line does not produce consistent results.


Regards