Using R as a pedagogical tool: Illustrating negative externalities

Any coursebook on environmental economics starts off by illustrating the problem of externalities. Three coursebooks I am familiar with do so in  their first chapters: Perman et al. (2003) in chapter 5, Tietenberg & Lewis (2016) in chapter 4 and Callan & Thomas (2013) in chapter 3. I did so as well when I taught the Environmental Economics last semester.

An externality “occurs if the production or consumption decisions of one agent have an impact on the utility or profit of another agent in an unintended way” (Perman et al., 2003). If we are talking about negative unintended consequences, then we say there is a negative externality.

Our pet example in environmental economics is pollution. We consider not only pollution from CO2 emissions that aggavate clima change, but also water, (local) air or land pollution. The pollution emitted by an economic agent is non-excludable and non-rivalrous. That is, no one can be excluded from being affected by pollution and the amount of pollution that affects an individual does not decrease the amount of pollution that the next individual is subjected to. This means, pollution is a public bad and should be regulated by the public agent (government or State). Let us use the case of pollution as a negative externality too.

To be able to show these things graphically to the students, I decided to create my own graphs. They unfortunately were more tedious to produce than I expected, so I thought I’d share the R code to generate the graphs.

We first assume the existence of a benefits curve of pollution. This curve represents the benefits of pollution for society. While it might be hard to grasp that pollution might have benefits, I ask my students to think of economic activities that they enjoy. For example, to enjoy a day at the beach, one has to drive to the beach (which results in air pollution) and inevitably walking on sand might lead to erosion of the beach and nearby ecosystem. Examples of benefits of pollution are: profit for firms given an increase in production, and increase in well-being for individuals. If we monetize and add all the benefits of pollution, we get the function that represents the aggregate benefits of pollution in the same unit of measurement.

Let aggregate benefits from pollution be represented by a function B. The function B depends on the level of pollution, which is denoted by X. If society is allowed to pollute more, there will be a higher level of benefits. The curve is concave, meaning the first unit of pollution gives much higher benefits at the margin that the following unit.


I define this function in R as so:

B = function(x){1500*x-x^2}

We also recognize that pollution has costs (or damages). This is perhaps easier to understand for students, as they are quicker at pointing out costs of pollution rather than benefits. Costs of pollution come in many forms. In the case of air pollution, one can point out the deterioration in human health, decrease in general well-being, deterioration of landscapes due to smog, or generally the costs of climate change. In the case of water pollution, one can point out increased water scarcity and increase in the costs of driking water, health problems, and impact of marine life. In the case of land pollution, costs include trash accumulation, land scarcity and increase in land costs, or health problems as well. This list is not comprehensive.

Much like the benefits function, if we aggregate all the costs from pollution, we can establish a damage function which depends on the level of pollution. If the level of pollution X is zero, then the damages will be zero as well. An increase in the level of pollution will lead to higher and higher increases in the damages for society. This curve is convex, that is, a marginal increase in pollution has lower damages at low levels of pollution than at higher levels of pollution.

Let us assume the damage function to be:


I define this function in R as so:

D = function(x){300*x+2*x^2}

The rational objective for society is to get the maximum benefits of pollution possible while minimizing the costs of pollution. In other words, we want to maximize the net benefits of pollution, which we define as the function NB.


Let us plot the benefit and damage functions in R. I use first the plot function to insert the Benefits function (B) and then the curve function to add the damage function (D).

plot(B(1:1000), type='l', xlab="M", ylab="D(X) & B(X)", col="blue", 
     xlim=c(0,750), ylim=c(0,450000))
curve (D, col="aquamarine4", add=TRUE)

B and D

The level of pollution X that maximizes net benefits is where the distance between the blue (benefits) and green (damages) line is the maximum. However, it is quite hard to see in the graph where that is.

Instead, we can calculate the marginal benefit and marginal damage functions and see where these two lines intersect. The marginal benefit of pollution (MB) is the additional benefit from an extra unit of pollution. The marginal damage of pollution (MD) is the additional damage from an extra unit of pollution.

The net benefits of pollution are maximized only where X is the value that equalizes the marginal benefits of pollution and marginal damage of pollution. That is:

MB(X) =MC(X)

I can find the MB and MD functions by taking the first derivate of the Benefits and Damage functions above with respect to X. Let us define these two curves in R:

MB = function(x){1500-2*x} 
MC = function(x){300+4*x}

The optimal level of pollution is:

1500-2*X = 300+4*X -> 1200 = 6*X -> X* = 200

If pollution is less than X* the marginal benefits of pollution are greater than the marginal level of pollution, so higher pollution will yield additional net benefits. Conversely, if pollution is greater than X*, the marginal benefits of pollution are less than the marginal damage of pollution, so less pollution will yield more net benefits.

The MD or MB at M* is called the equilibrium price of pollution, which we will call P*.

Let us plot the graph of MD and MB in R:

plot(MB(1:1000), type='l', xlab="M", ylab="MD & MB", col="blue", 
     xlim=c(0,750), ylim=c(0,2000)) 
curve (MC, col="aquamarine4", add=TRUE)

MB and MD

I can more easily see that X* = 200 in the graph with MB and MD, rather than the graph above with the aggregate benefits and aggregate damage functions.

The optimal level of emissions for society is 200 (that is, where the lines MD and MB intersect). However, market failure occurs if society does not by itself reach this optimal level. In that case, there is an argument for intervention by the public agent.



Callan, S. J., & Thomas, J. M. (2013). Environmental economics and management: Theory, policy, and applications. Cengage Learning.

Perman, R., Ma, Y., McGilvray, J., & Common, M. (2003). Natural resource and environmental economics. Pearson Education.

Tietenberg, T. H., & Lewis, L. (2016). Environmental and natural resource economics. Routledge.


1 Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s