Hi,

I am using a shapefile for the UK regions (NUTS1) from https://data.gov.uk/dataset/2aa6727d...united-kingdom

I have managed to convert to a shape file and produce a map but I wanted to label the map with region names. Unfortunately the centroids in the data seem incorrect so I used google to look them up and replace them in the dataset.

When I run my code (see below) all the labels seem to be at the correct latitude but the longitude (X coordinate) is out.

Can anyone help?

thanks,
Jane.

CODE:
//
// file: C:\Users\Jane\Google Drive\PhD\03_Data and modelling\maps\maps.do
//
// data source: https://data.gov.uk/dataset/2aa6727d...united-kingdom
*ssc install geo2xy
cap global working "C:\Users\Jane\Google Drive\PhD\03_Data and modelling\maps"
global proj mercator //albers
*cap global working "C:\Users\leva.sriubaite\Desktop\Jane"
*cap global working "C:\Users\isri0001\Dropbox\Jane"

shp2dta using "$working\regions.shp", ///
database("$working\nuts1_data") coordinates("$working\nuts1_coord") replace genid(nuts1)


*COORD
use "$working\nuts1_coord.dta", clear

/*
london
lon lat
-.30864 51.492271
2.10864 51.492271
*/
/*
set obs 2839094
replace _ID = 13 in 2839092
replace _ID = 13 in 2839093
replace _X = -0.30864 in 2839093
replace _Y = 51.492271 in 2839093
replace _ID = 13 in 2839094
replace _X = 2.10864 in 2839094
replace _Y = 51.492271 in 2839094
*/
*drop if _ID==13
*north
geo2xy _Y _X, proj($proj) replace
save "$working\nuts1_coord-albers.dta", replace


*DATA
use "$working\nuts1_data.dta", clear
cap rename var1 lon

gen lon2=lon
gen lat2=lat
// adjust where the region labels are placed

replace lat=55.1262743 if nuts1==1 //NE
replace lon=-2.8600543 if nuts1==1
replace lat=54.0472108 if nuts1==2 //NW
replace lon=-5.0176158 if nuts1==2
replace lat=53.9266255 if nuts1==3 //Y&H
replace lon=-2.328694 if nuts1==3
replace lat=52.8695323 if nuts1==4 //EMid
replace lon=-1.582406 if nuts1==4
replace lat=52.5048901 if nuts1==5 //WMid
replace lon=-2.0955889 if nuts1==5
replace lat=52.1988214 if nuts1==6 //East
replace lon=0.0499475 if nuts1==6
replace lat=51.5285582 if nuts1==7 //London
replace lon=-0.2416815 if nuts1==7
replace lat=51.3800976 if nuts1==8 //SE
replace lon=-1.373755 if nuts1==8
replace lat=50.9832435 if nuts1==9 //SW
replace lon=-5.0733556 if nuts1==9
replace lat=52.4000296 if nuts1==10 //Wales
replace lon=-5.2809503 if nuts1==10
replace lat=57.6676871 if nuts1==11 //Scotland
replace lon=-8.1709656 if nuts1==11 //-9.1709656


/*replace lon=-0.72 if nuts1==1 //lon==-1.7289 (East-west) NE
replace lon=-1.07 if nuts1==2 //lon==-2.7723701 (East-west) NW
replace lon=-0.18 if nuts1==3 //lon==-1.28712 Y&H
replace lon=0.45 if nuts1==4 //lon==-0.84966999 EMid
replace lon=-1.0 if nuts1==5 //lon==-2.20358 WMid
replace lon=1.8 if nuts1==6 //lon==0.504146 East
replace lon=3.8 if nuts1==7 //lon==-0.30864 London
replace lon=0.45 if nuts1==8 //lon==-0.99311 SE
replace lon=-1.07 if nuts1==9 //lon==-3.63343 SW
replace lon=-1.07 if nuts1==10 //lon==-3.99416 Wales
replace lon=-1.07 if nuts1==11 //lon==-3.97091 Scotland

replace lat=55.09703 if nuts1==1 //lat==55.29703 (North-south)
replace lat=54.02264 if nuts1==3 //lat==53.93264
replace lat=50.911 if nuts1==9 //lon==50.811 SW
replace lat=57.007429 if nuts1==11 //lat==56.177429
*/
drop if objectid == 12

cap gen add = nuts118nm
*Manual adjustment of region name!!!!
replace add="NE" if add=="North East (England)"
replace add="NW" if add=="North West (England)"
replace add="Y&H" if add=="Yorkshire and The Humber"
replace add="E Mid" if add=="East Midlands (England)"
replace add="W Mid" if add=="West Midlands (England)"
replace add="East" if add=="East of England"
replace add="SE" if add=="South East (England)"
replace add="SW" if add=="South West (England)"

/*
ssc install insheetjson
ssc install gcode
ssc install opencagegeo

gen add2 = nuts118nm
gen step = subinstr(add2, " ", "+",.)
gen fulladdress = step + ",+UK"

gcode fulladdress

geocode , fulladdr(fulladdress)
*/

geo2xy lat lon, proj($proj) replace

save "$working\nuts1_data-albers.dta", replace



spmap nuts1 if objectid <12 using "$working\nuts1_coord-albers.dta", id(objectid) ///
label(data("$working\nuts1_data-albers.dta") xcoor(lon) ycoor(lat) label(add) pos(3 0) color(black) size(vsmall)) ///
title("Per capita accidents in British regions, 2015", size(*1.0)) fcolor(Reds)