Announcement

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

  • #16
    Follow up to #15: the format of the shape information in the excel file is called WKT ("Well-known text representation of geometry", see https://en.wikipedia.org/wiki/Well-k...on_of_geometry), so the program I provided should probably better be called wkt2dta or so. Currently the program only supports "MultiPolygon", but it could easily be extended to support points and lines as well. I'll think about generalizing the program and integrating it into the geoframe system.

    Comment


    • #17
      Dear Prof. Ben Jann,

      Thank you so much for the kind help in #15.

      Comment


      • #18
        Hi everyone,

        I need your help in -geoplot-. My version of stata is 17.
        Here are my questions, please:
        1. First, I have some unmatched zipcodes from my "using" dataset, and I would like to match them to neighbouring zipcodes, if and only if the unmatched zipcodes contain more than 20 (>=20) households.
        2. Second, in the map that I will show you afterwards, I would like to have the Canary Islands near to the Iberian Peninsula, but I don't know how.
        3. Third, I would like to paint the white areas in my map into gray ones, since we do not have data on them.
        Here is a dataex sorted of my unmatched zipcodes (from the using dataset):


        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input str5 sp_zipcode_str long tag_zip_house_mun byte _merge
        "08092"   1 2
        "08190" 264 2
        "08200"   2 2
        "08220"   2 2
        "08240"  15 2
        "08400"  51 2
        "10683"   1 2
        "13197"   1 2
        "15192"   6 2
        "15407"   1 2
        "15708"   1 2
        "17092"   1 2
        "17254"   1 2
        "18849"   1 2
        "18857"   1 2
        "19019"   1 2
        "21102"   1 2
        "21458"   1 2
        "21646"   1 2
        "24400"  22 2
        "26000"   1 2
        end
        label values _merge _merge
        label def _merge 2 "Using only (2)", modify
        tag_zip_house_mun corresponds to the number of observations in each zipcode.
        Here is a dataex with the matched zipcodes:


        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input str5 sp_zipcode_str byte _merge
        "08100" 3
        "08105" 3
        "08106" 3
        "08107" 3
        "08110" 3
        "08120" 3
        "08130" 3
        "08140" 3
        "08148" 3
        "08150" 3
        "08160" 3
        "08170" 3
        "08172" 3
        "08173" 3
        "08174" 3
        "08178" 3
        "08180" 3
        "08181" 3
        "08182" 3
        "08183" 3
        "08184" 3
        "08185" 3
        "08186" 3
        "08187" 3
        "08188" 3
        "08189" 3
        "08191" 3
        end
        label values _merge _merge
        label def _merge 3 "Matched (3)", modify
        If needed, I can share the entire merge == 2 & merge == 3 data.

        Finally, here is my code:

        Code:
        cd ${stata}/1_export_contratos/data
        
        *** by zipcodes municipalities
        use "export_contratos_original_date_cleaned.dta", clear
        
        duplicates drop id, force
        
        tostring sp_zipcode, gen(my_newzip) format(%07.0f)
        gen sp_zipcode_str = substr(my_newzip,3, 2)
        replace sp_zipcode_str = substr(my_newzip,3, 5)
        sort sp_zipcode_twodigits
        drop my_newzip
        
        order id id_encod sp_zipcode sp_zipcode_str
        
        egen tag_zip_house_mun = tag(id sp_zipcode_str) if !missing(powers_tariff2_less_15000w)
        egen obs_by_zipcode_house_mun = total(tag_zip_house_mun), by(sp_zipcode_str)
        
        
        
        sort sp_zipcode
        collapse (count) tag_zip_house_mun, by(sp_zipcode_str)
        
        tempfile house_info_munic
        save `house_info_munic', replace
        
        save "${stata}/1_export_contratos/data/mapping_data/house_info_collapse_municip.dta", replace
        
        
        *******Map at the municipal level
        clear all
        cd ${export_geopath}
        
        use "Spain_municip.dta", clear
        gen sp_zipcode_str = COD_POSTAL
        sort sp_zipcode_str
        save Spain_municip.dta, replace
        
        
        
        *1)Creation of Provincias limits
        geoframe create Spain_provinc, replace
        geoframe describe Spain_provinc    
        
        *2)Creation of Municipal limits
        geoframe create Spain_municip, replace
        geoframe describe Spain_municip
        
        *3)Some data cleaning, if needed
        geoframe describe Spain_municip_shp
        
        duplicates drop sp_zipcode_str, force
        
        merge 1:1 sp_zipcode_str using `house_info_munic', keep(match master) nogenerate
        save Spain_municip, replace
        
        
        *4)Creation of CCAA limits
        geoframe create Spain_auton
        geoframe describe Spain_auton_shp
        
        *5)Creation of collapse connexion
        geoframe create "${stata}/1_export_contratos/data/mapping_data/house_info_collapse_municip", replace
        geoframe describe house_info_collapse_municip
        
        
        geoplot ///
            (area Spain_municip tag_zip_house_mun, color(reds)) ///
            (line Spain_auton, lwidth(0.05)) ///
            , tight legend(pos(9))

        Please find below and enclosed the map that I mentioned above.
        Could you please help me with that?

        Your help is really appreciated!

        Best,
        Michael
        Click image for larger version

Name:	Spain_Graph.png
Views:	1
Size:	152.0 KB
ID:	1736113

        Last edited by Michael Duarte Goncalves; 05 Dec 2023, 03:02.

        Comment


        • #19
          1. First, I have some unmatched zipcodes from my "using" dataset, and I would like to match them to neighbouring zipcodes, if and only if the unmatched zipcodes contain more than 20 (>=20) households.
          Not really clear to me, what you want to do here.

          2. Second, in the map that I will show you afterwards, I would like to have the Canary Islands near to the Iberian Peninsula, but I don't know how.
          A common way to do this would be to modify the coordinates of the shape items belonging to the Canary Islands before plotting. However, you could also (mis)use the zoom() option in geoplot. This requires that you place the Canary Islands in a separate layer.

          3. Third, I would like to paint the white areas in my map into gray ones, since we do not have data on them.
          It is unclear to me why you have the white areas in the map, since there are also gray areas for municipalities without data. It seems that for the white areas there is no shape information in the municipalities data. Make sure that your data contains shape information on all municipalities.

          Comment

          Working...
          X