I am trying to generate a map of Germany. After translating my shapefiles into dta files, I import my master dta file (locscode2) and later import the file which includes all the coordinates of German cities (x-ycoord). After merging both dta files, I did encounter problems before because the 'longitude' variable comes as a string variable for some reason. That is why I use the 'destring' command, in order for my spmap command to work later on. Since I am missing some coordinates in my data, I am manually inserting these in my do file. The error it gives comes up in the last command line. I'm guessing it might be related to the 'longitude' variable. Does anyone know what it might be? Thanks! Here's my code:
clear
* Translation of files (shp to dta)
shp2dta using DEU_adm1, database(deudb) coordinates(deucoord) genid(id)
shp2dta using DEU_adm3, database(deudb3) coordinates(deucoord3) genid(id3)
* Directory/Import excel file
cd "/Users/marciadiazclaudio/Desktop/shapefiles"
import excel "location(scode)2.xlsx", sheet("Hoja1") firstrow clear
save "locscode2.dta", replace
use locscode2
drop projCODE
*Import file with all coordinates for german cities
import excel "x-ycoord.xlsx", sheet("Hoja1") firstrow clear
duplicates drop location, force
save allcoord.dta,replace
use locscode2
merge m:m location using allcoord.dta
drop _merge
destring longitude, replace
generate id = _n
* Fill in missing coordinate values
replace latitude = 51.099188 if location == "Auerstedt"
replace longitude = 11.588744 if location == "Auerstedt"
clear
* Translation of files (shp to dta)
shp2dta using DEU_adm1, database(deudb) coordinates(deucoord) genid(id)
shp2dta using DEU_adm3, database(deudb3) coordinates(deucoord3) genid(id3)
* Directory/Import excel file
cd "/Users/marciadiazclaudio/Desktop/shapefiles"
import excel "location(scode)2.xlsx", sheet("Hoja1") firstrow clear
save "locscode2.dta", replace
use locscode2
drop projCODE
*Import file with all coordinates for german cities
import excel "x-ycoord.xlsx", sheet("Hoja1") firstrow clear
duplicates drop location, force
save allcoord.dta,replace
use locscode2
merge m:m location using allcoord.dta
drop _merge
destring longitude, replace
generate id = _n
* Fill in missing coordinate values
replace latitude = 51.099188 if location == "Auerstedt"
replace longitude = 11.588744 if location == "Auerstedt"
Comment