Joro's code has clear step by step logic. It could made a little shorter using statements like
More discussion of general technique at https://www.stata-journal.com/sjpdf....iclenum=dm0055 -- especially Sections 9 and 10.
Code:
egen meanpriceat18301 = mean(cond(date == 18301, price, .)), by(shpro)
Comment