Announcement

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

  • Drawing Tunisia's maps by governorats and their annual temperature, with 5 solar energy projects as points on this map

    Hello dear Stata users;

    I'm using Stata version 13.1 for this work. I'm current working on 5 projects of production of solar energy in Tunisia. As you know, these projects should be constructed in hot regions and governorats (as they already are). My goal is to draw the map of Tunisia with the 24 governorats (and their names) and their annual temperature of 2025 (I could have a temperature scale as the key of this map), and then to put those 5 projects on it as points with their names. I have this data at hand for the right moment:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str11 gouvernorat float tempraturemoyenneannuellec
    "Tunis"       20.5
    "Ariana"        20
    "Ben Arous"     21
    "La Manouba"    20
    "Nabeul"      19.5
    "Bizerte"     19.5
    "Béja"        18.5
    "Jendouba"    18.5
    "Le Kef"        18
    "Siliana"     18.5
    "Kairouan"    21.5
    "Sousse"      21.5
    "Monastir"    21.5
    "Mahdia"      21.5
    "Sfax"          22
    "Gabès"       22.5
    "Médenine"    22.5
    "Tataouine"     23
    "Gafsa"         22
    "Tozeur"        23
    "Kébili"        23
    "Sidi Bouzid" 21.5
    "Kasserine"   20.5
    "Zaghouan"      19
    end
    And,

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str42 nomduprojet float(latitude longitude)
    "Khobna – Qair (Mezzouna – Sidi Bouzid)"     34.3659 9.6294
    "Mezzouna – Scatec (Mezzouna – Sidi Bouzid)" 34.5776 9.8419
    "El Ksar – Qair (Gafsa)"                      34.421  8.784
    "Sagdoud – Voltalia (Redeyef – Gafsa)"        34.382  8.155
    "Menzel El Habib – Voltalia (Gabès)"          33.525   9.65
    end
    Could anyone help please? I know how to create a blank map of Tunisia and its governorats using a Shapefile and the "spmap" command, but I don't know how to move forward after that.

    With many thanks.

  • #2
    There isn’t much variation in temperature across the country’s administrative regions, so I’m not sure how informative a temperature map is vis-à-vis the locations of the solar energy projects. I generated the following using Stata 19.5, so I cannot guarantee that you’ll be able to replicate it in Stata 13. The project locations are marked with black-filled triangles, but you can adjust this to suit your preferences.

    Code:
    copy https://data.humdata.org/dataset/e47eda48-8f83-4858-b739-dbffb8a50c47/resource/d70d07db-a11c-4b83-9ae6-2f301a06fdd4/download/tun_admin_boundaries.shp.zip tun_admin_boundaries.shp.zip, replace
    unzipfile tun_admin_boundaries.shp.zip, replace
    spshape2dta tun_admin2.shp, saving(tunisia) replace
    
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str11 gouvernorat float tempraturemoyenneannuellec
    "Tunis"       20.5
    "Ariana"        20
    "Ben Arous"     21
    "La Manouba"    20
    "Nabeul"      19.5
    "Bizerte"     19.5
    "Béja"        18.5
    "Jendouba"    18.5
    "Le Kef"        18
    "Siliana"     18.5
    "Kairouan"    21.5
    "Sousse"      21.5
    "Monastir"    21.5
    "Mahdia"      21.5
    "Sfax"          22
    "Gabès"       22.5
    "Médenine"    22.5
    "Tataouine"     23
    "Gafsa"         22
    "Tozeur"        23
    "Kébili"        23
    "Sidi Bouzid" 21.5
    "Kasserine"   20.5
    "Zaghouan"      19
    end
    rename gouvernorat adm2_name
    tempfile mydata
    save `mydata'
    
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str42 nomduprojet float(latitude longitude)
    "Khobna – Qair (Mezzouna – Sidi Bouzid)"     34.3659 9.6294
    "Mezzouna – Scatec (Mezzouna – Sidi Bouzid)" 34.5776 9.8419
    "El Ksar – Qair (Gafsa)"                      34.421  8.784
    "Sagdoud – Voltalia (Redeyef – Gafsa)"        34.382  8.155
    "Menzel El Habib – Voltalia (Gabès)"          33.525   9.65
    end
    
    tempfile mydata2
    save mydata2, replace
    
    use tunisia.dta, clear
    merge m:1 adm2_name using `mydata', keep(match) nogen
    
    spmap tempraturemoyenneannuellec using tunisia_shp.dta, id(_ID) ///
        fcolor(Reds) ocolor(black) clmethod(custom) ///
        clbreaks(18 19 20 21 22 23) ///
        legend(order(2 "18°C - 19°C" 3 "19°C - 20°C" 4 "20°C - 21°C" 5 "21°C - 22°C" 6 "22°C - 23°C")) ///
        label(data("tunisia.dta") xcoord(_CX) ycoord(_CY) ///
              label(adm2_name) size(*1.1)) ///
        point(data(mydata2.dta) xcoord(longitude) ycoord(latitude) ///
              size(*1.2) fcolor(black) ocolor(black ..) shape(T))
    Res.:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	42.3 KB
ID:	1785652

    Comment


    • #3
      Looking at the map, I notice some name mismatches. For example, in the shape file, the admin region "Sidi Bouzid" is named "Sidi Bou Zid". That's why some admin regions appear as having no data (no fill). Fix this and it will resolve itself in the map.
      Last edited by Andrew Musau; 09 Apr 2026, 08:44.

      Comment


      • #4
        Andrew Musau Thanks for the help, that's basically what I wanted to draw. Yet, if I may push the discussion event further: Yes, it is true that there's no big difference in temperatures between the 24 admin regions, yet, that is the average annual temperature. Still, the map you've drawn shows the idea: Those solar energy production sites are well-constructed in the hottest regions of the contry. If I may ask if it's possible to give another color for the least hot regions (Kebili, Sidi Bouzid, Kasserine and Mannouba), just to show them and their boarders. With many thanks!

        Comment


        • #5
          Originally posted by Aziz Essouaied View Post
          Andrew Musau If I may ask if it's possible to give another color for the least hot regions (Kebili, Sidi Bouzid, Kasserine and Mannouba), just to show them and their boarders.
          My point in #3. These are not the least hot regions. They appear so just because of the name mismatches. I fix these below:

          Code:
          copy https://data.humdata.org/dataset/e47eda48-8f83-4858-b739-dbffb8a50c47/resource/d70d07db-a11c-4b83-9ae6-2f301a06fdd4/download/tun_admin_boundaries.shp.zip tun_admin_boundaries.shp.zip, replace
          unzipfile tun_admin_boundaries.shp.zip, replace
          spshape2dta tun_admin2.shp, saving(tunisia) replace
          
          
          
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str20 gouvernorat float tempraturemoyenneannuellec
          "Tunis"       20.5
          "Ariana"        20
          "Ben Arous"     21
          "Manubah"       20
          "Nabeul"      19.5
          "Bizerte"     19.5
          "Béja"        18.5
          "Jendouba"    18.5
          "Le Kef"        18
          "Siliana"     18.5
          "Kairouan"    21.5
          "Sousse"      21.5
          "Monastir"    21.5
          "Mahdia"      21.5
          "Sfax"          22
          "Gabès"       22.5
          "Médenine"    22.5
          "Tataouine"     23
          "Gafsa"         22
          "Tozeur"        23
          "Kebili"        23
          "Sidi Bou Zid" 21.5
          "Kassérine"   20.5
          "Zaghouan"      19
          end
          rename gouvernorat adm2_name
          tempfile mydata
          save `mydata'
          
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str42 nomduprojet float(latitude longitude)
          "Khobna – Qair (Mezzouna – Sidi Bouzid)"     34.3659 9.6294
          "Mezzouna – Scatec (Mezzouna – Sidi Bouzid)" 34.5776 9.8419
          "El Ksar – Qair (Gafsa)"                      34.421  8.784
          "Sagdoud – Voltalia (Redeyef – Gafsa)"        34.382  8.155
          "Menzel El Habib – Voltalia (Gabès)"          33.525   9.65
          end
          
          tempfile mydata2
          save mydata2, replace
          
          use tunisia.dta, clear
          merge m:1 adm2_name using `mydata', keep(match) 
          
          spmap tempraturemoyenneannuellec using tunisia_shp.dta, id(_ID) ///
              fcolor(Reds) ocolor(black) clmethod(custom) ///
              clbreaks(18 19 20 21 22 23) ///
              legend(order(2 "18°C - 19°C" 3 "19°C - 20°C" 4 "20°C - 21°C" 5 "21°C - 22°C" 6 "22°C - 23°C")) ///
              label(data("tunisia.dta") xcoord(_CX) ycoord(_CY) ///
                    label(adm2_name) size(*1.1)) ///
              point(data(mydata2.dta) xcoord(longitude) ycoord(latitude) ///
                    size(*1.2) fcolor(black) ocolor(black ..) shape(T))
          Res.:

          Click image for larger version

Name:	Graph.png
Views:	1
Size:	66.4 KB
ID:	1785656

          Comment


          • #6
            Andrew Musau Thanks very much! That really helped. Yet, I did wonder if it would make the map even better to include the names of the 5 solar energy projects, but then again, that's a problems in what comes to maps. Here it's just 5 points on a map, but if it was more than that, the map would become hard to read and interpret.

            Comment


            • #7
              Originally posted by Aziz Essouaied View Post
              Andrew Musau I did wonder if it would make the map even better to include the names of the 5 solar energy projects
              Maybe not on the map. You could try extending the legend and differentiating the markers using shapes and/ or color. Here is one take:

              Code:
              copy https://data.humdata.org/dataset/e47eda48-8f83-4858-b739-dbffb8a50c47/resource/d70d07db-a11c-4b83-9ae6-2f301a06fdd4/download/tun_admin_boundaries.shp.zip tun_admin_boundaries.shp.zip, replace
              unzipfile tun_admin_boundaries.shp.zip, replace
              spshape2dta tun_admin2.shp, saving(tunisia) replace
              
              * Example generated by -dataex-. To install: ssc install dataex
              clear
              input str20 gouvernorat float tempraturemoyenneannuellec
              "Tunis"       20.5
              "Ariana"        20
              "Ben Arous"     21
              "Manubah"       20
              "Nabeul"      19.5
              "Bizerte"     19.5
              "Béja"        18.5
              "Jendouba"    18.5
              "Le Kef"        18
              "Siliana"     18.5
              "Kairouan"    21.5
              "Sousse"      21.5
              "Monastir"    21.5
              "Mahdia"      21.5
              "Sfax"          22
              "Gabès"       22.5
              "Médenine"    22.5
              "Tataouine"     23
              "Gafsa"         22
              "Tozeur"        23
              "Kebili"        23
              "Sidi Bou Zid" 21.5
              "Kassérine"   20.5
              "Zaghouan"      19
              end
              rename gouvernorat adm2_name
              tempfile mydata
              save `mydata'
              
              * Example generated by -dataex-. To install: ssc install dataex
              clear
              input str42 nomduprojet float(latitude longitude project)
              "Khobna – Qair (Mezzouna – Sidi Bouzid)"     34.3659 9.6294 1
              "Mezzouna – Scatec (Mezzouna – Sidi Bouzid)" 34.5776 9.8419 2
              "El Ksar – Qair (Gafsa)"                      34.421  8.784 3
              "Sagdoud – Voltalia (Redeyef – Gafsa)"        34.382  8.155 4
              "Menzel El Habib – Voltalia (Gabès)"          33.525   9.65 5
              end
              
              tempfile mydata2
              save mydata2, replace
              
              use tunisia.dta, clear
              merge m:1 adm2_name using `mydata', keep(match) 
              
              spmap tempraturemoyenneannuellec using tunisia_shp.dta, id(_ID) ///
                  fcolor(Reds) ocolor(black) clmethod(custom) ///
                  clbreaks(18 19 20 21 22 23) ///
                  legend(order(2 "18°C - 19°C" 3 "19°C - 20°C" 4 "20°C - 21°C" 5 "21°C - 22°C" 6 "22°C - 23°C" ///
                      99 " "  7 "Khobna – Qair (Mezzouna – Sidi Bou Zid)" 99 " " ///
                      8 "Mezzouna – Scatec (Mezzouna – Sidi Bou Zid)" 99 " " ///
                      9 "El Ksar – Qair (Gafsa)" 99 " " ///
                      10 "Sagdoud – Voltalia (Redeyef – Gafsa)" 99 " " ///
                      11 "Menzel El Habib – Voltalia (Gabès)")) ///
                  label(data("tunisia.dta") xcoord(_CX) ycoord(_CY) ///
                        label(adm2_name) size(*1.1)) ///
                  point(data(mydata2.dta) by(project) xcoord(longitude) ycoord(latitude) ///
                        size(*1.2 ..) fcolor(blue%70 black%70 blue%70 black%70 blue%70) ///
                        ocolor(black ..) shape(T T S S O))

              Click image for larger version

Name:	Graph.png
Views:	1
Size:	83.7 KB
ID:	1785977

              Comment


              • #8
                Andrew Musau Thank you! I do get the idea, it does the job for this exercise, but then I wonder, what if there were more than just 5 points? I was thinking about having the points on the map, without having some differentiating colors and shapes (at least, if there wasn't a categorical variable for those point in my dataset)... But anyway, is there a possibility to have arrows for the points on the sides of the map with the name of each point? Is that feasible on Stata?

                Again, thanks for the help!

                Comment


                • #9
                  You could do it, but the effort does not seem worthwhile. A quick approach is to save the GPH produced by spmap and then install addplot from SSC.

                  Code:
                  ssc describe addplot
                  You can then use standard twoway code to add the lines and text. Alternatively, just use the graph editor.
                  Last edited by Andrew Musau; 16 May 2026, 17:50.

                  Comment


                  • #10
                    Andrew Musau Thanks!

                    Comment

                    Working...
                    X