In this blog post I will be talking about the travel cost variable, namely how to calculate distance and travel times. This is part 1 of a series of posts on this topic. Part 2 will follow next week.
Calculating the travel cost variable accurately is of utmost importance in any travel cost study. Needless to say that if you can’t show that your respondents are sensitive to the amount of money they have to spend to get on-site, everybody will question the validity of your results and data.
The travel cost is the sum of all expenses incurred to visit a recreational site, including both time and distance. It includes several components: the fuel costs, access fees (if any), road tolls, depreciation and the opportunity cost of time. Following Freeman et al. (2014), the full cost of a recreational trip can be expressed as:
wherein is an entrance free to the beach, is the per mile or kilometer cost of travel, is the round-trip distance traveled in miles or kilometers, is the individual specific value of time, is the round-trip time spent to get to the site, and is the time spent on-site. If individuals are free to choose the number of hours worked at a given wage rate, then simplifies to the wage rate (Freeman et al., 2014).
What we want to establish is the existence of a negative-sloped demand curve. This is represented in the graph below. It shows the number of trips to each recreational site on the horizontal axis and how they change in response to the travel cost (in Norwegian kroner) in the left axis.
This blog post will be focusing only on how to accurately estimate and . These are the distance and time traveled, respectively.
Usually, in survey data, we have 500+ respondents. Each respondent is at a different distance to the recreational site. To calculate the distance and time traveled, I could in principle do it manually in Google maps, inserting the coordinate or name of the site in each field. However, to avoid calculating these distances 500+ times, one can use available software that facilitate this work.
Because the travel cost method is much more popular in the US than anywhere else in the world, many authors use the PCMiller software to calculate the distance and time traveled from point A to point B (Leggett et al., 2014 or Hilger and Hanemann, 2006, for example). However, PCMiller seems to be more tailored to North American countries, and it is quite expensive. Instead, there are free R packages that retrieve this information from Google Maps (free within a limit) and which can be applied anywhere in the world.
One of the best packages out there is ggmap, which has a lot of functions related to mapping and geographical data. However, if all you need to do is to calculate the distance, you can use the gmapsdistance package. This is the package I will be talking about. Both packages work the same way, so most of what I will be writing about gmapsdistance also applies to ggmap.
As usual, the first step is to install the relevant package and set it in the library:
It’s very straightforward to use the gmapsdistance package. All you need is to define origin and destination vectors and declare your API key. For example, if my origin was Oslo, in Norway, and the destination is Stockholm, in Sweden, the code would look something like this:
gmapsdistance(origin = c("Oslo+Norway"), destination=c("Stockholm+Sweden"), combinations = "all", mode="driving", key = YOUR_API_KEY)
If you run this command, the output will give you the driving time and distance from Oslo to Stockholm.
Note! Earlier this year (2018), Google API Services have changed their policy and no longer allows for free calls of Google maps. What this means is that you need a “key” to use these commands, otherwise you will get the following error message:
Error in gmapsdistance(c(origin1, origin2, origin3, origin4, origin5, : Google API returned an error: Keyless access to Google Maps Platform is deprecated. Please use an API key with all your API calls to avoid service interruption. For further details please refer to http://g.co/dev/maps-no-account
Creating your own API key is very easy. You need to create your own account in the Google Cloud Platform, using a gmail account. Once there, you should enable billing by associating a credit number with your account. Don’t work, you probably will not spend any money: there is both a monthly free credit of $ 200 US dollars and a one-year credit of $200 US dollars. I rarely reach the monthly limit of $200. This amount represents around 32000 calls/requests from Google maps.
In the case of ggmap (and the function mapdist), instead of writing the “key” option in the command, you should register your API key before you run any ggmap function:
In the Cloud Platform, you should enable the Distance Matrix API. Once you’ve done that, you can generate an API key under the tab “Credentials”. You should copy and paste this API key in the code, replace it in the “key=” part, and not share it with anyone. Once you’ve done this, the R package should work perfectly.
There are a lot of options in this package, and I heavily recommend trying them out. In the next blog post I will be talking in more detail about these options.
Freeman III, A. M., Herriges, J. A., & Kling, C. L. (2014). The measurement of environmental and resource values: theory and methods. Routledge.
Hilger, J., & Hanemann, M. (2006). Heterogeneous preferences for water quality: a finite mixture model of beach recreation in Southern California.
Leggett, C. G., Scherer, N., Curry, M. S., Bailey, R., & Haab, T. C. (2014). Assessing the economic benefits of reductions in marine debris: a pilot study of beach recreation in Orange County, California. Industrial Economics, Incorporated.