Testing in a Random Effects Panel Data Model with Spatially Correlated Error Components and Spatially Lagged Dependent Variables

We propose a random effects panel data model with both spatially correlated error components and spatially lagged dependent variables. We focus on diagnostic testing procedures and derive Lagrange multiplier (LM) test statistics for a variety of hypotheses within this model. We first construct the joint LM test for both the individual random effects and the two spatial effects (spatial error correlation and spatial lag dependence). We then provide LM tests for the individual random effects and for the two spatial effects separately. In addition, in order to guard against local model misspecification, we derive locally adjusted (robust) LM tests based on the Bera and Yoon principle (Bera and Yoon, 1993). We conduct a small Monte Carlo simulation to show the good finite sample performances of these LM test statistics and revisit the cigarette demand example in Baltagi and Levin (1992) to illustrate our testing procedures.


Introduction
Spatial econometric models have been extensively used to study regional effects and interdependence between different spatial units.Most of the widely used spatial models are variants of the benchmark models developed in Cliff andOrd (1973, 1981) [1,2] and Anselin (1988a) [3].Based on the form of spatially correlated error components and/or spatially lagged dependent variables, these models better fit the real world data generating process by explicitly considering the spatial interdependence.Hypothesis testing for spatial dependence has been developed rapidly in the recent literature.For standard LM tests of spatial dependence in cross section models, see Anselin (1988a, b) [3,4], Anselin and Bera (1998) [5], and Anselin (2001) [6].For standard LM tests of spatial dependence in panel data models, Baltagi et al., (2003) [7] provide tests for random effects and/or spatial error correlation.Baltagi and Liu (2008) [8] provide tests for random effects and/or spatial lag dependence.Debarsy and Ertur (2010) [9] derive tests in the spatial panel data model with individual fixed effects based on Lee and Yu (2010) [10].Qu and Lee (2012) [11] consider tests in spatial models with limited dependent variables.Baltagi et al., (2013) [12] extend the model in Kapoor et al., (2007) [13] by allowing for different spatial correlation parameters in the individual random effects and in the disturbances, and they derive the corresponding LM tests.Further, standardized versions of the LM tests are discussed in Yang (2010) [14], Baltagi and Yang (2013a) [15] to remedy distributional misspecifications in finite sample and sensitivity to spatial layout.Born and Breitung (2011) [16], Baltagi and Yang (2013b) [17] discuss versions of LM tests that are robust against unknown heteroskedasticity.Recently, Yang (2015) [18] provides residual-based bootstrap procedure to obtain improved approximations to the finite sample critical values of the LM test statistics in spatial econometric models.
However, to the best of our knowledge, there are no test statistics treating the individual random effects, the spatial error correlation, and the spatial lag dependence simultaneously.We contribute to the literature by constructing various LM test statistics in such a general framework, or the so-called spatial autoregressive model with autoregressive disturbances (SARAR).Our results are useful for applied researchers to implement and perform model diagnostic testing in the SARAR framework.In particular, we first derive the joint LM test for the individual random effects and the two spatial effects.We next derive LM tests for the individual random effects.Finally, we derive LM tests for the two spatial effects.In addition, we provide robust LM tests in some cases as needed in order to guard against local misspecification.We emphasize some key features of the robust LM test in the following.Bera and Yoon (1993) [19] argue that the LM test with specific values of the nuisance parameters (marginal LM test) might suffer from local misspecification in the nuisance parameters.They propose robust LM test to guard against such local misspecification, see also Anselin et al., (1996) [20], Bera et al., (2001Bera et al., ( , 2009Bera et al., ( , 2010) ) [21][22][23], and He and Lin (2013) [24].Here, we emphasize two advantages of the robust LM test.First, the asymptotic size of marginal LM test will be distorted under local misspecification in the nuisance parameters since it follows a non-central χ 2 distribution.On the other hand, robust LM test follows a χ 2 distribution under such misspecification, thus it can provide valid asymptotic size as long as the misspecification is local.Second, while LM test without specifying values of the nuisance parameters (conditional LM test) does not suffer from such size distortion, it generally needs the maximum likelihood estimator (MLE), which could be costly in computation.In contrast, the robust LM test only requires restricted estimator under the relevant joint null hypothesis, which is simply the ordinary least square (OLS) estimator in most cases.Therefore, the robust LM test can provide result as good as the conditional LM test at a lower computational cost, provided that the deviation of nuisance parameters is local.However, there is one potential loss in using the robust LM test.If the values of nuisance parameters are correctly specified, the robust LM test is in general less powerful than the marginal LM test.Also, when the nuisance parameters deviate far away from the pre-specified values, the robust LM test is generally invalid.In sum, the standard LM tests (marginal and conditional LM tests) and the robust LM tests complement each other, and they should be used together for inference purposes.
In this paper, we maintain the assumption of random effects model, while an alternative specification is the fixed effects model with spatial dependence as in Lee and Yu (2010) [10], Debarsy and Ertur (2010) [9], and He and Lin (2013) [24].On the one hand, the random effects specification is a parsimonious way to allow for individual effects in different spatial units and it will be particularly useful for testing and selection in microeconometric applications when the number of units is very large.On the other hand, the fixed effects specification, which allows for correlation between the individual effects and the covariates, is more suited for many macro studies when the number of units is not very large (see Elhorst (2014) [25] for more discussion on comparison of the random effects model and the fixed effects model).
The rest of the paper is organized as follows.Model specification is discussed in Section 2. The LM test statistics are presented In Section 3. In Section 4, we report the Monte Carlo simulation results to show their satisfactory finite sample size and power performances.In Section 5, we provide an empirical example to illustrate our testing procedures.Section 6 concludes with suggestions for future research.All mathematical derivations are relegated to the Appendices.

The Model
Suppose that the data is generated according to the following spatial panel data model, for t = 1, 2, • • •, T, y t = λW y t + X t β + t , t = ρM t + µ + v t . (2.1) In the above specification, y t = (y t1 , y t2 , •••, y tN ) is an N ×1 vector of dependent variable for period t.It is spatially interdependent, as reflected by the spatial lag dependence coefficient λ.X t is an N × (K + 1) matrix of non-stochastic regressors for period t, with the first column to be ones, and is the corresponding (K + 1) × 1 slope parameter vector.t = ( t1 , t2 , • • •, tN ) is an N × 1 vector of the regression error term for period t.The error vector is also spatially correlated, as reflected by the spatial error correlation coefficient ρ. µ = (µ 1 , µ 2 , • • •, µ N ) is an N × 1 vector representing the individual random effects.The random effects terms {µ i }, i = 1, • • •, N are i.i.d.across i, with zero mean, variance σ 2 µ and E|µ i | 4+c 1 < ∞ for some c 1 > 0. v t = (v t1 , v t2 , • • •, v tN ) is an N × 1 vector of innovation terms.The innovation terms {v ti }, t = 1, • • •, T, i = 1, • • •, N are i.i.d.across i and t, with zero mean, variance σ 2 v and E|v ti | 4+c 2 < ∞ for some c 2 > 0 (see Lee and Yu (2012) [26] for other regularity and identification conditions as needed for asymptotic theory).W and M are nonstochastic spatial weights matrices of size N × N .Typically, they are specified by the first-order rook contiguity criterion and are row-standardized so that each row sums up to one.
By stacking across t, the model can be written as where ι T is a T × 1 vector of ones, I denotes the identity matrix with its dimension in the subscript, and ⊗ denotes the kronecker product.
Using the results in Magnus (1982) [27], we get 1) , where JT = J T /T , v ) and = By − Xβ, the log-likelihood function of the random vector y as if it is normally distributed is

LM and Robust LM Test Statistics
In this section, we provide explicit formulae for the LM test statistics.We first present the joint LM test for both the individual random effects and the spatial effects.We then provide LM test statistics for the individual random effects.Lastly, we present LM test statistics for the spatial effects, namely, the spatial error correlation and/or the spatial lag dependence. 1 In addition, we provide formulae for robust LM tests when necessary.
Before presenting the LM test statistics, we introduce the following notations for easy reference.Let Notice that there are four cases for which we do not present the LM tests formulae, since these four cases are not particularly interesting.The null hypotheses for the four cases are: µ = λ = 0 (ρ = 0) and σ 2 µ = λ = 0 (ρ = 0).The LM tests formulae for these four cases are not presented in the paper, but they are available upon request from the authors. where

Jointly Testing for Random Effects and Spatial Effects
Now we are ready to present the test statistics.We first construct the joint LM test statistic for the individual random effects and the spatial effects, namely, the spatial error correlation and the spatial lag dependence.The joint hypothesis is H a 0 : σ 2 µ = ρ = λ = 0 vs. H a 1 : at least one of σ 2 µ , ρ and λ is not zero.Thus we are testing the classical pooled panel data model against the full specification in (2.1), the LM test in this case is given by where v,a − N , and β a is the OLS estimator of β.Under H a 0 , LM a is asymptotically distributed as χ 2  3 , where χ 2 d denotes the χ 2 distribution with degree of freedom d.The test statistic LM a is useful in practice, and it is simple to compute since only the OLS estimator is required.Researchers should first use this joint LM test to determine if there is individual random effects and/or spatial effects in the general specification (2.1).If the joint null hypothesis cannot be rejected, then it is reasonable to just adopt the classical pooled panel data model.Otherwise either the individual random effects, or the spatial error correlation, or the spatial lag dependence need to be considered.As in Baltagi et al., (2003) [7], we do not provide formal proofs for the asymptotic null distributions of the LM test statistics in this paper, but these distributions are likely to hold by using the Central Limit Theorems (CLTs) in Kelejian andPrucha (2001, 2010) [28,29] under similar sets of low level assumptions in their papers.

Testing for Random Effects
In this section, we focus on testing for the individual random effects in various spatial panel data models.We provide formulae for the standard LM tests as well as formulae for the robust LM tests when necessary.The first hypothesis we consider is ).The null model is the classical pooled panel data model, and the alternative model is the random effects panel data model without spatial effects.The LM test denoted as LM b , is available in Baltagi et al., (2003) [7].Moreover, it can be shown that the robust LM test is the same as LM b in this case.We thus omit these formulae for the sake of compactness.
The second hypothesis is H c 0 : σ 2 µ = 0 (ρ = 0, λ = 0) vs. H c 1 : σ 2 µ > 0 (ρ = 0, λ = 0). 2 Under the null hypothesis, it is the pooled panel data model with spatial error correlation.Under the alternative 2 By ρ = 0, we mean that ρ is allowed to be nonzero, and the notation " =" has similar meaning in the rest of this paper.hypothesis, it is the random effects panel data model with spatial error correlation.The LM test statistic in this case is given by where z σ 2 µ ,c is z σ 2 µ evaluated at the restricted MLE under H c 0 .3Under H c 0 , LM c is asymptotically distributed as χ 2  1 .Further, it can be easily shown that the robust LM test in this case is the same as LM c .Thus LM c itself is robust against local deviation of λ from 0, and this will be confirmed by the simulation results.
The third hypothesis is Under the null hypothesis, it is the pooled panel data model with spatial lag dependence.Under the alternative hypothesis, it is the random effects panel data model with spatial lag dependence.The LM test statistic, denoted as LM d , is available in Baltagi and Liu (2008) [8].Moreover, it can be shown that the robust LM test in this case is the same as LM d .We thus omit these formulae here.
The last hypothesis concerning testing for the individual random effects is H e 0 : σ 2 µ = 0 (ρ = 0, λ = 0) vs. H e 1 : σ 2 µ > 0 (ρ = 0, λ = 0).Under the null hypothesis, it is the pooled panel data model with both spatial error correlation and spatial lag dependence.Under the alternative hypothesis, it is the full model in (2.1).The LM test statistic is given by Under H e 0 , LM e is asymptotically distributed as χ 2 1 .LM e tests for the individual random effects in the most general spatial model, and it is particularly useful when the researcher does not have any prior knowledge about whether the spatial error correlation and/or spatial lag dependence exist or not.In practice, the above four LM tests for the individual random effects correspond to different prior information on the nuisance parameters, and they need to be analyzed together to lead to the most appropriate model.
Notice that the LM tests in Section 3.2 are all designed for two-sided alternative hypothesis, while the parameter involved in the hypotheses, σ 2 µ , is by definition nonnegative.While our LM tests have good power against the one-sided alternative (see the simulation results), we point out that power of these tests can be further improved by following the ideas in Honda (1985Honda ( , 1991) ) [30,31].

Testing for Spatial Effects
In this section, we focus on testing for the spatial effects.We provide formulae for the standard LM tests as well as formulae for the robust LM tests when necessary.

Joint Tests for Spatial Effects
In practice, researcher may be interested in jointly testing for the spatial error correlation and the spatial lag dependence.The first joint hypothesis is H f 0 : ρ = λ = 0 (σ 2 µ = 0) vs. H f 1 : at least one of ρ and λ is not zero (σ 2 µ = 0).Under the null hypothesis, it is the classical pooled panel data model.Under the alternative hypothesis, it is the pooled panel data model with at least one type of the spatial effects.The LM test statistic in this case is given by where all quantities involved are defined Section 3.1 since only the OLS estimator is needed in this case.The test LM f is a useful extension of the result in Anselin et al., (1996) [20] to the panel data case.Interestingly, LM f is the sum of the first three terms of LM a .Under H f 0 , LM f is asymptotically distributed as χ 2  2 .It can be easily shown that the robust LM test in this case is the same as LM f .The second joint hypothesis is H g 0 : ρ = λ = 0 (σ 2 µ ≥ 0) vs. H g 1 : at least one of ρ and λ is not zero (σ 2 µ ≥ 0).Under the null hypothesis, it is the random effects panel data model without any spatial effects.Under the alternative hypothesis, it is the random effects panel data model with at least one type of spatial effects.The LM test statistic in this case is given by Under H g 0 , LM g is asymptotically distributed as χ 2 2 .Notice that both LM f and LM g are useful for jointly testing the spatial error correlation and spatial lag dependence.However, LM f assumes that it is pooled panel data model, while LM g allows for the individual random effects.Since LM f is the same as its robust version, then it can guard against local deviation of σ 2 µ from zero.However, LM g will work well even when σ 2 µ deviates far away from zero.

Testing for Spatial Error Correlation
In this section, we focus on testing for spatial error correlation.The first hypothesis we consider is . Under the null hypothesis, it is the classical pooled panel data model.Under the alternative hypothesis, it is the pooled panel data model with spatial error correlation.The LM and robust LM (denoted as LM * ) test statistics are given by where all quantities involved are defined in Section 3.1 since only the OLS estimator is needed in this case.Notice that although the formula of LM h is available in Baltagi et al., (2003) [7], we provide it here for comparison purposes as it is different from the robust test LM * h , which has not been considered previously in the literature.Under H h 0 , if the nuisance parameters λ and σ 2 µ do not deviate from 0, both LM h and LM * h are asymptotically distributed as χ 2 1 .However, when ρ = 0, but either λ or σ 2 µ deviates locally from 0, the distribution of LM h becomes non-centralized, tending to over reject the null hypothesis.On the other hand, LM * h is still asymptotically distributed as χ 2 1 , thus it does not suffer from size distortion as LM h .The second hypothesis is H i 0 : ρ = 0 (σ 2 µ = 0, λ = 0) vs. H i 1 : ρ = 0 (σ 2 µ = 0, λ = 0).Under the null hypothesis, it is the pooled panel data model with spatial lag dependence.Under the alternative hypothesis, it is the pooled panel data model with both spatial error correlation and spatial lag dependence.The LM test statistic is given by LM i is a useful extension of the results in Anselin et al., (1996) [20] to the panel data case.Under H i 0 , LM i is asymptotically distributed as χ 2  1 .Moreover, it can be easily shown that the robust LM test in this case is the same as LM i .Thus LM i itself is robust against local deviation of σ 2 µ from 0, and this will be confirmed by the simulation results.
The third hypothesis is H j 0 : ρ = 0 (σ 2 µ ≥ 0, λ = 0) vs. H j 1 : ρ = 0 (σ 2 µ ≥ 0, λ = 0).Under the null hypothesis, it is the random effects panel data model without spatial effects.Under the alternative hypothesis, it is the random effects panel data model with spatial error correlation.The LM and robust LM test statistics in this case are given by When ρ = 0, and if the nuisance parameter λ does not deviate from 0, both LM j and LM * j are asymptotically distributed as χ 2  1 .However, when ρ = 0, but λ deviates locally from 0, the distribution of LM j becomes non-centralized, tending to over reject the null hypothesis.On the other hand, LM * j is still asymptotically distributed as χ 2  1 in this case, thus it does not suffer from size distortion as LM j .The last hypothesis for spatial error correlation is H k 0 : ρ = 0 (σ 2 µ ≥ 0, λ = 0) vs. H k 1 : ρ = 0 (σ 2 µ ≥ 0, λ = 0).Under the null hypothesis, it is the random effects panel data model with spatial lag dependence.Under the alternative hypothesis, it is the random effects panel data model with both spatial error correlation and spatial lag dependence.The LM test statistic in this case is given by Under H k 0 , LM k is asymptotically distributed as χ 2 1 .In practice, to test for the spatial error correlation, the above test statistics correspond to different prior information on the nuisance parameters, and they need to be analyzed together to lead to the most appropriate model.

Testing for Spatial Lag Dependence
In this section, we focus on testing for the spatial lag dependence.The first hypothesis we consider is . Under the null hypothesis, it is the classical pooled panel data model.Under the alternative hypothesis, it is the pooled panel data model with spatial lag dependence.The LM and robust LM test statistic in this case are given by where all the related quantities are defined in Section 3.1 since only the OLS estimator is needed in this case.The formulae for LM l and LM * l are useful extensions of the results in Anselin et al., (1996) [20] to the panel data case.When λ = 0, and if the nuisance parameters σ 2 µ and ρ do not deviate from 0, both LM l and LM * l are asymptotically distributed as χ 2 1 .However, when λ = 0, but either σ 2 µ or ρ deviates locally from 0, the distribution of LM l becomes non-centralized, tending to over reject the null hypothesis.On the other hand, LM * l is still asymptotically distributed as χ 2 1 in this case, thus it does not suffer from size distortion as LM l .
The second hypothesis is H m 0 : λ = 0 (σ 2 µ = 0, ρ = 0) vs. H m 1 : λ = 0 (σ 2 µ = 0, ρ = 0).Under the null hypothesis, it is the pooled panel data model with spatial error correlation.Under the alternative hypothesis, it is the pooled panel data model with both spatial error correlation and spatial lag dependence.The LM test statistic in this case is given by LM m is a useful extension of the result in Anselin et al., (1996) [20] to the panel data case, and it is asymptotically distributed as χ 2 1 under H m 0 .It can be easily shown that the robust LM test in this case is the same as LM m .Thus LM m itself is robust against local deviation of σ 2 µ from 0, and this will be confirmed by the simulation results.
The third hypothesis is Under the null hypothesis, it is the random effects panel data model without spatial effects.Under the alternative hypothesis, it is the random effects panel data model with spatial lag dependence.The LM and robust LM test statistics are given by . (3.12) Notice that although the formula of LM n is available in Baltagi and Liu (2008) [8], we provide it here for comparison purposes since it is different from the robust test LM * n , which has not been considered previously in the literature.When λ = 0, and if the nuisance parameters ρ does not deviate from 0, both LM n and LM * n are asymptotically distributed as χ 2 1 .However, when λ = 0, but ρ deviates locally from 0, the distribution of LM n becomes non-centralized, tending to over reject the null hypothesis.On the other hand, LM * n is still asymptotically distributed as χ 2 1 in this case, thus it does not suffer from size distortion as LM n .
The last hypothesis is . Under the null hypothesis, it is the random effects panel data model with spatial error correlation.Under the alternative hypothesis, it is the random effects panel data model with both spatial error correlation and spatial lag dependence.The LM test statistic in this case is given by In practice, to test for the spatial lag dependence, the above test statistics correspond to different prior information on the nuisance parameters, and they need to be analyzed together to lead to the most appropriate model.

Monte Carlo Experiment
In this section, we conduct and present a small Monte Carlo experiment to show satisfactory performances of the above LM test statistics.In our Monte Carlo experiment, the data generating process is, for where α = 5, β = 0.5.x it is a single variable and is generated as x it = 0.1t + 0.5x i,t−1 + z it , where z it is generated according to a uniform distribution on [−0.5, 0.5].The initial value x i0 is set to be 5 + 10z i0 .The random effects term µ i is generated according to µ i ∼ i.i.n.(0, σ 2 µ ), and the innovation term v it is generated according to v it ∼ i.i.n.(0, σ 2 v ).σ 2 µ takes values 0, 0.2, 0.5, and 0.8, while σ 2 v is fixed to be 1.The spatial weights matrices M and W are set to be first-order rook and queen contiguity matrices with row-standardization, respectively.The spatial error correlation parameter ρ and spatial lag parameter λ vary in [−0.8, 0.8], with increment 0.2.Two combinations of sample size (N, T ) are considered, namely (49, 7) and (100, 10).Each experiment is replicated 1000 times, and the nominal size is set to be 0.05.
Frequency of rejection (FoR) of the joint test LM a is summarized in Table 1, where the upper part and lower part correspond to different sample sizes.We only report the case when σ 2 µ = 0.For other cases, that is, σ 2 µ = 0.2, 0.5, 0.8, FoRs are uniformly higher than that when σ 2 µ = 0.This is because we are jointly testing σ 2 µ = ρ = λ = 0.The empirical sizes of LM a are 0.049 and 0.050 for the (49, 7) and the (100, 10) sample, respectively.They are almost the same as the nominal size, reflecting that the limiting χ 2  3 distribution approximates the finite sample null distribution very well.As ρ or λ deviates from 0, FoR increases very fast.For example, when the sample size is (49, 7), FoR is 0.995 when ρ = λ = 0.2, and it reaches 1 when ρ = λ = 0.4.The power performance when sample size is (100, 10) is better than that when the sample size is (49, 7).The good size and power performance demonstrates that the joint test LM a should be very useful for applied researcher to determine whether there are individual random effects and spatial effects in a preliminary diagnostic testing process.
Experiment results for LM c and LM e are summarized in Table 2.For LM c , we only report results when ρ = −0.4 and 0.4 here to save space.The results when ρ takes other values are very similar, and they are available upon request.First, for the (49,7) sample, the empirical sizes of LM c are 0.043 and 0.036 when ρ = −0.4 and 0.4, respectively.As σ 2 µ increases from 0, the FoR of LM c increases very fast.Actually, when ρ = −0.4,FoR of LM c is 0.976 even when σ 2 µ is only 0.2.Second, we discussed in Section 3.2 that the robust LM test corresponding to LM c is the same as LM c , which implies that LM c itself is robust against local deviation of λ from 0. This is confirmed by the column for σ 2 µ = 0 in Table 2. Given σ 2 µ = 0, for the (49,7) sample, when λ varies in [−0.4,0.4], the FoRs of LM c are in the range of [0.036, 0.057].Thus LM c itself does not suffer from size distortion under local misspecification of the nuisance parameter λ.As expected, the performance of LM c for the (100, 10) sample is even better than that for the (49, 7) sample.Next, for LM e , we choose to report the simulation results for a few combinations of ρ and λ as shown in the table.Results for other cases are very similar.For the (49,7) sample, the empirical sizes of LM e vary in [0.035, 0.044], and the FoR increases rapidly as σ 2 µ increases from 0. As expected, the performance of LM e for the (100, 10) sample is even better than that for the (49, 7) sample.Both LM c and LM e are useful in testing for the random effects.LM e is useful in testing for the random effects when the researcher does not have any knowledge about the spatial effects, while LM c is particularly useful when the researcher has information that there is only spatial error correlation.λ −0.8 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 −0.6 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 −0.4 1.000 1.000 1.000 1.000 1.000 0.988 1.000 1.000 1.000 −0.2 1.000 1.000 1.000 1.000 0.864 0.758 1.000 1.000 1.000 0.0 1.000 1.000 1.000 0.989 0.050 0.986 1.000 1.000 1.000 0.2 1.000 1.000 1.000 0.911 0.926 1.000 1.000 1.000 1.000 0.4 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 0.6 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 0.8 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 The simulation results for LM f and LM g are presented in Tables 3 and 4, respectively.From Table 3, the empirical sizes of LM f are 0.053 and 0.050 for the (49, 7) and (100, 10) sample, respectively.As either ρ or λ deviates from 0, the FoR of increases very fast, indicating good power performance of LM f .For example, when ρ = λ = 0.2, FoR of LM f is 0.994 for the (49, 7) sample, while it is 1 for the (100, 10) sample.In Table 4, we only report the results for the case when σ 2 µ = 0.5 to save space, results for the other two cases are similar and available upon request.The empirical sizes of LM g are 0.050 and 0.043 for the (49, 7) and the (100, 10) sample, respectively.Similar to LM f , as either ρ or λ deviates from 0, the FoR of increases rapidly.Both LM f and LM g are useful in jointly detecting spatial error correlation and spatial lag dependence.LM f is useful when we assume pooled panel data model, while LM g is useful when we assume random effects panel data model.λ −0.8 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 −0.6 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 −0.4 1.000 1.000 1.000 1.000 1.000 0.993 1.000 1.000 1.000 −0.2 1.000 1.000 1.000 1.000 0.916 0.829 1.000 1.000 1.000 0.0 1.000 1.000 1.000 0.992 0.050 0.990 1.000 1.000 1.000 0.2 1.000 1.000 1.000 0.933 0.953 1.000 1.000 1.000 1.000 0.4 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 0.6 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 0.8 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000  Now we discuss simulation results of the test statistics for spatial error correlation, their FoRs are summarized in Tables 5 and 6 for different sample sizes.We focus on the (49, 7) sample for discussion.For LM h , the empirical size is 0.048.Moreover, LM h is very powerful in detecting spatial error correlation given that σ 2 µ = λ = 0.For example, FoR of LM h is 0.856 when ρ = −0.2.However, as discussed in Section 3.3.2,LM h is not robust against local misspecification, and this is confirmed by the simulation results.Given ρ = 0, when σ 2 µ and λ deviate locally from 0, the large FoRs of LM h are undesirable.For example, when ρ = 0 but σ 2 µ = λ = 0.2, FoR of LM h is 0.416.However, this size distortion is avoided by using LM * h .When ρ = 0, σ 2 µ takes values 0, 0. Although it is a little oversized in some cases, it is much better than that of LM h .On the other hand, the robust LM test is supposed to be less powerful than the corresponding LM test when the nuisance parameters are correctly specified.This is also confirmed by the simulation results, that is, when σ 2 µ = λ = 0, LM * h is less powerful than LM h .For example, when ρ = −0.2,FoR of LM h is 0.856, while that of LM * h is 0.626.Next, LM i tests for spatial error correlation in a pooled panel data model with spatial lag dependence.When σ 2 µ = 0, the empirical sizes of LM i vary in [0.040, 0.060].As ρ deviates from 0, FoR increases as expected.Furthermore, as discussed in Section 3.3.2, the robust LM test in this case is the same as LM i , implying that LM i is robust against local deviation of σ 2 µ from 0. This is confirmed by the simulation results.When σ 2 µ = 0.2, ρ = 0, the empirical sizes of LM i vary in [0.058, 0.080].Next, we discuss LM j and LM * j .LM j tests for spatial error correlation in a random effects panel data model without spatial lag dependence.We only present the representative result when σ 2 µ = 0.5 to save space, results in other cases are very similar.The empirical size of LM j is 0.045, and the FoR increases as ρ deviates away from 0. For example, FoR is 0.835 when ρ = −0.2.However, LM j suffers from size distortion when the nuisance parameter λ deviates away from 0. For example, when λ = −0.4,ρ = 0, the FoR of LM j is 0.747, which is undesirably high.For the same case, FoR of LM * j is 0.064.On the other hand, the robust LM test is less powerful when the nuisance parameter is correctly specified.This is also confirmed by the simulation results.For example, when λ = 0, ρ = −0.2,FoR of LM * j is 0.602, while that of LM j is 0.835.Lastly, we discuss the performance of LM k .LM k tests for spatial error correlation in a random effects panel data model with spatial lag dependence.The empirical sizes of LM k vary in [0.038, 0.058].As expected, when ρ moves away from 0, FoR increases rapidly, suggesting its good power performance.For all of the above tests, their performances are even better for the (100, 10) sample than for the (49, 7) sample and follow a similar discussion.In sum, the test statistics LM h , LM * h , LM i , LM j , LM * j , and LM k are all useful for detecting the spatial error correlation, but they are suited for different assumptions about the nuisance parameters.In practice, researchers are suggested to analyze them together to draw correct inference on ρ.Finally, the performances of the test statistics for spatial lag dependence are summarized in Tables 7 and 8.We focus on the (49, 7) sample for discussion.For LM l , the empirical size is 0.044, and it is very powerful in detecting the spatial lag dependence given that σ 2 µ = ρ = 0.For example, FoR of LM l is 0.987 when λ = −0.4.However, as discussed in Section 3.3.3,LM l is not robust against local misspecification, and this is confirmed by the simulation results.Given λ = 0, when σ 2 µ and ρ deviate locally from 0, the large FoRs of LM l are undesirable.For example, when λ = 0 but σ 2 µ = ρ = 0.2, FoR of LM l is 0.526.This size distortion is to some extent avoided by LM * l .When λ = 0 and σ 2 µ takes values 0, 0.2 and ρ ∈ [−0.2, 0.2], FoRs of LM * l are in the range of [0.035, 0.088].However, LM * l should be used with caution in this case, since the range of ρ in which LM * l provides valid size is narrow, and this becomes even worse for the (100, 10) sample.On the other hand, the robust LM test is supposed to be less powerful than the corresponding LM test when the nuisance parameters are correctly specified.When σ 2 µ = ρ = 0, LM * l is less powerful than LM l .For example, when λ = −0.4,FoR of LM l is 0.987, while that of LM * l is 0.809.Next, LM m tests for the spatial lag dependence in a pooled panel data model with spatial error correlation.The empirical sizes of LM m vary in [0.037, 0.055].As λ deviates from 0, FoR increases.Moreover, as discussed in Section 3.3.3,the robust LM test in this case is the same as LM m , implying that LM m itself is robust against local deviation of σ 2 µ from 0. This is confirmed in the simulation results.When σ 2 µ = 0.2, λ = 0, the FoRs of LM m vary in [0.060, 0.74].Next, we discuss LM n and LM * n .LM n tests for the spatial lag dependence in a random effects panel data model without spatial error correlation.We only present the representative result when σ 2 µ = 0.5, results in other cases are very similar.The empirical size of LM n is 0.035, and the FoR increases as λ deviates away from 0. For example, FoR is 0.981 when λ = −0.4.However, LM n suffers from size distortion when the nuisance parameter ρ deviates away from 0. For example, when λ = 0, ρ = −0.2, the FoR of LM n is 0.476, which is undesirably high.For the same case, FoR of LM * n is 0.063.However, as LM * l , LM * n should also be used with caution, since the range of ρ in which LM * n provides valid size is narrow, and it becomes even worse for the (100, 10) sample.On the other hand, LM * n is less powerful than LM n when ρ = 0.For example, when ρ = 0, λ = −0.4,FoR of LM * n is 0.778, while that of LM n is 0.981.Lastly, we discuss the performance of LM o .LM o tests for the spatial lag dependence in a random effects panel data model with spatial error correlation.The empirical sizes of LM o vary in [0.063, 0.079].As expected, when λ moves away from 0, FoR increases, suggesting its good power performance.For all of the above tests, their performances for the (100, 10) sample follows a similar discussion.In sum, the test statistics LM l , LM * l , LM m , LM n , LM * n , and LM o are all useful for detecting the spatial lag dependence, but they are suited for different assumptions about the nuisance parameters.In practice, researchers are suggested to analyze them together to draw correct inference on λ.

Empirical Illustration
In this section, we revisit the empirical example in Baltagi and Levin (1992) [32].For the purpose of illustrating usefulness of the test statistics in our framework, we estimate a static demand model for cigarettes as in Elhorst (2014) [25].The data is obtained from the Wiley website, it is a panel data of 45 U.S. states and Washington D.C. over the period of 1963-1992. 4We estimate the regression equation In the above specification, C t is the vector of average cigarettes consumption (in packs) per capita (14 years and older) for all the states in a given year t.P t is the corresponding price (per pack) vector in year t, with β 1 capturing the price effect on the demand for cigarettes.Y t is the vector of per capita disposable income in year t, with β 2 capturing the income effect on the demand for cigarettes.In the regression analysis, in addition to the standard price and income effects, we are particularly interested in whether and how the consumption of cigarettes in one state is related to those of its neighboring states.This is reflected by the spatial lag dependence structure (or the corresponding parameter λ).Further, we use the error component structure to allow for individual random effects and spatial correlation in the error term.For the spatial weights matrices, we choose two specifications and try different combinations of them.One is the standard row-normalized first-order rook contiguity matrix.The other one is the row-standardized border length weights matrix as suggested in Debarsy et al., (2012) [33]. 5ince we are particularly interested in whether the consumptions of cigarettes are spatial correlated and how they are correlated, we plot the average consumption of cigarettes (in packs) per capita over the 30 years for all the states in Figure 1.On the one hand, we see that the cigarette consumptions in some states are negatively correlated with those of its neighboring states.For example, Utah, which has a high percentage of Mormon population, 6 has the lowest consumption of cigarettes, with the average consumption to be 67.9 packs per capita per year.In sharp contrast, the consumption of cigarettes in Nevada is nearly 2.6 times of that of Utah, and this could be attributed to the fact that Nevada is a highly tourist state with many casinos.The cigarette consumption in Utah is negatively correlated with those of its neighboring states.This similar pattern also hold for Nevada, New Mexico, Kentucky, and New Hampshire.On the other hand, we see that the consumptions of cigarettes among many other states tend to be similar and thus positively correlated, examples include Iowa, Wisconsin, Pennsylvania, Alabama, Georgia, and so on.The overall spatial dependence is not clear and we will use the formal regression analysis to assess it below.Before the regression analysis, we first perform the diagnostic procedures and the results are summarized in Table 9.The first row in Table 9 shows that the joint null hypothesis H a 0 is strongly rejected, thus the classical pooled panel data model not appropriate for this data set, and the OLS estimator is biased.The next four rows show that the random effects model is strongly favored against the pooled panel data model, regardless of the assumptions imposed on the spatial parameters.Next, when we test for the spatial error effect and the spatial lag effect jointly, the values of LM f and LM g show that the null hypothesis ρ = λ = 0 is rejected no matter we assume σ 2 µ = 0 or allow for the case σ 2 µ > 0. This points us to a random effects model with at least one type of spatial effects.In the next six rows, we focus on testing for the spatial error correlation.Although these test statistics unanimously reject the null hypothesis ρ = 0 in favor of a model with spatial error correlation, we point out that the appropriate statistics should be LM j , LM * j , and LM k given the presence of random effects but not spatial lag dependence yet at this stage.Finally, we test for the spatial lag dependence, the results in the last six rows suggest rejecting the null hypothesis of no spatial lag dependence, although there is a small value of LM * l .Given that the random effects and the spatial error correlation are present by results above, we point out that the appropriate statistics should be LM * l , LM * n , and LM o .From the estimation results in Table 10, the estimated ρ is between 0.353 and 0.622 and thus it is not proper to consider such value of ρ as local deviation from 0. As a result, the robust LM tests do not apply.We are left with LM o , and it points to the presence of spatial lag dependence.In the following, we first estimate the random effects model with spatial error correlation using two types of spatial weights matrices, then we add in the spatially lagged dependent variable as suggested by our test statistics.
The estimation results are summarized in Table 10.The first column provides the OLS benchmark estimation result for comparison purpose.Although it is biased, all the parameter estimates have expected signs.Price has a negative effect on the consumption of cigarettes per capita, and the disposable income per capita has a positive effect on the consumption of cigarettes per capita, which are consistent with the standard consumption theory.In Columns 2 and 4, we include the spatial error correlation for the two different spatial weights matrices.Compared to the OLS estimates, the price and income elasticity all become smaller in magnitude but have the same signs.The estimated spatial error correlation are positive as 0.353 and 0.364, which do not differ much for the two different spatial weights matrices.In Columns 3, 5, 6, and 7, we estimate the full model with different combinations of the weights matrices.The estimates for the spatial lag dependence is negative and statistically significant, which is consistent with our diagnostic testing results.We thus conclude that the full model is the more appropriate specification, and overall we find that the negative correlation dominates in the spatial dependence among cigarette consumptions.

Conclusions
In this paper, we propose a panel data random effects models with both spatially correlated error components and spatially lagged dependent variables.We consider diagnostic testing within such a framework.We first derive the joint LM test for the individual random effects, the spatial error correlation and the spatial lag dependence.In practice, applied researchers should first consider this joint test.If the joint null hypothesis cannot be rejected, it is reasonable to adopt the classical pooled panel data model.Otherwise, either the individual random effects, or the spatial error correlation, or the spatial lag dependence must be taken into consideration.Next, we derive a wide range of LM tests for the individual random effects and for the two spatial effects separately.In addition, in order to guard against possible local model misspecification, we apply the Bera and Yoon (1993) [19] principle and construct robust LM tests in some cases.These test statistics complement each other and should be used together in performing diagnostic test to search for the most appropriate model.A small Monte Carlo experiment is carried out and the size and power performances of these test statistics are satisfactory.We further use the cigarette demand data set in Baltagi and Levin (1992) [32] to illustrate our testing procedures.Some future research directions can be considered.First, for the model specification of spatially correlated error components used in this paper, although it allows for both spatial spillovers of permanent and temporary shocks, it does not permit different intensities of these two shocks.It would be of interest to relax this assumption and further generalize our model (see Baltagi et al., 2013 [12]).Second, one can borrow the ideas in Baltagi andYang (2013a, 2013b) [15,17] to modify our test statistics in order to remedy distributional misspecifications in finite sample, sensitivity to spatial layout, or to be robust against unknown heteroskedasticity.
, where = By − Xβ.Let I be the information matrix, that is, Then after some routine calculation, the elements of I are given by tr(R 1 ), Due to the large number of test statistics in this paper, it turns out to be convenient to introduce some general notations for reference and easy exposition.Let where = By − X β, and A, B, Ω, β, σ 2 v are restricted MLEs of A, B, Ω, β, σ 2 v , respectively.Next, define For notational convenience in deriving many LM test statistics in Appendix B, we write the general information matrix as , where J 11 = J ρρ J ρλ • J λλ .
Let K = J 11 − J 12 J −1 22 J 21 and L = J 22 − J 21 J −1 11 J 12 , thus the upper left 2 by 2 submatrix and lower right 2 by 2 submatrix of J −1 are K −1 , L −1 , respectively. 7Moreover, we use I ∆ s 1 s 2 to denote the term in I −1 with the same location as I s 1 s 2 in I.

Appendix B
In this appendix, we provide detailed derivations for all of the LM test statistics.7 For computing the inverse of a partitioned symmetric matrix, if Λ = Λ 11 Λ 12 Λ 21 Λ 22 , then

B.1. Derivation of LM a
The restricted MLE under H a 0 is essentially the OLS estimator, i.e., β a = (X X) −1 X y, σ 2 v,a = ( a a )/(N T ), where a = y − y a , y a = X β a .The score vector under H a 0 and evaluated at the restricted MLE is After straightforward calculation, the information matrix under H a 0 and evaluated at the restricted MLE is , where ν a = [ y a (I T ⊗ (W W )) y a ]/ σ 2 v,a .In this case, , where ω a = [ y a (I T ⊗ W )(I N T − X(X X) −1 X )(I T ⊗ W ) y a ]/ σ 2 v,a .The first term of (L a ) −1 is easily calculated to be 2( σ 2 v,a ) 2 /[N T (T − 1)].Also, we have Finally, the joint LM test statistic is given by

B.2. Derivation of LM c
The score vector under H c 0 and evaluated at the restricted MLE is , and β c , A c are the restricted MLEs of β, A under H c 0 , respectively.After a little calculation, the information matrix under H c 0 and evaluated at the restricted MLE is , where θ 1,c , θ 3,c are θ 1 , θ 3 evaluated under H c 0 , respectively.Making use of the block diagonal structure of I c and straightforward but tedious calculation gives that I ∆ ).Finally, the LM test statistic in this case is given by

B.3. Derivation of LM e
The score vector under H e 0 and evaluated at the restricted MLE is ∂L(δ) ∂δ  v,e , where ω e = y e (I T ⊗ W ) A e I N T − A e X(X A e A e X) −1 X A e A e (I T ⊗ W ) y e / σ 2 v,e .After some straightforward but tedious calculation, we get that the term Finally, the LM test statistic in this case is given by µ ,e .

B.4. Derivation of LM f
The restricted MLE under H f 0 is essentially the OLS estimator.The score vector under H f 0 and evaluated at the restricted MLE is After a little calculation, the information matrix under H f 0 and evaluated at the restricted MLE is In this case, it is very easy to calculate that Thus the LM test statistic in this case is given by

B.5. Derivation of LM g
The score vector under H g 0 and evaluated at the restricted MLE is where z ρ,g = g Ω −1 g (I T ⊗ M ) g , z λ,g = g Ω −1 g (I T ⊗ W )y, g = y − X β g , and β g , Ω −1 g are restricted MLEs of β, Ω −1 under H g 0 , respectively.After a little calculation, the information matrix under H g 0 and evaluated at the restricted MLE is , where ν g = y g (I T ⊗ W ) Ω −1 g (I T ⊗ W ) y g , y g = X β g , and σ 2 µ,g , σ 2 v,g are restricted MLEs of σ 2 µ , σ 2 v under H g 0 , respectively.In this case, Finally, the LM test statistic in this case is given by

B.6. Derivation of LM h
The restricted MLE under H h 0 is essentially the OLS estimator.The score vector under H h 0 and evaluated at the restricted MLE is The information matrix under H h 0 and evaluated at the restricted MLE is simply In this case, we simply have I ∆ ρρ,h = 1 T b 1 , and thus the LM test statistic is given by To derive LM * h , we make use of the Bera and Yoon (1993) Principle that LM ψφ = LM φ + LM * ψ , where LM ψφ denotes the joint LM test for ψ, φ, LM φ denotes the marginal LM test for φ, while LM * ψ denotes the robust LM test for ψ.Thus it can be easily deduced that

B.7. Derivation of LM i
The score vector under H i 0 and evaluated at the restricted MLE is ,i , ϑ 3,i are ϑ 1 , ϑ 2 , ϑ 3 evaluated at the restricted MLE under H i 0 , respectively.Straightforward but tedious calculation gives that , Finally, the LM test statistic in this case is given by LM i = ξ i z 2 ρ,i .

B.8. Derivation of LM j
The score vector under H j 0 and evaluated at the restricted MLE is ∂L(δ) ∂δ | j = 0 z ρ,j 0 0 , where z ρ,j = j Ω −1 j (I T ⊗ M ) j , j = y −X β j , and β j , Ω −1 j are restricted MLEs of β, Ω −1 under H j 0 , respectively.The information matrix under H j 0 and evaluated at the restricted MLE is .
Thus the LM test statistic in this case is trivially given by To derive LM * j , we again make use of the Bera and Yoon (1993) [19] Principle and it can be easily deduced that , where , Next, we need to calculate the (1, 1)th element of (K k ) −1 .Straightforward calculation yields , where , and Then the (1, 1)th element of (K k ) −1 can be easily calculated as Finally, the LM test statistic in this case is given by

B.10. Derivation of LM l
The restricted MLE under H l 0 is essentially the OLS estimator.The score vector under H l 0 and evaluated at the restricted MLE is ∂L(δ) ∂δ | l = 0 z λ,a 0 .
The information matrix under H l 0 and evaluated at the restricted MLE is Straightforward calculation gives that I ∆ λλ,l = 1/(T b 3 + ω a ), thus the LM test statistic corresponding to H l 0 is given by LM l = 1 T b 3 + ω a z 2 λ,a .
To derive LM * l , we again make use of the Bera and Yoon (1993) [19] Principle and it can be easily deduced that   .

and σ 2 v
are restricted MLEs of A, B, Ω, β, and σ 2 v under the null hypotheses, respectively.Next, define ν = y

Figure 1 .
Figure 1.Average Consumption of Cigarettes (in packs) per Capita per Year by States, 1963-1992.

a − b 2 b 1 z ρ,a 2 .B. 11 .
Derivation of LM mThe score vector under H m 0 and evaluated at the restricted MLE is∂L(δ) ∂δ | m = 0 0 z λ,m 0 , where z λ,m = 1 σ 2 v,m m A m A m (I T ⊗ W ) y m , σ 2 v,m = m A m A m m /(N T ), m = y − y m , y m = X β m ,and β m , A m are restricted MLEs of β, A under H m 0 , respectively.The information matrix under H m 0 and evaluated at the restricted MLE isI m = ν m = y m (I T ⊗ W ) A m A m (I T ⊗ W ) y m / σ 2 v,m ,and θ 1,m , θ 2,m , θ 3,m , θ 4,m are θ 1 , θ 2 , θ 3 , θ 4 evaluated at the restricted MLE under H m 0 , respectively.Let I m = I 11,m I 12,m I 21,m I 22,m , where I 11,m = X A m A m X σ 2 v,m B.13. Derivation of LM o The score vector under H o 0 and evaluated at the restricted MLE is ∂L(δ) ∂δ | o = 0 z λ,o 0 0 0 , where z λ,o = o A o Ω −1 o A o (I T ⊗ W )y, o = y −X β o , and β o , A o , Ω −1 o are restricted MLEs of β, A, Ω −1 under H o 0 , respectively.The information matrix under H o 0 and evaluated at the restricted MLE is

Table 5 .
FoR of LM Tests for the Spatial Error Correlation, Sample Size: (49, 7).

Table 6 .
FoR of LM Tests for the Spatial Error Correlation, Sample Size: (100, 10).

Table 7 .
FoR of LM Tests for the Spatial Lag Dependence, Sample Size: (49, 7).

Table 8 .
FoR of LM Tests for the Spatial Lag Dependence, Sample Size: (100, 10).

Table 10 .
Estimation of the Cigarette Demand Function.
e z σ 2 µ ,e 0 , where z σ 2 µ ,e = [ e A e ( JT ⊗ I N ) A e e ]/ σ 2 v,e − N, σ 2 v,e = ( e A e A e e )/(N T ), e = B e y − X β e , and β e , A e , B e are restricted MLEs of β, A, B under H e 0 , respectively.After a little calculation, the information matrix under H e 0 and evaluated at the restricted MLE is and β i , B i are restricted MLEs of β, B under H i 0 , respectively.The information matrix under H i 0 and evaluated at the restricted MLE is 2 v,k are restricted MLEs of σ 2 µ , σ 2 v under H k 0 , and ϑ 1,k , ϑ 2,k , ϑ 3,k are ϑ 1 , ϑ 2 , ϑ 3 evaluated at the restricted MLE under H k 0 , respectively.Straightforward calculation gives