Drawing Maps for Political Ties with Stata

Jamel Saadaoui
The Stata Gallery
Published in
4 min readMar 17, 2024

--

Today, I will build on my previous blogs to show you how to draw a map of United Nations General Assembly Voting Data with Stata (see here for a full description of the data and the article introducing the methodology for computing ideal points is available here):

Step A

I will put the following files ne_10m_admin_0_countries.dbf, ne_10m_admin_0_countries.shp into the data folder; then I will produce the COW codes from the ne_10m_admin_0_countries.dta using the kountry package (ssc install kountry, replace):

**# *** Maps of Ideal Points ************************

cd C:\Users\jamel\Documents\GitHub\EconMacroBlog\
cd Maps_Political_Ties\

spshape2dta data\ne_10m_admin_0_countries, replace

use ne_10m_admin_0_countries.dta, replace

**#******** Generate country codes *****************************

kountry ADM0_A3, from(iso3c) to(cown)

rename _COWN_ COWcode
order COWcode ADM0_A3, first

save data\maps.dta, replace

The use of the kountry package has been covered in the two following blogs and in an open access article in the Stata Journal written by Rafal Raciborski.

Step B

I generated the file for the ideal points. Note that I already prepared this file in the data folder to merge it with vote data:

**#****** Generate UNvotes for Session 77 **********************

use data\IdealpointestimatesAll_Jul2023_merged.dta, clear

drop if COWcode==.

drop if session!=77

sort COWcode period_

collapse (mean) idealpointall, by(COWcode IFScode country session)

save data\Idealpoint77.dta, replace

Step C

I merge the data with the file that contains the coordinates and draw the maps:

**#****** Merge and draw the Maps ******************************

merge 1:m COWcode using data\maps.dta, nogenerate

format idealpointall %12.2f

// World

spmap idealpointall using ne_10m_admin_0_countries_shp.dta ///
if ADMIN!="Antarctica", id(_ID) ///
fcolor(Reds) osize(vvthin vvthin vvthin vvthin vvthin ///
vvthin vvthin) ///
ndsize(vvthin) ///
ndfcolor(gray) clnumber(7) ///
title("Ideal Points UN Session 77 (Dec 22 - Jun 23)")

graph rename Graph map_ideal_points_world, replace

graph export figures\map_ideal_points_world.png, as(png) ///
width(4000) replace
graph export figures\map_ideal_points_world.pdf, as(pdf) ///
replace

// Latin America & Caribbean

spmap idealpointall using ne_10m_admin_0_countries_shp.dta ///
if REGION_WB=="Latin America & Caribbean", id(_ID) ///
fcolor(Reds) osize(vvthin vvthin vvthin vvthin vvthin ///
vvthin vvthin) ///
ndsize(vvthin) ///
ndfcolor(gray) clnumber(7) ///
title("Ideal Points UN Session 77 (Dec 22 - Jun 23)")

graph rename Graph map_ideal_points_latam, replace

graph export figures\map_ideal_points_latam.png, as(png) ///
width(4000) replace
graph export figures\map_ideal_points_latam.pdf, as(pdf) ///
replace

// Africa

spmap idealpointall using ne_10m_admin_0_countries_shp.dta ///
if CONTINENT=="Africa", id(_ID) ///
fcolor(Reds) osize(vvthin vvthin vvthin vvthin vvthin ///
vvthin vvthin) ///
ndsize(vvthin) ///
ndfcolor(gray) clnumber(7) ///
title("Ideal Points UN Session 77 (Dec 22 - Jun 23)")

graph rename Graph map_ideal_points_africa, replace

graph export figures\map_ideal_points_africa.png, as(png) ///
width(4000) replace
graph export figures\map_ideal_points_africa.pdf, as(pdf) ///
replace

save data\maps_unvotes77_final.dta, replace

****************************************************************

Finally, with a bit of more coding, you can build the time series for the voting data:

**# ***  Smooth Ideal Points ***********************************

use data\IdealpointestimatesAll_Jul2023_merged.dta, clear

collapse (mean) idealpointall, ///
by(COWcode IFScode country period)

sort COWcode period_
drop if COWcode==.

tsset COWcode period_
tsfill, full

bysort COWcode: carryforward idealpointall IFScode country, ///
gen(ideal IFS CNTRY)

xtset COWcode period_

kountry COWcode, from(cown) to(iso3c)

rename _ISO3C_ iso3

encode iso3, gen(cn)
drop if cn==.

xtset cn period_
xtdes

label list cn

xtline ideal if cn==10 | cn==33 | cn==183 | cn==147, overlay
// Smooth the series with a moving average 
// (it works with panel data)
tssmooth ma idealnew = ideal, window(12,1,12)

drop if period_>tm(2023m6)

// Run everything between preserve and restore
preserve
keep if iso3=="USA" | iso3=="RUS" ///
| iso3=="CHN" | iso3=="FRA"
xtline idealnew, overlay legend(pos(6) cols(5)) ///
yline(0) tlabel(1946m1 1970m1 1999m1 2023m6) ///
graphregion(margin(l+2 r+4)) ///
title(Ideal Point Estimates: UN GA Voting Data)
graph rename Graph ideal_over_smoothed, replace
graph export figures\ideal_smoothed_over.png, as(png) ///
width(4000) replace
graph export figures\ideal_smoothed_over.pdf, as(pdf) ///
replace
restore

As we have seen in this blog, it is possible to draw maps in Stata in some simple steps at different levels. These maps could help you to visualize the United Nations General Assembly Voting Data. The files for replicating the results in this blog are available on my GitHub.

About the author

I am a teacher and researcher in social sciences, specialized in several topics related to international economics. Sometimes, I write on Probability, Philosophy, Economics, and other topics with a macro perspective. My recent works explore the interactions between geopolitical tensions and the economy. More information on my personal website: https://www.jamelsaadaoui.com/

--

--

Jamel Saadaoui
The Stata Gallery

I am a teacher and researcher in International Economics. Sometimes, I write on Probability, Philosophy, Economics, and other topics with a macro perspective.