Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Convert Geoda .GWT to stata format
From
[email protected]
To
[email protected]
Subject
st: Convert Geoda .GWT to stata format
Date
Fri, 28 Oct 2011 10:17:35 -0500
Adiwan Fahlan <[email protected]> asks
> Could anyone help me to convert from Geoda's .GWT spatial weight matrix to a
> Stata file?
Below I describe the steps needed to accomplish this task in Stata.
Before we begin, if Adiwan does not have the user-written -spmat- command,
Adiwan should intall it by typing in Stata
. ssc install sppack
-sppack- contains three Stata commands, -spmat-, -spreg-, and -spivreg-.
-spmat- is used for creating and managing spatial-weighting matrix objects
(spmat objects) while -spreg- and -spivreg- are used to fit
spatial-autoregressive models.
Assume Adiwan's file is named 'myfile.GWT'. First, we use -spmat import- to
read the GeoDa file
. spmat import myobj using myfile.GWT, geoda
-spmat import- created an spmat object named 'myobj' that contains the
spatial-weighting matrix constructed from the information contained in the
GeoDa file.
If Adiwan wants to use this spatial-weighting matrix to fit a
spatial-autoregressive model, there is no need to save the matrix to a Stata
file. Instead Adiwan can use the spmat object 'myobj' with -spreg- or
-spivreg-.
If Adiwan still wants to store the spatial-weighting matrix to a Stata file, the
next step is to extract the spatial-weighting matrix from the spmat object and
store it as a regular Mata matrix, I call it 'W'
. spmat getmatrix myobj W
The last step is to store that matrix as a Stata dataset. In the example below,
the variables in the dataset will be named x1, x2, x3, ...
. getmata (x*)=W
Finally, since spatial-weighting matrices consume a lot of memory, I would make
sure to clear 'W' and 'myobj' from memory
. spmat drop myobj
. mata mata drop W
--Rafal
[email protected]
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/