twosls module¶
TSLS function that can be iterated.
print_tsls_results(estimated_coeffs, estimated_stderrs, names_coeffs=None, title=None)
¶
Print the estimated coefficients and their standard errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimated_coeffs
|
ndarray
|
Estimated coefficients. |
required |
estimated_stderrs
|
ndarray
|
Estimated standard errors. |
required |
names_coeffs
|
list[str] | None
|
Coefficient names. If None, the
coefficients are labeled |
None
|
title
|
str | None
|
Header printed above the results. If None,
|
None
|
Source code in frac_blp/twosls.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
tsls_estimate(y, X, Z, J, optimal_instruments=True, prev_residuals=None, X_proj=None)
¶
Estimate \(E(y - X heta | Z) = 0\) by 2SLS with optimal instruments and weighting matrix.
The previous residuals are used to estimate the within-market covariance of the errors, which gives the optimal instruments and the weighting matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
ndarray
|
Dependent variable, a (T*J,) vector. |
required |
X
|
ndarray
|
Regressors, a (T*J, K) matrix. |
required |
Z
|
ndarray
|
Instruments, a (T*J, L) matrix. |
required |
J
|
int
|
Number of products in each market. |
required |
optimal_instruments
|
bool
|
If True, use optimal instruments. Default is True. |
True
|
prev_residuals
|
ndarray | None
|
Previous residuals, a (T*J,) vector.
If None, the OLS residuals of |
None
|
X_proj
|
ndarray | None
|
Projection of |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
tuple[np.ndarray, np.ndarray, np.ndarray]: The estimated coefficients |
ndarray
|
(a K-vector), their estimated variance (a (K, K) matrix), and the new |
ndarray
|
residuals (a (T*J,) vector). |
Source code in frac_blp/twosls.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |