spreg.ThreeSLS¶
- class spreg.ThreeSLS(bigy, bigX, bigyend, bigq, regimes=None, nonspat_diag=True, name_bigy=None, name_bigX=None, name_bigyend=None, name_bigq=None, name_ds=None, name_regimes=None)[source]¶
User class for 3SLS estimation
- Parameters:
- bigy
dictionary
with vector for dependent variable by equation
- bigX
dictionary
with matrix of explanatory variables by equation (note, already includes constant term)
- bigyend
dictionary
with matrix of endogenous variables by equation
- bigq
dictionary
with matrix of instruments by equation
- regimes
list
List of n values with the mapping of each observation to a regime. Assumed to be aligned with ‘x’.
- nonspat_diag: boolean
flag for non-spatial diagnostics, default = True.
- name_bigy
dictionary
with name of dependent variable for each equation. default = None, but should be specified. is done when sur_stackxy is used
- name_bigX
dictionary
with names of explanatory variables for each equation. default = None, but should be specified. is done when sur_stackxy is used
- name_bigyend
dictionary
with names of endogenous variables for each equation. default = None, but should be specified. is done when sur_stackZ is used
- name_bigq
dictionary
with names of instrumental variables for each equation. default = None, but should be specified. is done when sur_stackZ is used.
- name_ds
str
name for the data set.
- name_regimes
str
name of regime variable for use in the output.
- bigy
Examples
First import libpysal to load the spatial analysis tools.
>>> import libpysal >>> from libpysal.examples import load_example >>> from libpysal.weights import Queen >>> import spreg >>> np.set_printoptions(suppress=True) #prevent scientific format
Open data on NCOVR US County Homicides (3085 areas) using libpysal.io.open(). This is the DBF associated with the NAT shapefile. Note that libpysal.io.open() also reads data in CSV format.
>>> nat = load_example('Natregimes') >>> db = libpysal.io.open(nat.get_path("natregimes.dbf"),'r')
The specification of the model to be estimated can be provided as lists. Each equation should be listed separately. In this example, equation 1 has HR80 as dependent variable, PS80 and UE80 as exogenous regressors, RD80 as endogenous regressor and FP79 as additional instrument. For equation 2, HR90 is the dependent variable, PS90 and UE90 the exogenous regressors, RD90 as endogenous regressor and FP99 as additional instrument
>>> y_var = ['HR80','HR90'] >>> x_var = [['PS80','UE80'],['PS90','UE90']] >>> yend_var = [['RD80'],['RD90']] >>> q_var = [['FP79'],['FP89']]
The SUR method requires data to be provided as dictionaries. PySAL provides two tools to create these dictionaries from the list of variables: sur_dictxy and sur_dictZ. The tool sur_dictxy can be used to create the dictionaries for Y and X, and sur_dictZ for endogenous variables (yend) and additional instruments (q).
>>> bigy,bigX,bigyvars,bigXvars = spreg.sur_dictxy(db,y_var,x_var) >>> bigyend,bigyendvars = spreg.sur_dictZ(db,yend_var) >>> bigq,bigqvars = spreg.sur_dictZ(db,q_var)
We can now run the regression and then have a summary of the output by typing: print(reg.summary)
Alternatively, we can just check the betas and standard errors, asymptotic t and p-value of the parameters:
>>> reg = spreg.ThreeSLS(bigy,bigX,bigyend,bigq,name_bigy=bigyvars,name_bigX=bigXvars,name_bigyend=bigyendvars,name_bigq=bigqvars,name_ds="NAT") >>> reg.b3SLS {0: array([[6.92426353], [1.42921826], [0.00049435], [3.5829275 ]]), 1: array([[ 7.62385875], [ 1.65031181], [-0.21682974], [ 3.91250428]])}
>>> reg.tsls_inf {0: array([[ 0.23220853, 29.81916157, 0. ], [ 0.10373417, 13.77770036, 0. ], [ 0.03086193, 0.01601807, 0.98721998], [ 0.11131999, 32.18584124, 0. ]]), 1: array([[ 0.28739415, 26.52753638, 0. ], [ 0.09597031, 17.19606554, 0. ], [ 0.04089547, -5.30204786, 0.00000011], [ 0.13586789, 28.79638723, 0. ]])}
- Attributes:
- bigy
dictionary
with y values
- bigZ
dictionary
with matrix of exogenous and endogenous variables for each equation
- bigZHZH
dictionary
with matrix of cross products Zhat_r’Zhat_s
- bigZHy
dictionary
with matrix of cross products Zhat_r’y_end_s
- n_eq
int
number of equations
- n
int
number of observations in each cross-section
- bigK
array
vector with number of explanatory variables (including constant, exogenous and endogenous) for each equation
- b2SLS
dictionary
with 2SLS regression coefficients for each equation
- tslsE
array
N x n_eq array with OLS residuals for each equation
- b3SLS
dictionary
with 3SLS regression coefficients for each equation
- varb
array
variance-covariance matrix
- sig
array
Sigma matrix of inter-equation error covariances
- bigE
array
n by n_eq array of residuals
- corr
array
inter-equation 3SLS error correlation matrix
- tsls_inf
dictionary
with standard error, asymptotic t and p-value, one for each equation
- surchow
array
list with tuples for Chow test on regression coefficients each tuple contains test value, degrees of freedom, p-value
- name_ds
str
name for the data set
- name_bigy
dictionary
with name of dependent variable for each equation
- name_bigX
dictionary
with names of explanatory variables for each equation
- name_bigyend
dictionary
with names of endogenous variables for each equation
- name_bigq
dictionary
with names of instrumental variables for each equations
- name_regimes
str
name of regime variable for use in the output
- bigy
- __init__(bigy, bigX, bigyend, bigq, regimes=None, nonspat_diag=True, name_bigy=None, name_bigX=None, name_bigyend=None, name_bigq=None, name_ds=None, name_regimes=None)[source]¶
Methods
__init__
(bigy, bigX, bigyend, bigq[, ...])