Stata mqgeocode: OSM Error Fix
Recently, I assigned a GIS problem set to my students and had them geocode addresses to obtain latitude and longitude coordinates using mqgeocode in Stata. The reason I had them use mqgeocode and not geocode3 is because the latter is no longer available through ssc. Does anybody know why? Somebody please tell me. What's the difference between the two? One difference between the two is that mqgeocode uses MapQuest API and geocode3 uses Google Geocoding API.
Anyway, after my students downloaded mqgeocode, I received several emails from students letting me know that they could not obtain coordinates no matter what format the addresses were in. See below:
What? No coords? Why not? With the help of the nice people over at www.wmatsuoka.com we dug a little deeper and saw that the API key in that program had probably hit its limit which is why it wasn't returning any coordinates.
A quick fix for that is to replace the two lines in that ado file with your personal API key. How do you get a MapQuest API key? Just sign up for one here. It's pretty quick and fairly easy.
Then look for the lines "local osm_url1 =" and put in your own API key.
I put in my API key in a local called `apikey' which was passed on to the following lines in that program. The following two lines correspond to lines 47 and 141 of the mqgeocode.ado file, respectively:
local osm_url1 = "http://open.mapquestapi.com/geocoding/v1/reverse?key=`apikey'&location=" local osm_url1 = "http://open.mapquestapi.com/geocoding/v1/address?key=`apikey'&location="
I renamed that ado file and program as mqgeo2 and quickly got to geocoding:
And voilà! We now have latitude and longitude coordinates for our address which happens to be the California State Capitol building.
Ta da! This is what (old) MapQuest looks like (I miss Google already)
4/7/2016 04:28:21 am
Not sure why geocode3 is no longer available, but your students could use ggeocode (http://wbuchanan.github.io/StataJSON/ggeocode/) if they really wanted to use the Google API. An added benefit is that they would also have jsonio available on their machines in case they do any data visualization with D3 or other JS libraries (jsonio also serializes all of the metadata so things like value labels, variable labels, etc... are all available for generating graphs in JS).
4/15/2016 05:08:07 pm
Your comment will be posted after it is approved.
Leave a Reply.
My name is Belen, I like to play with data using Stata during work hours and in my free time. I like blogging about my Fitbit, Stata, and random musings.