In real life you do not simply construct instrument, that is a language you might see in some econometrics textbooks when they discus the model theoretically, e.g. "to get rid of simultaneity we construct instrument that has this or that property", but in real life you don't actually construct the series.
In real life you record data for some variable you believe will be good instrument. A good instrument should satisfy the properties you mention. There are no hard rules here, you need to think about it hard. Good examples are things like using draft lottery when estimating returns to education such as done by Angrist and Kruger. Draft clearly affects education, and since people were drafted by lottery its guaranteed its exogenous and $Cov(Z_i,ϵ_i)=0$.
A one way how you implement this, in lets say R
is as follows:
You can use package ivreg:
install.packages("ivreg")
library("ivreg")
Get yourself data, for the purpose of demonstration I will use:
data("SchoolingReturns", package = "ivreg")
Next since we already have all the data we can run a model. We can do simple Mincer equation
my_iv <- ivreg(log(wage) ~ education + poly(experience, 2h) |
nearcollege + poly(age, 2),
data = SchoolingReturns)
Where the first set of variables are the variables in second stage and after |
there is a set of instruments. We use proximity to college as an instrument for education (since being closer to university makes you more likely to attend one, but arguably your location is exogenous), and age for experience.
As you see you do not create the instrument in some computational way inside your PC. You go out and find data on variable that you can defend being a good instrument. You can use Hausman test or F-test to see whether the regression is consistent or whether first stage is strong to support the use of instrument. You can also run auxiliary first stage to examine whether the instrument is significant when regressed on endogenous regressor. For that you would just run regular regression where dependent variable is the a dependent variable and instrument will be independent variable.