# 讲解data留学生编程、辅导Python程序、Python语言编程调试 辅导留学生 Statistics统计、回归、迭代|讲解数据库SQL

- 首页 >> Database
Assignment 1
put your name and ID here
Section # 01
In environmental economics, perfectly competitive markets are our benchmark for efficiency: surplus is maximal under certain conditions:
•buyers and sellers take price as given.
•the market-maker knows the demand and supply curve (perfect information)
•there is no government intervention.
•there are no externalities.
The point of experiment 1 is to investigate how crucial are the assumptions of price taking and perfect knowledge. If the model of perfect competition does a good job of predicting behaviour even when these assumptions are not met, we can be more confident about using the model as our efficiency benchmark.
In experiment 1 the market-maker (in our case, the webserver) only makes use of the bids and asks when determining price, not the values and costs which determine the demand and supply curves. Furthermore, your bid or ask may be the marginal bid or ask, determining either the price paid by demanders or the price received by suppliers. In a nutshell, we compare the predictions of perfect competititon to the experimental outcomes to understand whether the assumptions of price taking and perfect information are substantive or merely for analytical convenience.
Recall that in experiment 1 buyers with bids weakly higher than the marginal bid purchase the good and suppliers with asks weakly lower than the marginal ask sell the good. We investigated two different market institutions regarding the prices paid and received. For roughly half the class the price paid by buyers was the marginal bid and the price received by sellers was the marginal ask: The difference between the marginal bid and marginal ask was the market maker’s gain per unit. For the remaining students the prices were reversed: the price paid by buyers was the marginal ask and the price received by sellers was the marginal bid. The difference between the marginal bid and marginal ask was the market maker’s loss per unit.
1 (5 marks)
What are the arguments a.k.a. inputs to function plot_sd? Hint: first_plot is created using function plot_sd in file assignment1.R. first_plot (below) shows the supply, demand, and outcomes for rounds 1-10 when the market-maker makes a gain.

2 (10 marks)
Explain what each line of code does in the body of function plot_sd. Hint: help on what built-in functions do can by found by typing ?x in the console, where x is the name of the function. Comment out the line of code that adds “hi” to the plot by putting a # at the beginning of the line and then save your assignment1.R file. Next, knit your assignment1.Rmd file and make sure the plot above no longer says “hi”.
3 (5 marks)
Describe the dataframe mydf. You can view the dataframe by clicking on it in the top right panel of Rstudio, and it will open in the top left panel. What are the columns, and what are the rows?

4 (5 marks)
Explain what the following code snippet does. Hint: this is covered in https://r4ds.had.co.nz/transform.html.
value_and_cost <- mydf%>%
filter(round==5 | round==15)%>%
mutate(session=case_when(round==5 ~ "1-10",
round==15 ~ "11-20"))%>%
group_by(marketmaker,session, role, variable)%>%
count(variable)
Cut and paste the above code snippet into your assignment1.R file and save. Source the assignment1.R and click on value_and_cost in the top right panel. How can dataframe value_and_cost be used to check to make sure that function plot_sd is plotting the supply and demand correctly?
5 (5 marks)
Use your new and improved version of plot_sd to plot the supply, demand, and outcomes for rounds 1-10 when the market-maker makes a loss. Hint: this plot should no longer say “hi”.
6 (5 marks)
Use your new and improved version of plot_sd to plot the supply, demand, and outcomes for rounds 11-20 when the market-maker makes a gain.
7 (5 marks)
Use your new and improved version of plot_sd to plot the supply, demand, and outcomes for rounds 11-20 when the market-maker makes a loss.
8 (10 marks)
What do the above plots allow us to compare: i.e what can we infer from the supply and demand curves, and what do the numbered points show?
9 (10 marks)
What is the meaning of the phrase market depth? How did market depth vary across the 4 simulations? In particular, what is the relationship between market depth and marketmaker gain vs loss in rounds 1-10 and in rounds 11-20?