Let's say I have one endogenous variable $X_1$ in the linear model
$$ Y=X_1\beta $$
and two instrumental variables $Z_1$ and $Z_2$ (strongly correlated with $X_1$ but not $Y$).
I compute the two-stage least squares in the following way:
$$ \widehat{\beta}_{2SLS} = [X'Z(Z'Z)^{-1}Z'X]^{-1}[X'Z(Z'Z)^{-1}Z'y] $$
I'm trying to understand the number of degrees of freedom in this situation in order to correct the calculation of the sample variance of my final regression model. I have two options:
According to Multiple linear regression degrees of freedom, I would have $N-2$ degrees of freedom.
However, because during the first stage of 2SLS I regress $X_1$ on the $Zs$, i.e., I run OLS on the linear model
$$ X_1=\delta_1Z_1 + \delta_2Z_2 $$
and in this case we have two predictor variables ($Z_1$ and $Z_2$), so perhaps I have $N-3$ degrees of freedom.
Any hints about which one works here?