Panel data, simple rearrangement?
By stnadard OLS regression results, in the simple regression

$$y_t = \alpha + \beta z_t + v_t, \;\;\;t=1,...,T$$

we have that

$$\hat \beta = \frac {\sum_{i=1}^T (z_t - \bar z)(y_t-\bar y)}{\sum_{i=1}^T (z_t - \bar z)^2}$$

and

$$\hat \alpha = \bar y - \hat \beta \bar z$$

So the residuals are

$$\hat v_t = y_t -(\hat \alpha +\hat \beta z_t)$$

Then, substitute for your particular $y_t$ and $z_t$ in all the above.