Announcement

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

  • Merging clima data and Subnational level Population Weighted Density (PWD)

    Dear Statalist,

    I am working on my research project that involves relating climate and Subnational level Population Weighted Density (PWD) data for the year 2000. I have obtained the following files

    (1) Weather files:
    http://climate.geog.udel.edu/~climat...oad.html#P2017
    From here I get, precip_2017.tar.gz (284MB) --> precip_2017 --> precip.2000

    (2) Subnational level Population Weighted Density (PWD) files:
    https://hub.worldpop.org/geodata/summary?id=50576
    From here I get, PWD_1km_sub_national_SHP.zip (2.20 MB) --> PWD_1km_sub_national_SHP --> PWD_2000_sub_national_1km.shp

    (3) As the PWD files are produced using GADM (version 3.6) level 1 administrative unit boundaries, these files have been obtained from:
    https://data.biogeo.ucdavis.edu/data...levels_shp.zip
    From here I get, gadm36_levels_shp.zip --> gadm36_levels_shp --> gadm36_0.shp (shapefile of country boundaries), gadm36_1.shp (shapefile using in PWD)

    To relate the ID of the points of PWD_2000_sub_national_1km.shp with the spatial data of precip.2000, I have done the following

    Code:
    ** The shapefile for the points
    * To install: ssc install shp2dta
    shp2dta using "PWD_1km_sub_national_SHP/PWD_2000_sub_national_1km.shp", /// 
        data("PWD_2000_points_data.dta") coor("PWD_2000_points_coor.dta") replace
    
    ** Import weather data one time period
    infile lon lat p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p2000 /// 
        using "precip_2017/precip.2000", clear
    
    ** Reduce to grid coordinates and data
    keep lat lon p2000
    order lat lon p2000
    isid lat lon, sort
    
    ** Match grid coordinates to points of countries
    * To install: ssc install geoinpoly
    geoinpoly lat lon using "PWD_2000_points_coor.dta"
    When executing the Code, it tells me "a polygon must start with missing coordinates" How can I make the ID of PWD appear in precip.2000?

    I'm hoping someone who has experience working with this kind of data and might have a solution.

    Thank you!
    Pedro
    Last edited by Pedro Troncoso; 11 Aug 2022, 09:37.

  • #2
    I'm not at all familar with any of this data, but the issue appears to be PWD_2000_sub_national_1km.shp, which is not a polygon file. You might have to map those points to polygon file beforehand. Example --

    Code:
    clear all
    
    // Get files
    copy "https://data.biogeo.ucdavis.edu/data/gadm3.6/gadm36_levels_shp.zip" "gadm36_levels_shp.zip"
    unzipfile gadm36_levels_shp.zip
    
    
    copy "https://data.worldpop.org/GIS/Population_Weighted_Density/Unconstrained_Subnational/1km/PWD_1km_sub_national_SHP.zip" "PWD_1km_sub_national_SHP.zip"
    unzipfile PWD_1km_sub_national_SHP.zip
    
          
    copy "http://climate.geog.udel.edu/~climate/html_pages/Global2017/precip_2017.tar.gz" "precip_2017.tar.gz"
    shell gunzip precip_2017.tar.gz  
    shell tar -xf precip_2017.tar
    
    
    shp2dta using "PWD_1km_sub_national_SHP/PWD_2000_sub_national_1km.shp", ///
            data("PWD_2000_points_data.dta") coor("PWD_2000_points_coor.dta") replace
    
    shp2dta using "gadm36_1", ///
            data("points_data.dta") coor("coor.dta") replace
    
    
    // This is the "polygon" (coordinates) file
    use PWD_2000_points_coor, clear
    
    spmap using "coor.dta" , id(_ID) ocolor(black ..) osize(0.05 ..)  point(xcoord(_X) ycoord(_Y)  data(PWD_2000_points_coor)  fcolor(blue%50 ..) size(vsmall))
    
    exit
    Click image for larger version

Name:	image.png
Views:	1
Size:	636.0 KB
ID:	1677441

    Last edited by Justin Niakamal; 11 Aug 2022, 19:29.

    Comment


    • #3
      Hi @Justin Niakamal

      Thank you very much for your Stylized Example. I followed your Code indicated in #2 and I get the same results! However, it doesn't solve the problem I have...

      The problem I have is that I need to associate the 3496 _IDs of the "PWD_2000_points_coor.dta" file with the precip.2000 file (from precip_2017) but doing this directly following the Code indicated in #1 returns the specified error.

      Using shp2dta I can associate the 3610 _IDs from the "coor.dta" file coming from gadm36_1.shp (used to generate the PWD metrics) with the precip.2000 file, but then I don't know what else to do to leave only the 3496 _ID of the file "PWD_2000_points_coor.dta" to later merge its metrics with " PWD_2000_points_data.dta".

      Comment


      • #4
        Hi Pedro Troncoso, yes it won't solve your problem. The code in #2 is to highlight the issue with the PWD_2000_points_coor.dta file. The .shp file isn't a polygon file, so your code in #1 won't work because
        Code:
        geoinpoly lat lon using "PWD_2000_points_coor.dta"
        PWD_2000_points_coor.dta needs to be a polygon file, but as shown in my code it appears to just be the centroid of some polygon (as mentioned before, I'm not at all familiar with this data).

        Comment


        • #5
          Hi Justin Niakamal, thank you very much for your concern and for answering me. I will keep searching to solve my problem...

          Comment

          Working...
          X