Is exogeneity guaranteed for a lottery-generated instrumental variable? If using $z$ as an instrument for $x$, to study the effect $x$ has on $y$ and given that $z$ was indeed generated through a lottery, is it definite that exogeneity of $z$ will hold?
I have looked at this as two-stage OLS and I believe that the fact $z$ is lottery-generated can satisfy the exogeneity condition, i.e. $\text{corr}(z_i, \epsilon_i) = 0$. Is that true?
The simple answer is no.
Randomness does not imply exogeneity.
In my opinion, the following example from Deaton: &quot;Randomization in the tropics, and the search for the elusive keys to economic development&quot; is quite illuminating.
Assume that you want to estimate the effect of having a railway-station on poverty. We have data on the poverty rate $P_c$ and the presence of a station $R_c \in \{0,1\}$ for a large number of cities $c$. Assume that the true data generating process is given by:
$$
P_c = \alpha + \beta_c R_c + \varepsilon_c,
$$
Notice here that the slope $\beta_c$ is city specific, so the effect of a railroad is heterogeneous across cities.
The coefficient $\beta_c$ cannot be estimated, but you might wonder whether it is possible to estimate the mean of $\beta_c$ over all cities that decide to build a railroad.  $\overline{\beta} = \mathbb{E}(\beta_c|R_c = 1)$. Then:
$$
P_c = \alpha + \overline{\beta} R_c + (\varepsilon_c + (\beta_c - \overline{\beta})R_c) = \alpha + \overline{\beta} R_c + \upsilon_c,
$$
where $\upsilon_c = \varepsilon_c + (\beta_c - \overline{\beta})R_c$ is the new error. Although $\mathbb{E}(\upsilon_c) = 0$, you might be worried that:
$$
\mathbb{E}(R_c \upsilon_c) \ne 0.
$$
Indeed, we have:
$$
\mathbb{E}(R_c \upsilon_c) = \mathbb{E}(\varepsilon_c R_c = 1) + \mathbb{E}(\beta_c - \overline{\beta}|R_c = 1) \Pr(R_c = 1) = \mathbb{E}(\varepsilon_c R_c).
$$
This will only be zero if the decision to build a station is uncorrelated to anything that might otherwise influence the poverty rate in the city. As this is probably not satisfied, we need an instrument.
A random instrument
Assume that the government randomly allocates cities to development areas, captured by the instrument $Z_c$ (equal to 1 if city $c$ is a development area and zero otherwise).
If designations to development areas motivate the building of railways, we have that there is positive correlation between $Z_c$ and $R_c$. Also as $Z_c$ is random, we can assume that $\mathbb{E}(Z_c \varepsilon_c) = 0$. However:
$$
\mathbb{E}(Z_c \upsilon_c) = \mathbb{E}(\varepsilon_c Z_c) + \mathbb{E}(\beta_c - \overline{\beta}|Z_c = 1, R_c = 1)\Pr(R_c = 1, Z_c = 1).
$$
The first term on the right hand side is zero by the randomness of $Z_c$. As such, $Z_c$ will be uncorrelated to $\upsilon_c$ iff:
$$
\mathbb{E}(\beta_c - \overline{\beta}|Z_c = 1, R_c = 1) = \mathbb{E}(\beta_c|Z_c = 1, R_c = 1) - \mathbb{E}(\beta_c|R_c = 1) = 0.
$$
This will be the case if the mean effect of building a station over all cities that are a development area equals the mean effect over all cities that build the railroad (whether they are a development area or not).
The last condition can be rewritten as:
$$
\begin{align*}
&amp;\mathbb{E}(\beta_c|Z_c = 1, R_c = 1) = \mathbb{E}(\beta_c|R_c = 1),\\
\to &amp;\mathbb{E}(\beta_c|Z_c = 1, R_c = 1) = \mathbb{E}(\beta_c|Z_C = 1, R_c = 1) \Pr(Z_c = 1) + \mathbb{E}(\beta_c|Z_c = 0, R_c = 1) \Pr(Z_c = 0),\\
\to &amp;\mathbb{E}(\beta_c|Z_c = 1, R_c = 1)\Pr(Z_c = 0) = \mathbb{E}(\beta_c|Z_c = 0, R_c = 1) \Pr(Z_c = 0),\\
\to &amp;\mathbb{E}(\beta_c|Z_c = 1, R_c = 1)\Pr(Z_c = 0|R_c = 1) = \mathbb{E}(\beta_c|Z_c = 0, R_c = 1)\Pr(Z_c = 0|R_c = 1),\\
\to &amp;\mathbb{E}(\beta_c|Z_c = 1, R_c = 1)\Pr(Z_c = 0, R_c = 1) = \mathbb{E}(\beta_c|Z_c = 0, R_c = 1) \Pr(Z_c = 0, R_c = 1).
\end{align*}
$$
This will be the case if either:

$\mathbb{E}(\beta_c|Z_c = 1, R_c = 1) = \mathbb{E}(\beta_c|Z_c = 0, R_c = 1)$ which means that the mean effect among all cities who are a development area and decided to build a railroad should be equal to the mean effect among those who build a railroad and are not a development area. So if the behaviour (i.e. the decision to build a station) changes due to being designated as a development area, this condition will not be satisfied.
Or $Pr(Z_c = 0, R_c = 1) = 0$ which means that no city that is not a development area builds a station.

In short: randomness of the instrument makes sure that $\mathbb{E}(\varepsilon_c Z_c) = 0$ but does not guarantee that $\mathbb{E}(\upsilon_c Z_c) = 0$.