Announcement

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

  • Help with expanding a dataset and merging with a new dataset?

    Hi folks! I have a list of J respondents, each with an identifier and a zip code. I also have a separate dataset made up of N different sites, and their lat/long. I want to expand each respondent observation by the number of sites, and then append the site dataset onto the respondent dataset J times, so that each respondent has one observation for each site.


    For context, here is the structure of my respondent data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte personid long zipcode
    1 60606
    2 66206
    3 60602
    4 48912
    5 43877
    6 24595
    end
    Here is my site data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte siteID float(lat lon)
    1 42.34538 -82.9744
    2 42.57205 -82.7986
    3 42.67822 -82.7337
    4  41.6858 -83.3781
    end

    And here Is what I'd like the end result to look like:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str8 personID str7 zipcode str6 siteID str8(lat lon)  
    "1"        "60606"   "1"      "42.34538" "-82.9744"
    "1"        "60606"   "2"      "42.57205" "-82.7986"
    "1"        "60606"   "3"      "42.67822" "-82.7337"
    "1"        "60606"   "4"      "41.6858"  "-83.3781"
    "2"        "66206"   "1"      "42.34538" "-82.9744"
    "2"        "66206"   "2"      "42.57205" "-82.7986"
    "2"        "66206"   "3"      "42.67822" "-82.7337"
    "2"        "66206"   "4"      "41.6858"  "-83.3781"
    "3"        "60602"   "1"      "42.34538" "-82.9744"
    "3"        "60602"   "2"      "42.57205" "-82.7986"
    "3"        "60602"   "3"      "42.67822" "-82.7337"
    "3"        "60602"   "4"      "41.6858"  "-83.3781"
    "4"        "48912"   "1"      "42.34538" "-82.9744"
    "4"        "48912"   "2"      "42.57205" "-82.7986"
    "4"        "48912"   "3"      "42.67822" "-82.7337"
    "4"        "48912"   "4"      "41.6858"  "-83.3781"
    "5"        "43877"   "1"      "42.34538" "-82.9744"
    "5"        "43877"   "2"      "42.57205" "-82.7986"
    "5"        "43877"   "3"      "42.67822" "-82.7337"
    "5"        "43877"   "4"      "41.6858"  "-83.3781"
    "6"        "24595"   "1"      "42.34538" "-82.9744"
    "6"        "24595"   "2"      "42.57205" "-82.7986"
    "6"        "24595"   "3"      "42.67822" "-82.7337"
    "6"        "24595"   "4"      "41.6858"  "-83.3781"
    end

    Apologies for the formatting; I'm pretty new here. I've been trying to figure this out for a while, with no luck, so any help would be greatly appreciated!

  • #2
    -help cross-

    That does exactly what you want.

    Why are you apologizing for the formatting? You did it exactly right! And on your very first post! Bravo.

    Comment


    • #3
      Thank you so much Clyde! works great.

      Comment

      Working...
      X