You wanna estimate the impact of distance on trade but your coefficient is biased since the error includes many country-pair affinities you can't control for. If you include country-pair fixed effects, the distance variable is dropped. So how can you do it? This paper suggests a 3-step procedure.
The first stage runs a fixed-effects model to obtain the unit effects, the second stage breaks down the unit effects into a part explained by distance and an error term, and the third stage reestimates the first stage by pooled OLS (with or without autocorrelation correction and with or without panel-corrected SEs) including distance plus the error term of stage 2, which then accounts for the unexplained part of the unit effects.