# Using R as a pedagogical tool: Deriving Welfare Measures

In this blog post I will talk about the concepts of compensating and equivalent surplus, especifically in the field of environmental economics. I will also illustrate how to produce graphs to illustrate these concepts.

The main motivation to use environmental valuation methods is the recognition that environmental goods and services have a value despite being associated with a price of zero. That is, individuals get welfare when they use environmental goods and services.

There are different measures of welfare. One could think of consumer surplus as the difference between the market price and the maximum amount of money the individual would be willing to pay. Since Nature has a price of zero, the maximum amount of monet or WTP of the individual is in fact his/her consumer surplus.

Instead of finding consumer surplus by drawing a Marshallian demand curve, we think in terms of a consumer’s Hicksian demand. That is the demand for a good that minimizes their expenditure on goods and services while yielding a given level of utility.

If indeed environmental goods and services increase my welfare as an individual, my utility function, denoted by U, depends on the environmental quality or quantity that is available to me. Environmental quality is usually denoted by Q. The environmental quality can represent anything related to quality of the environment that affects an individual’s utility, for example clean air, tree coverage near my house or waste in the street.  On the other hand, the individual’s utility also depends on their income, which is represented by the lower-case y. $U_i = U(Q,y_i)$

An indifference curve is a visual representation of all combinations of the composite good and the environmental good between which the individual is indifferent. Indifference curves to the right means the individual gains higher utility.

Let us draw the indifference curve for an initial situation.

`utility_u <- function(x) 10/x`

To draw the function above, I need to use the tibble and ggplot2 packages.

```library(tibble)
library(ggplot2)
ggplot() + stat_function(data = tibble(x = 1:9), aes(x = x),
fun = utility_u, size = 1, color="black") +
annotate("text", label = "\U016A=U(X,Q)", x = 8.5, y = 1.8,
family= "Times New Roman", size=6) +
labs(x = " Non-market good (Q)", y = " Market good (X)", size=14) +
coord_cartesian(xlim = c(0, 10), ylim = c(0, 6)) +
theme_classic(base_size = 14) +
geom_point(aes(x=4, y=10/4), colour="black", size = 3) +
annotate(geom = "segment", x = 4, y = 10/4, xend = 0, yend = 10/4,
linetype = "dashed", color = "grey50", size = 0.5) +
annotate(geom = "segment", x = 4, y = 10/4, xend = 4, yend = 0,
linetype = "dashed", color = "grey50", size = 0.5) +
scale_x_continuous(expand = c(0, 0), breaks = 4, labels = c("Q\U2080")) +
scale_y_continuous(expand = c(0, 0), breaks = 10/4,
labels = c("\u03A7\U2080")) +
theme(text=element_text(family="Times New Roman"),
plot.margin = unit(c(1.2,1.2,1.2,1.2),"cm"),
axis.title.x = element_text(vjust=-2.00),
axis.title.y = element_text(vjust= 2.00) )```

The code above is quite long because I specified labels for the axis (“labs” option), labeled the curve (“annotate” option), and other options to make the graph more self-explanatory.

This is the resulting graph: Bear in mind that Q, or environmental quality is not something the individual can freely choose, because environmental goods or quality are usually public goods. Environmental quality is usually taken as a given.

However, if the individual’s utility depends on both his/her income and environmental quality, then it is possible to calculate how much the individual would be willing to give up in money terms if environmental quality was improved. In microeconomic theory, that is the definition of the marginal rate of substitution. In other words, if quality would increase slightly, there should be a positive amount of money I would be willing to give up to have that increase in environmental quality, so that my utility increases or stays the same. That is the definition of the Willingness to Pay (WTP), which is a measure of welfare.

Let us assume that there is an improvement in environmental quality. The indifference curve should move to the right, that is the individual now has a higher utility. The new indifference function is defined as:

`utility_u2 <- function(x) 15/x`

To plot this movement of the indifference curve, I can use this code:

```ggplot() +
stat_function(data = tibble(x = 1:9), aes(x = x), fun = utility_u,
size = 1, color="black") +
stat_function(data = tibble(x = 1:9), aes(x = x), fun = utility_u2,
size = 1, color="black") +
annotate("text", label = "\U016A=U(X,Q)", x = 8.5, y = 0.9,
family= "Times New Roman", size=6) +
labs(x = " Non-market good (Q)", y = " Market good (X)", size=14) +
coord_cartesian(xlim = c(0, 10), ylim = c(0, 6)) +
theme_classic(base_size = 14) +
geom_point(aes(x=4, y=10/4), colour="black", size = 3) +
geom_point(aes(x=6, y=10/4), colour="black", size = 3) +
geom_point(aes(x=6, y=10/6), colour="black", size = 3) +
annotate(geom = "segment", x = 6, y = 10/4, xend = 0, yend = 10/4,
linetype = "dashed", color = "grey50", size = 0.5) +
annotate(geom = "segment", x = 6, y = 10/4, xend = 6, yend = 0,
linetype = "dashed", color = "grey50", size = 0.5) +
annotate(geom = "segment", x = 4, y = 10/4, xend = 4, yend = 0,
linetype = "dashed", color = "grey50", size = 0.5) +
annotate(geom = "segment", x = 6, y = 10/6, xend = 0, yend = 10/6,
linetype = "dashed", color = "grey50", size = 0.5) +
scale_x_continuous(expand = c(0, 0), breaks = c(4,6),
labels = c("Q\U2080", "Q\U2081")) +
scale_y_continuous(expand = c(0, 0), breaks = c(10/4, 10/6),
labels = c("\u03A7\U2080", "\u03A7\U2081")) +
theme(text=element_text(family="Times New Roman"),
plot.margin = unit(c(1.2,1.2,1.2,1.2),"cm"),
axis.title.x = element_text(vjust=-2.00),
axis.title.y = element_text(vjust= 2.00) )```

The resulting graph looks like this: The WTP is the distance between the two Xs in the vertical axis. In this case, WTP correspondents to what economists call the compensating surplus for the increase from q0 to q1. Compensating Surplus is the money amount the people have to pay for the change to occur. This is the compensating surplus because we are comparing the two points at the initial indifference curve. If we were comparing the two points at the final indifference curve, we would be referring to equivalent surplus. That would be the money amount that the individuals would accept for the environmental quality change not to occur.

While it might seem confusing why there are two different welfare measures, whether we use one of the other when conducting research depends on the property rights, that is, who owns the right to the environment. If individuals (or society) have the right to get better environmental quality (that is, have the right for the improvement), then it would not make sense to ask for their willingness to pay to obtain this improvement (compensating surplus), but rather for their willingness to accept the change not to occur (equivalent surplus). On the other hand, if they do not have the right to increased environmental quality, then it makes more sense to ask them  for their maximum willingness to pay for improved environmental quality.