This page was generated from notebooks/panels_examples.ipynb. Interactive online version: Binder badge

Spatial Panel Models in spreg

This notebook presents a usage example of the spatial panel functions available in spreg as of version 1.9.1. Prepared by: Luc Anselin and Pedro Amaral

Preliminaries

Import required libraries and load the example data.

In this example, we will use data on NCOVR US County Homicides (3085 areas) included in libpysal. We will extract the HR (homicide rates) data in the 70’s, 80’s and 90’s from the dataframe and make them the dependent variable for the regression. Note that the data can also be passed in the long format instead of wide format (i.e. a vector with n*t rows and a single column for the dependent variable and a matrix of dimension n*t x k for the independent variables).

For explanatory variables, we will extract RD and PS in the same time periods from the dataframe to be used as independent variables in the regression.

IMPORTANT: If in wide format as in the example below, the data must be organized in a way that all time periods of a given variable are side-by-side and in the correct time order. That is: x[:, 0:T] refers to T periods of \(k_1\), x[:, T+1:2T] refers to \(k_2\), etc. By default a vector of ones will be added to the independent variables passed in.

[2]:
import libpysal
import spreg
import geopandas as gpd
[3]:
libpysal.examples.load_example('NCOVR')
shp_path = libpysal.examples.get_path('NAT.shp')
dfs = gpd.read_file(shp_path)

# Subset to East Coast states to have a smaller sample
east_fips = [9, 10, 11, 12, 13, 23, 24, 25, 33, 34, 36, 37, 42, 44, 45, 50, 51, 54]
dfs2 = dfs[dfs['STFIPS'].isin(east_fips)]

wq1 = libpysal.weights.Queen.from_dataframe(dfs2,ids='FIPSNO')
wq1.transform = 'r'

y_var = dfs2[['HR70', 'HR80', 'HR90']]
x_var = dfs2[['RD70','RD80','RD90','PS70','PS80','PS90']]

spreg version 1.9.1 offers the following panel functions (in addition to the SUR estimators):

  1. OLS and Basic Panel Classes

  • PooledOLS Description: Baseline pooled regression for panel data. Initializes and runs the pooled OLS estimation with optional BSK spatial diagnostics.

  • PanelFE Description: Fixed Effects (Within) estimator for panel data. Performs the “Within Transformation” (demeaning) and executes the regression.

  • PanelRE Description: Random Effects (GLS) estimator. Estimates variance components using Swamy-Arora, computes quasi-demeaning, and performs the Hausman test.

  1. GMM-Based Spatial Error Classes

  • GM_ErrorPooled Description: Pooled Spatial Error Model (SEM) via GMM. Based on the heteroskedasticity-robust estimator proposed by Arraiz2010, available in the spreg function GM_Error_Het.

  • GM_ErrorRE Description: KKP spatial random effects model.

  1. Maximum Likelihood (ML) Spatial Classes

  • ML_ErrorPooled Description: Pooled ML SEM with diagnostic output.

  • ML_ErrorFE Description: ML estimation for Fixed Effects Spatial Error models.

  • ML_ErrorRE Description: ML estimation for Random Effects Spatial Error models using Ord’s eigenvalue approach.

  • ML_LagFE Description: ML estimation for Fixed Effects Spatial Lag models with spatial impacts.

  • ML_LagRE Description: ML Spatial Lag Random Effects to estimate both the spatial lag (ρ) and the random effects component (ϕ)

In the examples shown below, the following notation will be used:

  • \(Y\): \(NT \times 1\) vector of the dependent variable

  • \(X\): \(NT \times K\) matrix of exogenous variables

  • \(\beta\): \(K \times 1\) vector of parameters

  • \(W_N\): \(N \times N\) spatial weights matrix

  • \(\iota_T\): \(T \times 1\) vector of ones

  • \(\otimes\): Kronecker product

  • \(\mu\): \(N \times 1\) vector of individual fixed or random effects

  • \(\epsilon\): \(NT \times 1\) vector of idiosyncratic errors

  • \(\rho\): Spatial lag parameter

  • \(\lambda\): Spatial error parameter

Pooled panel

\[Y = X\beta + \epsilon\]

where :math:`epsilon sim N(0, sigma^2 I_{NT})`

Optional arguments include (among others):

  • spat_diag: If True, then compute the BSK tests (boolean, default = True)

  • slx_lags: Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the SLX type (integer, default = 0).

  • slx_vars: “all” or list of booleans to select x variables to be lagged (str or list, default = “all”).

  • BSK_list: List of BSK tests to compute if spat_diag is True. Options are “all”, “LMJ”, “LM1”, “LM2”, “LMC_spatial”, “LMC_RE” (default: [“LMJ”, “LM1”, “LM2”]).

  • time_effects: If True, then include time dummies in the model specification (the first time period is omitted), (boolean, default = False)

[4]:
panel = spreg.PooledOLS(y=y_var, x=x_var, w=wq1, spat_diag=True, slx_lags=0)
print(panel.summary)
REGRESSION RESULTS
------------------

SUMMARY OF OUTPUT: POOLED OLS PANEL
------------------------------------------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :          HR                Number of Observations:        2367
Mean dependent var  :      8.8420                Number of Variables   :           3
S.D. dependent var  :      7.4372                Degrees of Freedom    :        2364
R-squared           :      0.3641
Adjusted R-squared  :      0.3636
Sum squared residual:     83215.9                F-statistic           :    676.8331
Sigma-square        :      35.201                Prob(F-statistic)     :  3.906e-233
S.E. of regression  :       5.933                Log likelihood        :   -7571.669
Sigma-square ML     :      35.157                Akaike info criterion :   15149.338
S.E of regression ML:      5.9293                Schwarz criterion     :   15166.646

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     t-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT         7.41873         0.15201        48.80313         0.00000
                  RD         4.77170         0.13421        35.55307         0.00000
                  PS         1.30852         0.15173         8.62399         0.00000
------------------------------------------------------------------------------------
Warning: Assuming panel is in wide format.
y[:, 0] refers to T0, y[:, 1] refers to T1, etc.
x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc.

SPATIAL DIAGNOSTIC TESTS
------------------------------------------------------------------------------------
TEST                             DF        VALUE           PROB
LM Marginal RE (LM1)             1        13.5268        0.00000
LM Marginal Spatial (LM2)        1        19.9909        0.00000
LM Joint (LMJ)                   2       582.6102        0.00000
================================ END OF REPORT =====================================

We can also add time fixed effects with the argument time_effects=True:

[5]:
panel_t = spreg.PooledOLS(y=y_var, x=x_var, w=wq1, spat_diag=True, slx_lags=0, time_effects=True)
print(panel_t.summary)
REGRESSION RESULTS
------------------

SUMMARY OF OUTPUT: POOLED OLS PANEL WITH TIME DUMMIES
------------------------------------------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :          HR                Number of Observations:        2367
Mean dependent var  :      8.8420                Number of Variables   :           5
S.D. dependent var  :      7.4372                Degrees of Freedom    :        2362
R-squared           :      0.3666
Adjusted R-squared  :      0.3655
Sum squared residual:     82891.8                F-statistic           :    341.7606
Sigma-square        :      35.094                Prob(F-statistic)     :  2.658e-232
S.E. of regression  :       5.924                Log likelihood        :   -7567.051
Sigma-square ML     :      35.020                Akaike info criterion :   15144.102
S.E of regression ML:      5.9178                Schwarz criterion     :   15172.949

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     t-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT         7.80035         0.23029        33.87257         0.00000
                  RD         4.78176         0.13438        35.58493         0.00000
                  PS         1.31468         0.15154         8.67540         0.00000
              time_2        -0.88538         0.29827        -2.96835         0.00302
              time_3        -0.27378         0.29881        -0.91622         0.35964
------------------------------------------------------------------------------------
Warning: Assuming panel is in wide format.
y[:, 0] refers to T0, y[:, 1] refers to T1, etc.
x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc.

SPATIAL DIAGNOSTIC TESTS
------------------------------------------------------------------------------------
TEST                             DF        VALUE           PROB
LM Marginal RE (LM1)             1        13.6660        0.00000
LM Marginal Spatial (LM2)        1        19.7664        0.00000
LM Joint (LMJ)                   2       577.4706        0.00000
================================ END OF REPORT =====================================

Fixed Effects

\[Y = (\iota_T \otimes I_N)\mu + X\beta + \epsilon\]

where :math:`iota_T` is a :math:`T times 1` vector of ones, and :math:`mu` is an :math:`N times 1` vector of fixed effects.

Optional arguments include (among others):

  • slx_lags: Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the SLX type (integer, default = 0).

  • slx_vars: “all” or list of booleans to select x variables to be lagged (str or list, default = “all”).

  • time_effects: If True, then include time dummies in the model specification (the first time period is omitted), (boolean, default = False)

[6]:
panelFE = spreg.PanelFE(y=y_var, x=x_var, w=wq1, time_effects=True)
print(panelFE.summary)
PanelFE
REGRESSION RESULTS
------------------

SUMMARY OF OUTPUT: FIXED EFFECTS PANEL (TWO-WAY)
------------------------------------------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :          HR                Number of Observations:        2367
Mean dependent var  :      8.8420                Number of Variables   :           4
S.D. dependent var  :      7.4372                Degrees of Freedom    :        2363
Pseudo R-squared    :      0.7154
Sum squared residual:     37242.6                F-statistic           :   1980.1123
Sigma-square        :      23.661                Prob(F-statistic)     :           0
S.E. of regression  :       4.864                Log likelihood        :   -6620.153
Sigma-square ML     :      15.734                Akaike info criterion :   13248.306
S.E of regression ML:      3.9666                Schwarz criterion     :   13271.384
Individual FE mean  :     13.2519

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
                  RD         0.45933         0.43621         1.05301         0.29233
                  PS        -7.76315         1.24162        -6.25246         0.00000
              time_2        -0.72031         0.24557        -2.93317         0.00336
              time_3        -0.61024         0.25150        -2.42638         0.01525
------------------------------------------------------------------------------------
Warning: Assuming panel is in wide format.
y[:, 0] refers to T0, y[:, 1] refers to T1, etc.
x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc.
================================ END OF REPORT =====================================
[7]:
# Individual fixedeffects (fixed_effects) for the first 5 observations
panelFE.fixed_effects[0:5]
[7]:
array([[3.74145206],
       [2.07285211],
       [0.11815978],
       [9.14970737],
       [3.50770994]])

Random Effects

\[Y = X\beta + v\]
\[v = (\iota_T \otimes I_N)\mu + \epsilon\]

where :math:`mu sim N(0, sigma_mu^2 I_N)` represents the random effects, and :math:`epsilon sim N(0, sigma_epsilon^2 I_{NT})`.

Optional arguments include (among others):

  • slx_lags: Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the SLX type (integer, default = 0).

  • slx_vars: “all” or list of booleans to select x variables to be lagged (str or list, default = “all”).

  • spat_diag: If True (default), then compute the ‘LMC_spatial’ BSK test (boolean).

  • time_effects: If True, then include time dummies in the model specification (the first time period is omitted), (boolean, default = False)

[8]:
panelRE = spreg.PanelRE(y=y_var, x=x_var, w=wq1, time_effects=True)
print(panelRE.summary)
PanelRE
REGRESSION RESULTS
------------------

SUMMARY OF OUTPUT: RANDOM EFFECTS PANEL (TWO-WAY)
------------------------------------------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :          HR                Number of Observations:        2367
Mean dependent var  :      8.8420                Number of Variables   :           5
S.D. dependent var  :      7.4372                Degrees of Freedom    :        2362
Pseudo R-squared    :      0.3663
Sum squared residual:     83069.7                F-statistic           :    304.2376
Sigma-square        :      24.634                Prob(F-statistic)     :  2.904e-211
S.E. of regression  :       4.963                Log likelihood        :   -7569.587
Sigma-square ML     :      24.634                Akaike info criterion :   15149.175
S.E of regression ML:      4.9633                Schwarz criterion     :   15178.021

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT         7.96329         0.24138        32.99033         0.00000
                  RD         4.48233         0.16365        27.39044         0.00000
                  PS         1.11105         0.19109         5.81414         0.00000
              time_2        -0.87882         0.24992        -3.51642         0.00044
              time_3        -0.31160         0.25087        -1.24209         0.21420
------------------------------------------------------------------------------------
Warning: Assuming panel is in wide format.
y[:, 0] refers to T0, y[:, 1] refers to T1, etc.
x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc.

VARIANCE COMPONENTS ESTIMATES
------------------------------------------------------------------------------------
Sigma2_epsilon (Idiosyncratic)         23.6611
Sigma2_mu (Individual)                 10.3578
Theta (Quasi-demeaning weight)          0.3425
------------------------------------------------------------------------------------

DIAGNOSTIC TESTS
------------------------------------------------------------------------------------
TEST                             DF        VALUE           PROB
Hausman Specification Test       4       104.8838        0.00000
LM Conditional Spatial           1        11.3924        0.00000
================================ END OF REPORT =====================================

Pooled SEM - GM estimator

\[Y = X\beta + u\]
\[u = \lambda(I_T \otimes W_N)u + \epsilon\]

where :math:`lambda` is the spatial error coefficient and :math:`W_N` is the spatial weights matrix.

Optional arguments include (among others):

  • slx_lags: Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the SLX type (integer, default = 0).

  • slx_vars: “all” or list of booleans to select x variables to be lagged (str or list, default = “all”).

  • max_iter: Maximum number of iterations of steps 2a and 2b from Arraiz2010 (int, default = 1).

  • step1c: If True, then include Step 1c from Arraiz2010 (boolean, default = False).

  • nonspat_diag: If True (default), then compute the ‘LMC_RE’ BSK test.

  • time_effects: If True, then include time dummies in the model specification (the first time period is omitted), (boolean, default = False)

[9]:
panelSEM = spreg.GM_ErrorPooled(y=y_var, x=x_var, w=wq1, time_effects=True)
print(panelSEM.summary)
GM_ErrorPooled
REGRESSION RESULTS
------------------

SUMMARY OF OUTPUT: GMM POOLED SPATIAL ERROR MODEL (SEM) WITH TIME EFFECTS
------------------------------------------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :          HR                Number of Observations:        2367
Mean dependent var  :      8.8420                Number of Variables   :           5
S.D. dependent var  :      7.4372                Degrees of Freedom    :        2362
Pseudo R-squared    :      0.3661
N. of iterations    :           1                Step1c computed       :          No

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT         7.92549         0.52087        15.21578         0.00000
                  RD         4.52893         0.21980        20.60451         0.00000
                  PS         1.06665         0.22974         4.64295         0.00000
              time_2        -0.88294         0.57053        -1.54758         0.12172
              time_3        -0.27761         0.58097        -0.47784         0.63277
              lambda         0.49960         0.02820        17.71501         0.00000
------------------------------------------------------------------------------------
Warning: Assuming panel is in wide format.
y[:, 0] refers to T0, y[:, 1] refers to T1, etc.
x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc.

DIAGNOSTIC TESTS
------------------------------------------------------------------------------------
TEST                             DF        VALUE           PROB
LM Conditional RE                1         8.3469        0.00000
Warning: The properties of the LM Conditional RE test using GM have not been
         established. We recommend using ML_ErrorPooled.
================================ END OF REPORT =====================================

Pooled SEM - ML estimator

\[Y = X\beta + u\]
\[u = \lambda(I_T \otimes W_N)u + \epsilon\]

where :math:`lambda` is the spatial error coefficient and :math:`W_N` is the spatial weights matrix.

Optional arguments include (among others):

  • slx_lags: Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the SLX type (integer, default = 0).

  • slx_vars: “all” or list of booleans to select x variables to be lagged (str or list, default = “all”).

  • method: if ‘LU’ (default), LU decomposition for sparse matrices (Recommended for Panel); if ‘ord’, Ord eigenvalue calculation (Slow for large Panel); if ‘full’, brute force (Should not use for Panel).

  • nonspat_diag: If True (default), then compute the ‘LMC_RE’ BSK test.

  • time_effects: If True, then include time dummies in the model specification (the first time period is omitted), (boolean, default = False)

[10]:
panelML_SEM = spreg.ML_ErrorPooled(y=y_var, x=x_var, w=wq1, time_effects=True)
print(panelML_SEM.summary)
ML_ErrorPooled
REGRESSION RESULTS
------------------

SUMMARY OF OUTPUT: ML POOLED SPATIAL ERROR MODEL (SEM) WITH TIME EFFECTS
------------------------------------------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :          HR                Number of Observations:        2367
Mean dependent var  :      8.8420                Number of Variables   :           5
S.D. dependent var  :      7.4372                Degrees of Freedom    :        2362
Pseudo R-squared    :      0.3661
Log likelihood      :  -7415.3400
Sigma-square ML     :     29.4794                Akaike info criterion :   14840.680
S.E of regression   :      5.4295                Schwarz criterion     :   14869.527

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT         7.92772         0.36546        21.69220         0.00000
                  RD         4.52292         0.15549        29.08778         0.00000
                  PS         1.06039         0.16516         6.42020         0.00000
              time_2        -0.88297         0.49770        -1.77409         0.07605
              time_3        -0.27716         0.49814        -0.55639         0.57795
              lambda         0.45075         0.02479        18.18283         0.00000
------------------------------------------------------------------------------------
Warning: Assuming panel is in wide format.
y[:, 0] refers to T0, y[:, 1] refers to T1, etc.
x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc.

DIAGNOSTIC TESTS
------------------------------------------------------------------------------------
TEST                             DF        VALUE           PROB
LM Conditional RE                1         7.7867        0.00000
================================ END OF REPORT =====================================

Error model - Random Effects - KKP GM Estimator

\[Y = X\beta + u\]
\[u = \lambda(I_T \otimes W_N)u + v\]
\[v = (\iota_T \otimes I_N)\mu + \epsilon\]

where the spatial error process (:math:`lambda`) applies to the composite error term, meaning both the random effects (:math:`mu`) and idiosyncratic errors (:math:`epsilon`) are spatially correlated.

Optional arguments include (among others):

  • slx_lags: Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the SLX type (integer, default = 0).

  • slx_vars: “all” or list of booleans to select x variables to be lagged (str or list, default = “all”).

  • full_weights: (boolean) Considers different weights for each of the 6 moment conditions if True or only 2 sets of weights for the first 3 and the last 3 moment conditions if False (default)

  • time_effects: If True, then include time dummies in the model specification (the first time period is omitted), (boolean, default = False).

[11]:
panelSEM_RE = spreg.GM_ErrorRE(y=y_var, x=x_var, w=wq1, time_effects=True)
print(panelSEM_RE.summary)
GM_ErrorRE
REGRESSION RESULTS
------------------

SUMMARY OF OUTPUT: GMM SPATIAL ERROR PANEL MODEL - RANDOM EFFECTS (KKP) WITH TIME EFFECTS
------------------------------------------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :          HR                Number of Observations:        2367
Mean dependent var  :      8.8420                Number of Variables   :           5
S.D. dependent var  :      7.4372                Degrees of Freedom    :        2362
Pseudo R-squared    :      0.3658

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT         8.00947         0.36223        22.11171         0.00000
                  RD         4.33873         0.17675        24.54686         0.00000
                  PS         0.98289         0.19398         5.06702         0.00000
              time_2        -0.87936         0.43506        -2.02123         0.04326
              time_3        -0.30258         0.43570        -0.69446         0.48739
              lambda         0.43481
            sigma2_v        23.83305
            sigma2_1        41.44246
------------------------------------------------------------------------------------
Warning: Assuming panel is in wide format.
y[:, 0] refers to T0, y[:, 1] refers to T1, etc.
x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc.
================================ END OF REPORT =====================================

Error model - Random Effects - ML Estimator

\[Y = X\beta + v\]
\[v = (\iota_T \otimes I_N)\mu + u\]
\[u = \lambda(I_T \otimes W_N)u + \epsilon\]

where the spatial error process (:math:`lambda`) applies only to the idiosyncratic error term (:math:`u`). The individual random effects (:math:`mu`) remain spatially independent.

Optional arguments include (among others):

  • slx_lags: Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the SLX type (integer, default = 0).

  • slx_vars: “all” or list of booleans to select x variables to be lagged (str or list, default = “all”).

  • time_effects: If True, then include time dummies in the model specification (the first time period is omitted), (boolean, default = False).

[12]:
panelSEM_RE = spreg.ML_ErrorRE(y=y_var, x=x_var, w=wq1, time_effects=True)
print(panelSEM_RE.summary)
ML_ErrorRE
REGRESSION RESULTS
------------------

SUMMARY OF OUTPUT: ML SPATIAL ERROR PANEL MODEL (SEM) - RANDOM EFFECTS WITH TIME EFFECTS
------------------------------------------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :          HR                Number of Observations:        2367
Mean dependent var  :      8.8420                Number of Variables   :           5
S.D. dependent var  :      7.4372                Degrees of Freedom    :        2362
Pseudo R-squared    :      0.3662

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT         7.97586         0.34060        23.41702         0.00000
                  RD         4.40256         0.17082        25.77277         0.00000
                  PS         1.06403         0.18945         5.61627         0.00000
              time_2        -0.88101         0.43623        -2.01959         0.04343
              time_3        -0.29602         0.43681        -0.67769         0.49797
              lambda         0.43445         0.00506        85.93267         0.00000
            sigma2_u         6.07456         0.03674       165.31880         0.00000
------------------------------------------------------------------------------------
Warning: Assuming panel is in wide format.
y[:, 0] refers to T0, y[:, 1] refers to T1, etc.
x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc.
================================ END OF REPORT =====================================

Error Model - Fixed Effects - ML Estimator

\[Y = (\iota_T \otimes I_N)\mu + X\beta + u\]
\[u = \lambda(I_T \otimes W_N)u + \epsilon\]

Optional arguments include (among others):

  • slx_lags: Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the SLX type (integer, default = 0).

  • slx_vars: “all” or list of booleans to select x variables to be lagged (str or list, default = “all”).

  • time_effects: If True, then include time dummies in the model specification (the first time period is omitted), (boolean, default = False).

[13]:
panelSEM_FE = spreg.ML_ErrorFE(y=y_var, x=x_var, w=wq1, time_effects=True)
print(panelSEM_FE.summary)
ML_ErrorFE
REGRESSION RESULTS
------------------

SUMMARY OF OUTPUT: ML SPATIAL ERROR PANEL MODEL - FIXED EFFECTS WITH TIME EFFECTS
------------------------------------------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :          HR                Number of Observations:        2367
Mean dependent var  :      0.0000                Number of Variables   :           4
S.D. dependent var  :      4.0669                Degrees of Freedom    :        2363
Pseudo R-squared    :      0.0482
Log likelihood      :  -6603.0402
Sigma-square ML     :     15.4047                Akaike info criterion :   13214.080
S.E of regression   :      3.9249                Schwarz criterion     :   13237.158
Individual FE mean  :     13.0962

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
                  RD         0.57502         0.37000         1.55413         0.12015
                  PS        -7.50039         1.08379        -6.92055         0.00000
              time_2        -0.73178         0.24282        -3.01372         0.00258
              time_3        -0.59552         0.24712        -2.40989         0.01596
              lambda         0.18464         0.02990         6.17509         0.00000
------------------------------------------------------------------------------------
Warning: Assuming panel is in wide format.
y[:, 0] refers to T0, y[:, 1] refers to T1, etc.
x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc.
================================ END OF REPORT =====================================
[14]:
# Individual fixed effects (mu_i) for the first 5 observations
panelSEM_FE.fixed_effects[0:5]
[14]:
array([[3.70982062],
       [2.1301645 ],
       [0.38974858],
       [9.01973087],
       [3.5246372 ]])

Lag Model - Random Effects - ML Estimator

\[Y = \rho(I_T \otimes W_N)Y + X\beta + v\]
\[v = (\iota_T \otimes I_N)\mu + \epsilon\]

Optional arguments include (among others):

  • slx_lags: Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the SLX type (integer, default = 0).

  • slx_vars: “all” or list of booleans to select x variables to be lagged (str or list, default = “all”).

  • spat_impacts: Include average direct impact (ADI), average indirect impact (AII), and average total impact (ATI) in summary results; Options are ‘simple’, ‘full’, ‘power’, ‘all’ or None; (str or list, default = ‘simple’).

  • time_effects: If True, then include time dummies in the model specification (the first time period is omitted), (boolean, default = False).

[15]:
panelSAR_RE = spreg.ML_LagRE(y=y_var, x=x_var, w=wq1, time_effects=True)
print(panelSAR_RE.summary)
ML_LagRE
REGRESSION RESULTS
------------------

SUMMARY OF OUTPUT: ML SPATIAL LAG PANEL - RANDOM EFFECTS WITH TIME EFFECTS
------------------------------------------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :          HR                Number of Observations:        2367
Mean dependent var  :      6.5463                Number of Variables   :           7
S.D. dependent var  :      6.1475                Degrees of Freedom    :        2360
Pseudo R-squared    :      0.3699
Log likelihood      :  -7379.9922
Sigma-square ML     :     23.8393                Akaike info criterion :   14773.984
S.E of regression   :      4.8826                Schwarz criterion     :   14814.370

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT         4.75649         0.30540        15.57459         0.00000
                  RD         3.60734         0.16273        22.16809         0.00000
                  PS         1.20358         0.16758         7.18209         0.00000
              time_2        -0.58553         0.24670        -2.37351         0.01762
              time_3        -0.08517         0.24690        -0.34497         0.73012
                W_HR         0.35428         0.02405        14.73405         0.00000
                 phi         0.74036         0.02129        34.77480         0.00000
------------------------------------------------------------------------------------
Warning: Assuming panel is in wide format.
y[:, 0] refers to T0, y[:, 1] refers to T1, etc.
x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc.

SPATIAL LAG MODEL IMPACTS
Impacts computed using the 'simple' method.
            Variable         Direct        Indirect          Total
                  RD         3.6073          1.9792          5.5866
                  PS         1.2036          0.6604          1.8639
              time_2        -0.5855         -0.3213         -0.9068
              time_3        -0.0852         -0.0467         -0.1319
================================ END OF REPORT =====================================

Lag Model - Fixed Effects - ML Estimator

\[Y = \rho(I_T \otimes W_N)Y + (\iota_T \otimes I_N)\mu + X\beta + \epsilon\]

where :math:`rho` is the spatial lag (autoregressive) coefficient.

Optional arguments include (among others):

  • slx_lags: Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the SLX type (integer, default = 0).

  • slx_vars: “all” or list of booleans to select x variables to be lagged (str or list, default = “all”).

  • spat_impacts: Include average direct impact (ADI), average indirect impact (AII), and average total impact (ATI) in summary results; Options are ‘simple’, ‘full’, ‘power’, ‘all’ or None; (str or list, default = ‘simple’).

  • time_effects: If True, then include time dummies in the model specification (the first time period is omitted), (boolean, default = False).

[16]:
panelSAR_FE = spreg.ML_LagFE(y=y_var, x=x_var, w=wq1, time_effects=True)
print(panelSAR_FE.summary)
ML_LagFE
REGRESSION RESULTS
------------------

SUMMARY OF OUTPUT: ML SPATIAL LAG PANEL - FIXED EFFECTS WITH TIME EFFECTS
------------------------------------------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :          HR                Number of Observations:        2367
Mean dependent var  :      0.0000                Number of Variables   :           5
S.D. dependent var  :      4.0669                Degrees of Freedom    :        2362
Pseudo R-squared    :      0.0684
Log likelihood      :  -6603.2997
Sigma-square ML     :     15.4124                Akaike info criterion :   13216.599
S.E of regression   :      3.9259                Schwarz criterion     :   13245.446
Individual FE mean  :     11.1174

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
                  RD         0.50779         0.35209         1.44222         0.14924
                  PS        -6.92694         1.00983        -6.85953         0.00000
              time_2        -0.58665         0.19954        -2.93997         0.00328
              time_3        -0.44757         0.20437        -2.18999         0.02852
                W_HR         0.18083         0.02952         6.12514         0.00000
------------------------------------------------------------------------------------
Warning: Assuming panel is in wide format.
y[:, 0] refers to T0, y[:, 1] refers to T1, etc.
x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc.

SPATIAL LAG MODEL IMPACTS
Impacts computed using the 'simple' method.
            Variable         Direct        Indirect          Total
                  RD         0.5078          0.1121          0.6199
                  PS        -6.9269         -1.5291         -8.4560
              time_2        -0.5866         -0.1295         -0.7161
              time_3        -0.4476         -0.0988         -0.5464
================================ END OF REPORT =====================================
[17]:
# Individual fixed effects (mu_i) for the first 5 observations
panelSAR_FE.fixed_effects[0:5]
[17]:
array([[2.76615386],
       [1.55072091],
       [0.29991187],
       [7.93198396],
       [3.20451278]])