Announcement

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

  • Joining spatial files - geoinploy

    Dear STATA listers,

    I have a bunch of geo coordinates across the US. I want to map these coordinates into the corresponding census tracts, that can be easily done with geoinpoly.

    I downloaded tiger tract shapefiles from US census. The shapefiles are available state-wise, I first covert the shapefiles into “coor” and “data” files:

    shp2dta using "state_tract_x.shp", genid(_ID) data("data_01.dta") coor("coor_01.dta") replace

    After the conversion, I appended state-tract files for the whole country. However, when I use geoinpoly it tells me that my _ID is not unique in data_US.dta file. I believe this might be due to intersecting polygons.

    What should I do?

    If I try to merge state-tract shapefiles using mergepoly, I am not sure how this can be resolved. I tried to follow the following post:

    https://www.statalist.org/forums/for...files-in-stata

    But file size might become an issue.

    I want both statistical analysis and plotting data for the full country.

    Any suggestion/guidance would be helpful.

    Thank you.

    Lg,
    Mg

  • #2
    The created _ID starts at 1 for each state. You need to renumber the __IDs. Here is an example of the three Pacific Northwest states: Oregon, Washington, and Idaho.
    Code:
    foreach l in 16 41 53 {
            copy https://www2.census.gov/geo/tiger/TIGER2021/TRACT/tl_2021_`l'_tract.zip ., replace
            unzipfile tl_2021_`l'_tract.zip, replace
            spshape2dta tl_2021_`l'_tract, replace
    }
    
    use tl_2021_16_tract
    sum _ID
    local maxid = r(max)
    use tl_2021_41_tract
    replace _ID = _ID + `maxid'
    save, replace
    use tl_2021_41_tract_shp
    replace _ID = _ID + `maxid'
    save, replace
    sum _ID
    local maxid = r(mean)
    use tl_2021_53_tract
    replace _ID = _ID + `maxid'
    save, replace
    use tl_2021_53_tract_shp
    replace _ID = _ID + `maxid'
    save, replace
    
    use tl_2021_16_tract,clear
    append using tl_2021_41_tract tl_2021_53_tract
    sort _ID
    save pnw_tract,replace
    
    use tl_2021_16_tract_shp
    append using tl_2021_41_tract_shp tl_2021_53_tract_shp
    sort _ID shape_order
    save pnw_tract_shp,replace
    use pnw_tract
    spmap using pnw_tract_shp , id(_ID) osize(vthin) ocolor(gs8) title(Pacific Northwest Census Tracts)
    Click image for larger version

Name:	Graph3.png
Views:	1
Size:	185.8 KB
ID:	1636368

    Comment


    • #3
      Dear Scott,

      Sorry a bit late in seeing the post.

      Thank you very much. It is really helpful.

      I followed an alternative way, I split my master file by state and then did the mapping. With a smile loop, that did not take long.

      Again, many thanks!

      Best wishes,
      Manish

      Comment

      Working...
      X