Announcement

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

  • Create spatial weighting matrix for cities belonging to the same administrative area

    I am a beginner in spatial analysis. I am trying to create a spatial weighting matrix that cities belonging to the same administrative area have value one and zero otherwise. Is it possible to do it with spmat?

  • #2
    Cross-posted at https://stackoverflow.com/questions/...administrative

    Comment


    • #3
      Solving your problem would depend completely on the structure and coding of your data. If you post a sample of your data using -dataex- as described in the StataList FAQ, your chance of receiving a helpful response would improve considerably.

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Sorry, I was not aware of the rule and will delete the post at Stack Overflow. After several trials, I think it's probably the easiest to prepare the matrix in excel with its transpose function.

        Comment


        • #5
          The OP apparently has a satisfactory solution for their purposes, but to help people with a similar problem who might encounter this thread in the future, I'd note that solving this in Stata would likely be easy, i.e., a few lines of code. For example, transposing matrices in Stata (data sets, Stata matrices, or Mata matrices) is trivial, documentation about which can be found via -help transpose-.

          Comment


          • #6
            It's not a rule that you can't cross-post. There is just a request that you tell us about cross-posting.

            Being new here is precisely why you should read the FAQ Advice, as prompted generally and as recommended by Mike Lacy. See https://www.statalist.org/forums/help

            Comment


            • #7
              Originally posted by Nick Cox View Post
              It's not a rule that you can't cross-post. There is just a request that you tell us about cross-posting.

              Being new here is precisely why you should read the FAQ Advice, as prompted generally and as recommended by Mike Lacy. See https://www.statalist.org/forums/help
              Thanks for the link!

              Comment


              • #8
                Originally posted by Mike Lacy View Post
                Solving your problem would depend completely on the structure and coding of your data. If you post a sample of your data using -dataex- as described in the StataList FAQ, your chance of receiving a helpful response would improve considerably.
                Hello, Mike, this is a matrix showing to which province each city belongs:


                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input float(city prov1 prov2 prov3)
                1 1 0 0
                2 1 0 0
                3 1 0 0
                4 0 1 0
                5 0 1 0
                6 0 1 0
                7 0 1 0
                8 0 0 1
                9 0 0 1
                end
                What I want to create is the following:


                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input float(city city1 city2 city3 city4 city5 city6 city7 city8 city9)
                1 1 1 1 0 0 0 0 0 0
                2 1 1 1 0 0 0 0 0 0
                3 1 1 1 0 0 0 0 0 0
                4 0 0 0 1 1 1 1 0 0
                5 0 0 0 1 1 1 1 0 0
                6 0 0 0 1 1 1 1 0 0
                7 0 0 0 1 1 1 1 0 0
                8 0 0 0 0 0 0 0 1 1
                9 0 0 0 0 0 0 0 1 1
                end
                A city-by-city matrix, where cities belonging to the same provinces have value 1. I think what I need to do is transpose by row. Is there a good way to accomplish this task in Stata?

                Comment

                Working...
                X