I'm currently reading Quantile Regression by Roger Koenker, and for some reason, I'm having a lot of trouble deriving one of his equations (sect. 1.3, p. 5-6).
He goes on to demonstrate that $\hat{x}$ minimizing a linear loss corresponds to the $τ$th quartile of the distribution, when the loss is defined by $$ \rho_\tau(u) = (\tau - 1)\min(0,u) + \tau \max(0,u). $$
To do so, he first writes down the expected loss using the CDF $F$ of the distribution: $$ E[\rho_\tau(X-\hat x)] = (\tau -1)\int_{-\infty}^{\hat x}(x-\hat x)\,dF(x) + \tau \int_{\hat x}^\infty (x-\hat x)\,dF(x), \tag 1 $$ where $X$ is a random variable, which he then differentiates by $\hat x$ to obtain $$ (1-\tau)\int_{-\infty}^{\hat x} dF(x) - τ\int_{\hat x}^\infty dF(x) \tag 2 $$ Now I'm a bit rusty with calculus, and I couldn't find how to go from (1) to (2). I tried to integrate by parts and to apply the fundamental theorem, but I couldn't obtained the result (2).
This results from applying Leibniz's Rule
\begin{eqnarray*} \frac{d}{d\hat x} E_{ϱ_τ}(X-\hat x) &=& (τ -1)\frac{d}{d\hat x}\int_{-∞}^{\hat x}(x-\hat x)\,dF(x)+τ\frac{d}{d\hat x}\int_{\hat x}^{∞}(x-\hat x)\,dF(x) \\ &=& (τ -1)\left((x - \hat x)|_{\hat x} + \int_{-∞}^{\hat x} \frac{d}{d\hat x}(x-\hat x)\,dF(x)\right)+τ\left((x - \hat x)|_{\hat x} + \int_{\hat x}^{∞}\frac{d}{d\hat x}(x-\hat x)\,dF(x)\right) \\ &=& (τ -1)\left(0 + \int_{-∞}^{\hat x} (-1)\,dF(x)\right)+τ\left(0 + \int_{\hat x}^{∞}(-1)\,dF(x)\right) \\ &=& (1 - \tau)\int_{-∞}^{\hat x} \,dF(x)-τ\int_{\hat x}^{∞}\,dF(x) \\ \end{eqnarray*}