Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spatial regression, Spatial Weights matrix using coordinates - Panel data with 11 years! Please help.

    Hello,
    I have a data set of 40 countries for 11 years from 2005 to 2015. I'm trying to create a spatial weights matrix with coordinates X and Y for each country. My data set in STATA looks like this

    USA 2005
    USA 2006
    USA 2007
    ....

    France 2005
    France 2006
    France 2007
    ....
    When I enter the coordinates for each country in the data set, do I have to repeat the same coordinates for each country in every year?
    I have tried to do that but when I run the following regression:

    global xcoord X
    global ycoord Y
    global band 100
    spatwmat, name(W) xcoord($xcoord) ycoord($ycoord) band(0 $band) standardize eigenval(E)

    Then, it shows the following error message:
    matsize too small
    You have attempted to create a matrix with too many rows or columns or attempted to fit a model with too many variables. You need to increase
    matsize; it is currently 400. Use set matsize; see help matsize.

    If you are using factor variables and included an interaction that has lots of missing cells, either increase matsize or set emptycells drop to
    reduce the required matrix size; see help set emptycells.

    If you are using factor variables, you might have accidentally treated a continuous variable as a categorical, resulting in lots of categories.
    Use the c. operator on such variables.

    So, my question is how do I create a spatial weights matrix using coordinates for panel data? How to I enter coordinates correctly for panel data? Note that in my data set, there are 40 countries so the weight matrix is 40x40. However, if I enter the coordinates as the panel data format as the above, I will have to repeat the same coordinates 11 times (for 11 years) for every country.

    What does band actual mean? is it the difference in coordinate, how to translate the band into actual distance such as miles or kilometers?


  • #2
    Hi Harry,

    I have been working with a similar spatial panel data set and can answer some of these questions, but I am not an expert and I hope others will be able to provide a more complete answer.

    First, to clarify, this command...
    Code:
    spatwmat, name(W) xcoord($xcoord) ycoord($ycoord) band(0 $band) standardize eigenval(E)
    ...does not run a regression. It simply creates the spatial weights matrix that will later be used to run a spatially weighted regression using a different command, such as -spatreg-.

    The "matsize too small" error is telling you that you need to increase the maximum allowable matrix size. I assume you are getting this error because with 40x11=440 observations in your dataset, the matrix that you are trying to create has 440 rows and 440 columns. The error message is telling you that your maximum matsize is set to 400, which is too small. The command to change the maximum matrix size is:
    Code:
    set matsize 440
    However, your intuition is correct -- you only need a 40x40 matrix because the location of countries does not chance from year to year. You can do this easily by creating the matrix using only data from one year. Unfortunately, spatwmat is a user-written command that does not take if statements, but there are easy ways around that. For example:
    Code:
    preserve
    keep if year == 2005
    spatwmat, name(W) xcoord(X) ycoord(Y) band(0 100) standardize eigenval(E)
    restore
    However, it is still good practice to store the coordinates as panel data (yes, with each coordinate repeated 11 times - think of it as a cross-sectional id variable).

    As for the band option-- I believe that spatwmat calculates the simple Euclidean distance between each coordinate, using whatever units your coordinate system is in. Note also that per the spatwmat help file, "Both the x-coordinate and the y-coordinate must be expressed in projected units, e.g., metres, kilometres, miles, or arbitrary digitizing units."

    You did not say what version of Stata you are using. If you have access to Stata 15, you can do all of this this more easily using the new -spmatrix- command which is much better equipped to handle spatial panel data. You can first declare time-series data using xtset, then declare spatial data using spset. See the manual here for details.

    I would be interested in hearing what commands others recommend for taking a cross-sectional spatial weighting matrix and using it for spatially-weighted panel regressions. However, I hope this is of use in the meantime for simply creating the matrix.

    Best,
    Brina
    Last edited by Brina Seidel; 02 Oct 2017, 13:05.

    Comment


    • #3
      Hi Brina. Thank you for your explanation. It's very helpful. I will try to do it tonight. I'm using Stata 13. This is the first time that I've tried to use spatial regression. I have tried to search my question online everywhere but I could not find an answer. Sure, I will try do it and will update the result. Also, if I increase the matsize to 440 and enter the same coordinates for 11 times for each country, does Sata understand it correctly and no problem with my regression results? I hope I will be ok doing that way. Thank much.

      Comment


      • #4
        Everything runs great after I increase the matrix size. I'm wondering is there any way or command that I can get the summary statistics of the spatial independent variable (the variable that has spatial weights). Thanks.

        Comment

        Working...
        X