Belen Chavez
  • Introduction
  • About
  • Data Blog
  • Calligraphy
  • Teaching

Stata mqgeocode: OSM Error Fix

3/15/2016

2 Comments

 
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:
Picture
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:
Picture
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) 
Picture
2 Comments
William Buchanan link
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).

Reply
Belen
4/15/2016 05:08:07 pm

Hey William,

This is an introductory course in Stata. I'd prefer to have the students get used to using SSC (which I couldn't find a reference to ggeocode). mqgeocode has also been showcased in the Stata Journal which is the primary reason for this blog post. Thanks for the link to ggeocode; it seems jsonio is a bit out of the scope for this assignment/course.

Thanks,
Belen

Reply

Your comment will be posted after it is approved.


Leave a Reply.

    Author

    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.

    If you like the Stata posts you see here, I guarantee you'll also like what's over at
    wmatsuoka.com


    Archives

    March 2018
    January 2018
    September 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015
    September 2015
    August 2015
    July 2015


    Categories

    All
    API
    Beer
    BJJ
    BreweryDB
    CURL
    Education Research
    Excel
    Fitbit
    Fitbit API
    Google
    Google Charts API
    Google Maps
    LinkedIn
    Love
    Parsing
    PPIC
    Putexcel
    Rant
    San Diego
    Stata
    Tableau
    Twitter API
    Valentine's Day


Powered by Create your own unique website with customizable templates.
  • Introduction
  • About
  • Data Blog
  • Calligraphy
  • Teaching