How this calculation works
Two-stage least squares uses variation in a regressor that can be predicted by instruments. The goal is to estimate a structural relationship when the original regressor may be correlated with the outcome error.
With regressors X=[intercept,exogenous,endogenous] and instruments Z=[intercept,same exogenous,excluded instruments], compute Xhat=P_Z X by QR, beta=(X^T P_Z X)^-1 X^T P_Z y. Structural residuals y-X beta, not y-Xhat beta, determine residual variance. For each endogenous regressor compare restricted first stage on exogenous columns versus full Z: F=((RSSr-RSSu)/q)/(RSSu/(n-rankZ)). State this is a first-stage diagnostic, not an automatic weak-IV-valid inference method. Classical covariance sigma²(X^TP_ZX)^-1 only when assumed; do not use naive second-stage OLS SE.A worked example
With the prefilled inputs, coefficients = [1.3146013123964015,3.010494403820824]. Rows [outcome,endogenous,instruments...,controls...]. Declare instrument and control column counts.
Good to know
2SLS HC1 uses structural rather than second-stage projected residuals. First-stage F is homoskedastic diagnostic, not proof of instrument validity.
Reference: Primary method reference or author-maintained documentation (opens in a new tab) ↗
Separate endogeneity from ordinary prediction
Two-stage least squares uses variation in a regressor that can be predicted by instruments. The goal is to estimate a structural relationship when the original regressor may be correlated with the outcome error.
This requires more than a strong instrument-regressor correlation. Instruments must also satisfy a justified exclusion and exogeneity argument, which cannot be established by this calculator's fitted coefficients.
Compare with the Simple linear regression calculator. Estimate a structural coefficient with endogenous regressors using excluded instruments; ordinary multiple regression cannot impose instrument orthogonality.
Build both design matrices
Rows [outcome,endogenous,instruments...,controls...]. Declare instrument and control column counts.Include every exogenous regressor in both the structural regressor matrix and the instrument matrix. Add excluded instruments only to the latter, and make any intercept coding consistent.
There must be enough independent instrumental variation to identify the endogenous columns. Duplicate instruments or redundant regressors can make the projected design singular even when the input table has many rows. Enter one endogenous regressor, then the declared excluded instruments, then any ordinary controls. The controls appear in both the structural design and the instrument design, and both designs include an intercept. A column-order mistake can therefore produce a numerically valid calculation for the wrong model. Excluded instruments must provide independent first-stage variation after controlling for the included exogenous variables. Full rank is necessary for the matrix calculation, while the scientific exclusion restriction and independence assumptions require evidence outside these rows. Neither the program nor a large first-stage coefficient can establish those restrictions.
Project before solving the structural coefficients
The first stage projects the structural regressors onto the instrument space. The second stage uses that projected information to solve the two-stage coefficient equations.
The structural residual is still observed y minus the original X times the fitted coefficient. Replacing original X with projected X when measuring residual variation gives the wrong uncertainty calculation.
Read the first-stage diagnostic
The partial first-stage F statistic compares the excluded-instrument contribution after accounting for the included exogenous variables. Its numerator counts those additional instrument directions and its denominator uses the full first-stage residual degrees of freedom.
A finite F value is a diagnostic rather than universal permission to use conventional confidence intervals. Weak identification can require specialized inference, especially with several endogenous regressors or nonstandard error structures.
An exact six-row calculation
Take x=(-2,-1,0,0,1,2), instrument z=(-2,-1,-1,1,1,2), and outcome y=2+3x. With an intercept, the two-stage structural coefficients are exactly two and three.
The centered first-stage explained sum of squares is25/3 and its residual sum is5/3. Four residual degrees of freedom give a partial F statistic of20, while the structural equation has zero residual error in this constructed example.
Keep diagnostics distinct from assumptions
A strong first stage supports relevance in the observed sample but cannot show that an instrument affects the outcome only through the endogenous variable. Subject-matter reasoning is still needed.
Overidentification diagnostics, when available, also depend on model assumptions. A large p-value does not prove every instrument is valid, and a just-identified model cannot provide that particular redundancy check. An instrument that merely duplicates an included control provides no excluded identifying variation; rank checks should expose that duplication before either regression stage is interpreted.
Report uncertainty under its actual convention
Classical two-stage covariance assumes the stated structural error conditions. Heteroskedastic or clustered observations need corresponding robust covariance formulas rather than ordinary second-stage regression output.
Report the instrument set, endogenous columns, sample size, first-stage fit and covariance convention together. This makes a coefficient comparison interpretable and exposes when two analyses answer different structural questions. The second-stage uncertainty uses structural residuals, obtained by subtracting the fitted structural equation evaluated at the original endogenous regressor. Using residuals from a regression on its projected values would give the wrong sandwich. The reported covariance has the HC1 sample-size adjustment and assumes independent rows. The first-stage partial F compares the unrestricted instrument regression with the control-only regression using a homoskedastic reference; it is not a heteroskedasticity-robust weak-instrument test. Clustered data, several endogenous regressors or weak-identification confidence sets require another procedure. A perfect first stage is rejected for its undefined conventional F rather than displayed as an arbitrary finite statistic. 2SLS HC1 uses structural rather than second-stage projected residuals. First-stage F is homoskedastic diagnostic, not proof of instrument validity.
A few questions, answered
Can a large first-stage F prove my instrument is valid?
No. It checks sample relevance, while exclusion and exogeneity need a defensible causal argument.
Why must exogenous regressors also be instruments?
They supply their own valid variation and must remain in the projected regressor space under the standard2SLS specification.
Are ordinary second-stage standard errors correct?
Generally no. Use the2SLS structural covariance formula with the original structural residuals.
What happens with too few instruments?
The projected design cannot identify every endogenous coefficient; the fit must be rejected rather than solved with an arbitrary inverse.