Announcement

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

  • Drawing country maps on Stata

    Hello Stata community;

    I would love to get some help and suggestions on this topic, because I know that it is possible to draw maps of countries on Stata, but I just don't know how.
    I'm working on Tunisia, a small North-African country with 24 states (or governorates) which is near Libya and Algeria.
    My goal is to draw a map of the country on Stata with the names on the states shown on it (like, for each state, I want its name to be written on it or a bit above it, yet without crowding too much the graph, for aesthetic reasons).
    Some people suggested that I could downloand the coordinates of a country (what's called a "shapefile" I guess from some websites, yet I don't know that much about this option)

    Is there an easy, standard way to draw a map graph on Stata? Or are there multiple ways to choose from? What's the best most straight-forward way to do so?

    Thanks for the help.

  • #2
    I ain't at home, but you'll wanna use this shapefile to start with. And look up the grmap command, it'll take care of all your mapping needs.

    Comment


    • #3
      Here is a basic map. The shapefile is from https://geodata.lib.utexas.edu/catal...rd-nm977mv7656

      You might need to adjust where the labels are plotted (the -label(xcoord(_CX) ycoord(_CY) ... )-) or abbreviate the names to avoid crowding.


      Code:
      copy https://stacks.stanford.edu/file/druid:nm977mv7656/data.zip  tunisia.zip, replace
      
      unzipfile tunisia.zip, replace
      fs *.shp
      spshape2dta    `=r(files)', saving(tunisia) replace
      
      use tunisia,clear
      spmap using tunisia_shp, id(_ID) label(xcoord(_CX) ycoord(_CY) label(NAME_1) length(22) size(*.85))
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	73.3 KB
ID:	1683204

      Comment


      • #4
        Hello Scott Merryman & Jared Greathouse;

        Thanks for the tips, they were really helpful.

        Scott Merryman Is it possible, please, to have that same map just with the names of the governorates in Arabic? Is there an "ssc install" command that I should use in order to make Stata read Arabic language already?

        ​​​​​​​ Thanks again for the help.

        Comment


        • #5
          Nah you'll need to do the Arabic yourself.

          Comment


          • #6
            Aziz Essouaied The language depends on what is in the shapefile database. This website appears to have the names in both English and Arabic : https://data.humdata.org/dataset/cod-ab-tun

            Using the same process as above returns the map below, which I hope the labels are rendered in Arabic correctly.


            Click image for larger version

Name:	Graph2.png
Views:	1
Size:	108.3 KB
ID:	1683293

            Comment


            • #7
              Scott Merryman Thanks again for the help
              I've tried that code, and I'm getting this error message:
              spmap using tunisia_shp, id(_ID) label(xcoord(_CX) ycoord(_CY) label(NAME_1) length(22) size(*.85))
              variable _ID not found
              (error in option id())
              r(111);
              I guess it's because the variable ID is not unique, so I wanna ask if there's a way to fix that or to mention that it is a duplicate variable.

              Comment


              • #8

                This is the complete code from start to finish:

                Code:
                clear*
                cd C:\Users\scott\Desktop\tmp2
                
                //download shapefile
                copy https://data.humdata.org/dataset/e47eda48-8f83-4858-b739-dbffb8a50c47/resource/b2fccd7a-55f0-4d69-9eb7-ab47367fbfe6/download/tun_adm_2022_shp.zip  tun_adm_2022_shp.zip, replace
                
                
                //Unzip shapefile folder
                unzipfile tun_adm_2022_shp.zip, replace
                
                //Change directory to shapefile folder
                cd ./tun_adm_2022_shp
                
                //Convert shapefile to stata data set
                spshape2dta  tun_admbnda_adm2_2022, replace
                
                use tun_admbnda_adm2_2022.dta
                spmap using  tun_admbnda_adm2_2022_shp, id(_ID) /// 
                    label(xcoord(_CX) ycoord(_CY) label(ADM2_AR) length(19) size(*1.5))

                Comment

                Working...
                X