Dear stata users,

How do I match options with expiration date closest to earnings announcement date (during or as close as possible to earning announcement date after) with the relevant earnings announcement date? In the data example below I already matched expiration date (exdate) to be after the earnings announcement date (anndats_act) but I dont know how to make sure expiration date is closest to the earnings announcement date. Specifically, I want to have one value of iv_spread per estimator per forecast date (so not actual announcement date).


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long(date exdate) str8 cusip float(option_duration iv_spread) double(estimator value actual) long anndats_act
13158 13196 "03783310" 38 -.022294 51020 -.0196 -.02 13165
13158 13196 "03783310" 38  .000501    28 -.0196 -.02 13165
13158 13168 "03783310" 10 -.188772   142   -.02 -.02 13165
13158 13168 "03783310" 10  .042142   142   -.02 -.02 13165
13158 13196 "03783310" 38 -.030153   142   -.02 -.02 13165
13158 13196 "03783310" 38 -.013164 50003 -.0196 -.02 13165
13158 13168 "03783310" 10 -.076504   142   -.02 -.02 13165
13158 13168 "03783310" 10 -.173916   142   -.02 -.02 13165
13158 13168 "03783310" 10 -.115971   142   -.02 -.02 13165
13158 13168 "03783310" 10 -.021389 52135 -.0196 -.02 13165
end
format %d date
format %d exdate
format %d anndats_act
Your help is greatly appreciated!

Kind regards,

Frank