'estimate model using 2SLS IV regression
Returns
results : instance of RegressionResults
regression result
Notes
This returns a generic RegressioResults instance as defined for the
linear models.
Parameter estimates and covariance are correct, but other results
haven\'t been tested yet, to seee whether they apply without changes.'

def fit(self):

    (y, x, z) = (self.endog, self.exog, self.instrument)
    ztz = np.dot(z.T, z)
    ztx = np.dot(z.T, x)
    self.xhatparams = xhatparams = np.linalg.solve(ztz, ztx)
    F = xhat = np.dot(z, xhatparams)
    FtF = np.dot(F.T, F)
    self.xhatprod = FtF
    Ftx = np.dot(F.T, x)
    Fty = np.dot(F.T, y)
    params = np.linalg.solve(FtF, Fty)
    Ftxinv = np.linalg.inv(Ftx)
    self.normalized_cov_params = np.dot(Ftxinv.T, np.dot(FtF, Ftxinv))
    lfit = IVRegressionResults(self, params, normalized_cov_params=self.normalized_cov_params)
    lfit.exog_hat_params = xhatparams
    lfit.exog_hat = xhat
    self._results = lfit
    self._results_ols2nd = OLS(y, xhat).fit()
    return RegressionResultsWrapper(lfit)
