# The Travel Cost Variable (part 1)

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:

$C_j = f_j+p_d+d_j+w(t_j^1+t_j^2)$

wherein $f_j$ is an entrance free to the beach, $p_d$ is the per mile or kilometer cost of travel, $d_j$ is the round-trip distance traveled in miles or kilometers, $w$ is the individual specific value of time, $t_j^1$ is the round-trip time spent to get to the site, and $t_j^2$ is the time spent on-site. If individuals are free to choose the number of hours worked at a given wage rate, then $w$ 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.

Note: Own elaboration based on survey data

This blog post will be focusing only on how to accurately estimate $d_j$ and $t_j^1$. 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:

```install.packages("gmapsdistance")

library(gmapsdistance)```

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,  :

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:

`register_google(YOUR_API_KEY)`

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.

References:

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.