Observational studies are prone to bias due to confounding either measured or unmeasured. While measured confounding can be controlled for with a variety of sophisticated methods such as propensity score-based matching, stratification and multivariable regression model, the unmeasured confounding is usually cumbersome, leading to biased estimates. In econometrics, instrumental variable (IV) is widely used to control for unmeasured confounding. However, its use in clinical researches is generally less employed. In some subspecialties of clinical medicine such as pharmacoepidemiological research, IV analysis is increasingly used in recent years. With the development of electronic healthcare records, more and more healthcare data are available to clinical investigators. Such kind of data are observational in nature, thus estimates based on these data are subject to confounding. This article aims to review several methods for implementing IV analysis for binary and continuous outcomes. R code for these analyses are provided and explained in the main text.