---
title: "Simple Monocentric City: No Housing, Land in Utility Function"
header-includes: \usepackage{amsmath}
output: html_notebook
---

In this [R Markdown](http://rmarkdown.rstudio.com) notebook I draw some figures illustrating the basic ideas in the monocentric city model (Alonso-Muth-Mills model). To keep things simple, I use a model without a housing construction industry and where consumers just consume land directly. The city is a line and the amount of land at every point is equal to 1.

## Assumptions and Functional Forms
Consumers have Cobb-Douglas utility over *land* $l$ and a numeraire good $z$. 

$$U(l,z)=l^{\alpha}z^{1-\alpha}\tag{1}$$

For a consumer living at distance $x$ from the center, the budget constraint is:
$$y=z+r(x)l(x)-\tau*x\tag{2}$$
The city is closed, with population $N$, and  agricultural land rent $r_A$.

## Solving the Model
In equilibrium all consumers have the same (endogenous) utility, $\bar{u}$, and the land rent at the fringe of the city is equal to the agricultural rent, $r(\bar{x})=r_A$. Further, there is one unit of land at every location, $L(x)=1$ for $x=0$ to $x=\bar{x}$, and everyone is housed between the center of the city and the fringe.

From Cobb-Douglas demand we know that $z(x)=(1-\alpha)(y-\tau*x)$ and $l(x)=\frac{\alpha(y-\tau*x)}{r(x)}$. Substituting these into the spatial equilibrium condition (equal utility) gives:

$$U(l,z)=\left[\frac{\alpha(y-\tau*x)}{r(x)}\right]^{\alpha}\left[(1-\alpha)(y-\tau*x)\right]^{1-\alpha}=\bar{u}\tag{3}$$
We can rewrite this equation to express land rent at $x$ as a function of $y$, $\tau$, $\bar{u}$, and $\alpha$.
$$r(x)=\left(\frac{y-\tau*x}{\bar{u}}\right)^{\frac{1}{\alpha}}\alpha(1-\alpha)^{\frac{1-\alpha}{\alpha}}\tag{4}$$
The Alonso-Muth condition tells us the gradient of the land rent, which we could also derive by taking the derivative of the above equation:
$$\frac{dr(x)}{dx}=-\tau((1-\alpha)(y-\tau*x))^{\frac{1-\alpha}{\alpha}}\bar{u}^{\frac{-1}{\alpha}}=\frac{-\tau}{l(x)}\tag{5}$$
There are $1/l(x)$ people living at every location $x$. Combining the Alonso-Muth condition with the requirement that everyone is housed in the city implies that:
$$\displaystyle\int_{x=0}^{\bar{x}}\frac{1}{l(x)}dx=\frac{1}{-\tau}\displaystyle\int_{x=0}^{\bar{x}}\frac{dr(x)}{dx}dx=\frac{r(\bar{x})-r(0)}{-\tau}=N\tag{6}$$
Using $r(\bar{x})=r_A$ gives $r(0)=\tau*N+r(\bar{x})$. We can then find the utility of a consumer at the center by inserting this expression for $r(0)$ into the indirect utility function (eq 3), thus giving us $\bar{u}$. Finally, with $\bar{u}$ we can solve for $\bar{x}$ by the land rent equation (eq 4) equal to $r_A$.

## Solving for equilibrium
First, let's set the exogenous parameters: $\alpha$, $y$, $\tau$, $r_A$, and $N$.
```{r}
alpha<-0.5
y<-100
tau<-1
r.A<-50
N<-1000
```
Next, let's write functions for the indirect utility and land rent, so that we can solve for the equilibrium values of $\bar{u}$ and $\bar{x}$.
```{r}
V<-function(x,r.x,alpha,y,tau){
  l.x<-alpha*(y-tau*x)/r.x #demand for land
  z.x<-(1-alpha)*(y-tau*x) #demand for numeraire
  l.x^alpha*z.x^(1-alpha) #returns the utility at x
}
R<-function(x,alpha,y,tau,u.bar) {
  inner<-(y-tau*x)/u.bar
  const<-alpha*(1-alpha)^((1-alpha)/alpha)
  inner^(1/alpha)*const #returns the rent at x
}
```
Now let's solve for the equilibrium values. To find the fringe we will look for the value $\bar{x}$ such that $R(\bar{x})-r_A=0$.
```{r}
r.0<-r.A+tau*N
u.bar<-V(0,r.0,alpha,y,tau)
#Define a function so that we can find x.bar
find.xbar<-function(x,alpha,y,tau,r.A,u.bar) {
  R(x,alpha,y,tau,u.bar)-r.A
}
x.bar<-as.numeric(uniroot(find.xbar,lower=0,upper=y/tau,alpha=alpha,y=y,tau=tau,r.A=r.A,u.bar=u.bar)[1])
```
The equilibrium values are $\bar{u}$=`r u.bar` and $\bar{x}$=`r x.bar`.
Is this correct? Let's check if integrating the population at each location is equal to the total, $N$.
```{r}
l.demand<-function(x,alpha,y,tau,r.x) { #demand for land
  alpha*(y-tau*x)/r.x
}
pop<-function(x,alpha,y,tau,u.bar) {
  r.x<-R(x,alpha,y,tau,u.bar)
  1/l.demand(x,alpha,y,tau,r.x)
}
N.check<-integrate(pop,lower=0,upper=x.bar,alpha=alpha,y=y,tau=tau,u.bar=u.bar) #this should be equal to N
```
Integrating the population over the city yields a total population of *N.check*=`r N.check$value`

## Graphing
First, let's graph the equilibrium rent curve
```{r}
curve(R(x,alpha,y,tau,u.bar),from=0,to=x.bar,xlab="Distance from center (x)",ylab="Land rent, r(x)",main="Land rent over the city")
```
Next we can look at land consumption:
```{r}
curve(l.demand(x,alpha,y,tau,R(x,alpha,y,tau,u.bar)),from=0,to=x.bar,xlab="Distance from center (x)",ylab="Land consumption, l(x)",main="Land consumption over the city")
```

### Comparative Statics
Now let's look at some comparative statics.
```{r}
y.1<-500
tau.1<-0.7
r.A.1<-100
N.1<-5000
```
How does a change  in the transporation cost $\tau$ from $\tau_0$=`r tau` to $\tau_1$=`r tau.1` affect land consumption at every point?
```{r}
r.0.1<-r.A+tau.1*N
u.bar.1<-V(0,r.0.1,alpha,y,tau.1)
x.bar.1<-as.numeric(uniroot(find.xbar,lower=0,upper=y/tau.1,alpha=alpha,y=y,tau=tau.1,r.A=r.A,u.bar=u.bar.1)[1])

curve(R(x,alpha,y,tau.1,u.bar.1),from=0,to=x.bar.1,xlab="Distance from center (x)",ylab="Land rent, r(x)",main="Land rent over the city",col="red",ylim=c(0,max(r.0,r.0.1)),xlim=c(0,max(x.bar,x.bar.1)))
curve(R(x,alpha,y,tau,u.bar),from=0,to=x.bar,add=TRUE,col="black")
text(x.bar,l.demand(x.bar,alpha,y,tau,r.A),"tau.0")
text(x.bar.1,l.demand(x.bar.1,alpha,y,tau.1,r.A),"tau.1",col="red")

curve(l.demand(x,alpha,y,tau.1,R(x,alpha,y,tau.1,u.bar.1)),from=0,to=x.bar.1,xlab="Distance from center (x)",ylab="Land consumption, l(x)",main="Land consumption over the city",col="red",ylim=c(0,0.3),xlim=c(0,max(x.bar,x.bar.1)))
curve(l.demand(x,alpha,y,tau,R(x,alpha,y,tau,u.bar)),from=0,to=x.bar,add=TRUE,col="black")
text(x.bar,l.demand(x.bar,alpha,y,tau,r.A),"tau.0")
text(x.bar.1,l.demand(x.bar.1,alpha,y,tau.1,r.A),"tau.1",col="red")
```


# R Notebook Instructions
Add a new chunk by clicking the *Insert Chunk* button on the toolbar or by pressing *Ctrl+Alt+I*.

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the *Preview* button or press *Ctrl+Shift+K* to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike *Knit*, *Preview* does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
