PART ONE: CC & PP GRAPH IN A CLOSED ECONOMY

Establishing Formulas and Defining Values:

CC curve is determined using the formula n(F/S)+c, where parameters establish the Fixed Cost (F) to be a constant at 500000, and Marginal Cost to be a constant at 100. With these constants plugged in, the formula becomes n(500000/S)+100.S changes between closed and open economy, but for this first graph, the value for S is 100000, which we establish as constant 1 in the code.

PP curve is determined using the formula c+1/(nb). As established, the Marginal Cost (c) is set to 100, and given the parameter b=.01, the formula becomes 100+1/(n/0.01), which can be simplified as 100+(100/n).

q.supplied <- function(n) {
  return(n*(500000/constant.1) + 100)
}
q.demanded <- function(n) {
  return(100 + 100 / (n))
}
#S in a closed economy
constant.1 <- 100000

n <- seq(from = 1, to = 20, by = 1)
data <- data.frame(n = n, Qd = q.demanded(n), Qs = q.supplied(n))
data_long <- data%>%
  pivot_longer(cols = c(Qd, Qs), names_to = "Variable", values_to = "Price")
plot.1 <- ggplot(data_long, aes(x = n, y = Price, color = Variable)) +geom_line(linewidth = 1.25) +
  scale_color_manual(values = c("Qd" = "blue", "Qs" = "red"),
                      labels = c("Qd" = "PP Line", "Qs" = "CC Line")) +
scale_x_continuous(breaks = seq(0, 20, by = 1)) + 
  labs( 
    title = "Equilibrium in a Monopolistically Competitive Market - CC and PP Graph 1",
    subtitle = "In Closed Economy",
    x = "Number of Firms",
    y = "Price / Cost",
    color = "Curves",
  ) +
  theme_minimal() 

plot.1

PART TWO: PP & CC GRAPH WITH ADDITIONAL CC CURVE REFLECTING A CLOSED ECONOMY

Average Cost as a Function of Number of Firms: Parameter b still set to 0.01, and F to 500000.

As established above, the CC curve is determined using the formula n(500000/S)+100.For the open economy, the parameter S is set to 150000, which is established as constant 2.

#S in a closed economy, corresponding to CC 1 as represented by q supplied
constant.1 <- 100000
#S in an open economy, corresponding to CC 2 as represented by q supplied 2
constant.2 <- 150000

q.supplied <- function(n) {
  return(n*(500000/constant.1) + 100)
}
q.supplied.2 <- function(n) {
  return(n*(500000/constant.2) + 100)
}
q.demanded <- function(n) {
  return(100 + 100 / (n))
}



n <- seq(from = 1, to = 20, by = 1)
data.2 <- data.frame(n = n, Qd = q.demanded(n), Qs = q.supplied(n), Qs.2 = q.supplied.2(n))

data_long.2 <- data.2%>%
  pivot_longer(cols = c(Qd, Qs, Qs.2), names_to = "variable", values_to = "Price")

plot.2 <- ggplot(data_long.2, aes(x = n, y = Price, color = variable)) +geom_line(linewidth = 1.25) + 
  scale_color_manual(values = c("Qd" = "blue", "Qs" = "red", "Qs.2" = "orange"), 
                     labels = c("Qd" = "PP Line", "Qs" = "CC 1 (Closed Economy)", "Qs.2" = "CC 2 (Open Economy)")) + 
  scale_x_continuous(breaks = seq(0, 20, by = 1)) + 
  labs( 
    title = "Equilibrium in a Monopolistically Competitive Market - CC and PP Graph 2",
    subtitle = "In Closed and Open Economies",
    x = "Number of Firms",
    y = "Price / Cost",
    color = "Curves"
  ) +
  theme_minimal() 

plot.2

PART THREE: EQUILIBRIUM CALCULATIONS

A Closed Economy:

#Qd = 100+100/n
#Qs = n(500000/S) + 100
#Because this is the closed economy equilibrium, S is set to 100000 as a parameter.
#Setting them equal now: Qd = Qs -> 100 + 100/n = n(500000/100000) + 100 -> 100 + 100/n = 5n +100 -> 100/n=5n -> 100 = 5(n^2) -> n = root(20). This is then plugged in to the PP function and CC determine the equilibrium price. They should both give roughly the same answer.

eq.firms <- sqrt(20)
eq.price <- function(eq.firms) {
  return(eq.firms * (500000 / 100000) + 100)
}
eq.price1 <- function(eq.firms) {
  return(100+100/(eq.firms))
}

#Aggregate Output: Given by the equation s=5000*n^2. This is derived from setting the CC and PP functions equal to each other, and solving for S.
eq.aggregateoutput <- function(eq.firms) {
  return(5000*((eq.firms)^2))
}

#Firm Output: Given by the equation Q = S/n, using the values for S and N that have been found. 
eq.firmoutput <- function(eq.firms) {
  return((100000)/(eq.firms))
}

options(scipen = 7)
print(paste("Equilibrium Number of Firms: Root 20"))
## [1] "Equilibrium Number of Firms: Root 20"
print(paste("Equilibrium Number of Firms (numerical): ", eq.firms))
## [1] "Equilibrium Number of Firms (numerical):  4.47213595499958"
print(paste("Equilibrium Price (derived via CC function): ", eq.price(eq.firms))) 
## [1] "Equilibrium Price (derived via CC function):  122.360679774998"
print(paste("Equilibrium Price (derived via PP function): ", eq.price1(eq.firms)))
## [1] "Equilibrium Price (derived via PP function):  122.360679774998"
print(paste("Equilibrium Aggregate Output: ", eq.aggregateoutput(eq.firms)))
## [1] "Equilibrium Aggregate Output:  100000"
print(paste("Equilibrium Firm Output: ", eq.firmoutput(eq.firms)))
## [1] "Equilibrium Firm Output:  22360.6797749979"
#Qd = 100+100/n
#Qs = n(500000/S) + 100
#Because this is the open economy equilibrium, S is set to 150000 as a parameter.
#Setting them equal now: Qd = Qs -> 100 + 100/n = n(500000/150000) + 100 -> 100 + 100/n = (10/3)n +100 -> 100/n = (10/3)n -> 300/n = 10n -> 30 = n^2 -> n = root(30). This is then plugged in to the PP function and CC determine the equilibrium price. They should both give roughly the same answer.

eq.firms2 <- sqrt(30)
eq.price2 <- function(eq.firms2) {
  return(eq.firms2 * (500000 / 150000) + 100)
}
eq.price3 <- function(eq.firms2) {
  return(100+100/(eq.firms2))
}

#Aggregate Output: Given by the equation s=5000*n^2. This is derived from setting the CC and PP functions equal to each other, and solving for S.
eq.aggregateoutput <- function(eq.firms2) {
  return(5000*((eq.firms2)^2))
}

#Firm Output: Given by the equation Q = S/n, using the values for S and N that have been found. 
eq.firmoutput <- function(eq.firms2) {
  return((150000)/(eq.firms2))
  }

An Open Economy:

print(paste("Equilibrium Number of Firms: Root 30"))
## [1] "Equilibrium Number of Firms: Root 30"
print(paste("Equilibrium Number of Firms (numerical): ", eq.firms2))
## [1] "Equilibrium Number of Firms (numerical):  5.47722557505166"
print(paste("Equilibrium Price: ", eq.price2(eq.firms2)))
## [1] "Equilibrium Price:  118.257418583506"
print(paste("Equilibrium Price: ", eq.price3(eq.firms2)))
## [1] "Equilibrium Price:  118.257418583506"
print(paste("Equilibrium Aggregate Output: ", eq.aggregateoutput(eq.firms2)))
## [1] "Equilibrium Aggregate Output:  150000"
print(paste("Equilibrium Firm Output: ", eq.firmoutput(eq.firms2)))
## [1] "Equilibrium Firm Output:  27386.1278752583"

PART 4: TOTAL NUMBER OF FIRMS as a FUNCTION of TOTAL OUTPUT Parameters: b = .01, c = 100, F = 500000

#Using the equilibrium equation which sets AC equal to PP, we find that 1/(n*b) + c = n*(F/S) + c -> 1/(n*.01) + 100= n*(500000/S) + 100 -> 100/n = n*(500000/S) -> n^2 = 100S/500000 -> n = sqrt(100S)/sqrt(500000) -> n = sqrt(S)/(10(sqrt(50))). This equation will be the function that will be graphed, using S as the input (x va,ue) and n as the output (y value)

number.of.firms <- function(S) {
  return(sqrt(S)/(10*(sqrt(50))))
}

S <- seq(from = 0, to = 250000, by = 5000)
data <- data.frame(S = S, Nf = number.of.firms(S))

data_long <- data%>%
  pivot_longer(cols = c(Nf), names_to = "Variable", values_to = "Firms")
plot.3 <- ggplot(data_long, aes(x = S, y = Firms, color = Variable)) +geom_line(linewidth = 1) +
  scale_color_manual(values = c("Nf" = "darkblue"),
                      labels = c("Nf" = "Number of Firms")) +
scale_x_continuous(breaks = seq(0, 250000, by = 50000)) + 
scale_y_continuous(breaks = seq(0, 8, by = 1)) +
  labs( 
    title = "Total Number of Firms as a function of Total Output of Market",
    subtitle = "Total Output (S) ranging from 100,000 to 500,000",
    x = "Total Output",
    y = "Number of Firms",
    color = "Curves"
  ) +
  theme_minimal() 
plot.3