The aim of the present routine is to simulate a demand equation with endogenous prices and unobservable product quality and to retrieve the original parameters using the Control Function (CF) approach. The CF approach is a very useful and simple method to obtain unbiased estimates. The present R code helps to understand the underlying structure of the endogeneity problem in demand estimations. Results support the important bias correction of the CF approach.