Hello,
I have a spatial dataset with about 23,000 observations and I am trying to use the new spmatrix command in Stata 15 MP to create an inverse distance weighting matrix for use in spatial regressions. The following command has been running for over a day:
I was very surprised by this because, using this exact same dataset, the user-written command spmat idistance has taken just 204 seconds in Stata 14 MP to make a matrix. The code is as follows.
My questions are:
1. Is there anything I can do to improve the speed of the spmatrix create command? Furthermore, can anyone clarify why spmatrix create takes so much longer than spmat? Is it something about how the matrix is being saved? Or is it the distance formula that is being used? If something very computationally intensive is going on (vincenty ellipsoid, etc.), I would love to have the option to use simple haversine distances instead so that things run faster.
2. If there is no way to make spmatrix create faster, I was hoping to be able to save the matrix that I produced with spmat and import it using the spmatrix command. After running the spmat command above, I saved the matrix, then tried to import it using spmatrix.
I received the following error:
incorrect number of columns in row 1 of weighting matrix
error reading file Output Data/pirate_mat.txt
I also tried the same thing again, saving the spmat matrix with no ids in case the id column was screwing things up.
I got the same error using this method.
I was surprised to see the "incorrect number of columns" because this matrix definitionally has exactly as many columns as there are observations in the dataset (which I confirmed using spmat summarize). Can anyone explain how to resolve this error? I was thinking it might have something to do with the fact that spmat export saves a space-delimited file-- but it appears as though spmatrix export also creates a space-delimited file which spmatrix import can read. Is there a different way to export the spmat matrix that can be read by spmatrix import?
I was really hoping to use the new spxtregress and (please correct me if I'm wrong) I don't think I can do that unless I use spmatrix to declare the weights, so any advice would be greatly appreciated. I am using Stata 15 MP. Thanks so much for your help.
Best,
Brina
I have a spatial dataset with about 23,000 observations and I am trying to use the new spmatrix command in Stata 15 MP to create an inverse distance weighting matrix for use in spatial regressions. The following command has been running for over a day:
Code:
spset id, coord(cent_long cent_lat) coordsys(latlong, kilometers) spmatrix create idistance pirate_mat, vtruncate(1/1000)
Code:
spmat idistance pirate_mat cent_long cent_lat, id(id) dfunction(dhaversine) vtruncate(1/1000) replace
1. Is there anything I can do to improve the speed of the spmatrix create command? Furthermore, can anyone clarify why spmatrix create takes so much longer than spmat? Is it something about how the matrix is being saved? Or is it the distance formula that is being used? If something very computationally intensive is going on (vincenty ellipsoid, etc.), I would love to have the option to use simple haversine distances instead so that things run faster.
2. If there is no way to make spmatrix create faster, I was hoping to be able to save the matrix that I produced with spmat and import it using the spmatrix command. After running the spmat command above, I saved the matrix, then tried to import it using spmatrix.
Code:
spmat export pirate_mat using "Output Data/pirate_mat.txt", replace spmatrix import pirate_mat using "Output Data/pirate_mat.txt", replace
incorrect number of columns in row 1 of weighting matrix
error reading file Output Data/pirate_mat.txt
I also tried the same thing again, saving the spmat matrix with no ids in case the id column was screwing things up.
Code:
spmat export pirate_mat using "Output Data/pirate_mat_noid.txt", replace noid spmatrix import pirate_mat using "Output Data/pirate_mat_noid.txt", replace
I was surprised to see the "incorrect number of columns" because this matrix definitionally has exactly as many columns as there are observations in the dataset (which I confirmed using spmat summarize). Can anyone explain how to resolve this error? I was thinking it might have something to do with the fact that spmat export saves a space-delimited file-- but it appears as though spmatrix export also creates a space-delimited file which spmatrix import can read. Is there a different way to export the spmat matrix that can be read by spmatrix import?
I was really hoping to use the new spxtregress and (please correct me if I'm wrong) I don't think I can do that unless I use spmatrix to declare the weights, so any advice would be greatly appreciated. I am using Stata 15 MP. Thanks so much for your help.
Best,
Brina
Comment