Announcement

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

  • Mina Wu
    started a topic transforming dta format into matrix format

    transforming dta format into matrix format

    Hi

    I have 33x33 symmetric matrix in txt format, which I import into Stata 15 (w.dta, henceforth). I would like to use this matrix for spatial econometric analysis.
    However, Stata does not recognize this dataset as matrix.
    What do I need to do to convert it to a matrix format, which I can use in spatial econometric modelling?

    Thank you!

  • Sebastian Kripfganz
    replied
    Originally posted by Maximilian Kotz View Post
    "spmat summarize W")
    "weighting matrix w not found"
    This indicates that you created the spmat weight matrix object as upper-case W but tried to call spxtregress with lower-case w. Names in Stata are case sensitive.

    Leave a comment:


  • Maximilian Kotz
    replied
    Hi Mina! Did you ever find a way to get around this problem?

    I am trying to import a spatial weighting matrix from a txt file with "spmat import W using Wmatrix.txt", and although the matrix is clearly recognised (since it produces output with "spmat summarize W"), I also receive the error "weighting matrix w not found" when trying to run spxtregress commands.

    Leave a comment:


  • John Mullahy
    replied
    Mina: I'm not very familiar with -spxtregress- but on quick inspection it looks like you might need to use -spmatrix create- instead of -mkmat-.

    Leave a comment:


  • Mina Wu
    replied
    wbuchanan and John Mullahy Thank you so much for the answer!
    I have scarce knowledge of Mata.. My matrix is only 33x33, so that should work directly in STATA. It is a sparse symmetric matrix, whose row-value sum to 1. Its row start with v1..v2, while its values are 0 and <1. Basically, I converted the dataset to matrix using the help file, as suggested by John Mullahy

    help mkmat
    Which allows to convert variables (33, with names v1-v33) into matrix w. What i do is the following:

    mkmat v1-v33, matrix(w)
    I receive no error message after this command. Basically, after this I import my data (spatial panel dataset) and apply spxtregress command (spatial pane). However, w matrix (saved above) is not recognized at all. In fact, I get a message

    weighting matrix w not found
    How can I store matrix w for alter use, as recognized by wbuchanan ?

    Thank you very much.

    Leave a comment:


  • wbuchanan
    replied
    Mina Wu
    You could read the file and parse it into a matrix all in Mata, but it is difficult to provide any more useful information without knowing more about the file (e.g., how are the data delimited, etc...). In the worst case scenario, you could probably define the matrix directly in a .do file or something similar then could create a file that saves/stores the Mata matrix for later use.

    Leave a comment:


  • John Mullahy
    replied
    Mina: If you want to use the matrix in subsequent Stata computations, then check out the -mkmat- command
    Code:
    help mkmat
    If instead you want to do the analysis in Mata, then check out -st_data-
    Code:
    help mf_st_data
    Either way it is straightforward to get your data into a matrix that can be used for subsequent analysis.

    Leave a comment:

Working...
X