frac_utils module¶
Utility helpers for building instruments and projections in FRAC.
make_X(X_exo, X_endo)
¶
Combine exogenous and endogenous regressors into a single regressor matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_exo
|
ndarray | None
|
Exogenous regressors. |
required |
X_endo
|
ndarray | None
|
Endogenous regressors. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The concatenated regressor matrix. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
Source code in frac_blp/frac_utils.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
make_Z_full(Z, X1_exo=None, degree_Z=2, degree_X1=2)
¶
Build a full set of polynomial instruments for FRAC without demographics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Z
|
ndarray
|
Baseline instruments. |
required |
X1_exo
|
ndarray | None
|
Exogenous regressors without random coefficients. |
None
|
degree_Z
|
int
|
Maximum degree applied to columns of |
2
|
degree_X1
|
int
|
Maximum degree applied to columns of |
2
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Instrument matrix whose columns enumerate every admissible |
ndarray
|
combination of polynomial terms, preceded by a column of ones. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in frac_blp/frac_utils.py
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 76 77 78 79 80 81 82 83 | |
proj_Z_full(X, Z_full)
¶
Project each column of X onto Z_full and report fitted values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Variables to project. |
required |
Z_full
|
ndarray
|
Instrument matrix used for the projections. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
tuple[np.ndarray, np.ndarray, np.ndarray]: |
ndarray
|
|
ndarray
|
R-squared values. |
Source code in frac_blp/frac_utils.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |