Section # 01
Students must abide by UVic academic regulations and observe standards of scholarly integrity (i.e. no plagiarism or cheating). Therefore, this assignment must be taken individually and not with a friend, classmate, or group. You are also prohibited from sharing any information about the assignment with others. I affirm that I will not give or receive any aid on this assignment and that all work will be my own. name here
In environmental economics, perfectly competitive markets are our benchmark for efficiency: surplus is maximal under certain conditions:
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 are private information. 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 competition 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. In one treatment 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. In the other treatment 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. The treatments were imbalanced in terms of the number of subjects: in rounds 1-10 most subjects were in the gain treatment, and then in rounds 11-20 most of the subjects were in the loss treatment. This allows us to look at the how the market institution (market-maker gain vs. loss) interacts with market depth.
Suppose that you are a demander. If you are in the treatment where the market-maker makes a loss, could your bid ever determine the price buyers pay? If you are in the treatment where the market-maker makes a gain, could your bid ever determine the price buyers pay? How does market depth influence the probability your bid will determine the price buyers pay when the marketmaker gains?
The market maker makes a loss when buyers pay the marginal ask… so only by coincidence would you end up paying what you bid. i.e. you paying what you bid could only happen if your bid is the marginal bid and there is no gap between the marginal bid and marginal ask.
The market maker makes a gain when buyers pay the marginal bid… so yes, it is more likely that your bid could be the marginal bid, and thus determine the price you pay.
In the treatment where the marketmaker makes a gain, the fewer the bidders the more likely your bid will be the marginal bid: This should create a greater incentive to shade your bid (bid less than your value) if you are a buyer.
Create a function named salutations which takes as an argument person and prints a personalized greeting. The body of your function should be something like print(paste0("hello ",person,"!")). Hint: functions are defined like this function_name<-function(argument){body}. Functions are called like this: function_name("Rich")
#paste here your salutations function and call it using your name.
salutations <- function(person){
print(paste0("hello ",person,"!"))
}
salutations("Rich")
## [1] "hello Rich!"
Using dataframes supply_and_demand, bid_and_ask, and outcomes plot supply & demand, bids & asks and the marginal bid & ask for round_of_ten==10. Make the supply and demand prominent, and the bids and asks more subtle, and the marginal bid and ask as dots.
Explain what each line of code does to create first_plot. 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. Suppose that you were interested in looking at all the rounds in round_of_ten, not just round 10. What would you modify in the code for first_plot for each different round? How many lines of code would you have if you cut/pasted/modified the code that created first_plot to create second_plot, third_plot… tenth_plot?
The first line of code gives the name first_plot to a plot where quantity is on the x axis and price is on the y axis, and buyers and sellers have a different colour. The second line of code plots the supply and demand step functions for the last round of each session i.e. rounds 10 and 20. The third line of code plots the bid and ask step functions for the last round of each session i.e. rounds 10 and 20. The fourth line of code plots the marginal bid, marginal ask and the number of transactions for the last round of each session i.e. rounds 10 and 20. The fifth line of code creates a separate plot for each of the simulations. The sixth line of code gives a title. To plot a different round, say round 7, you would replace all the 10s with 7s. So cut/paste/modify for all 10 rounds would result in 60 lines of code.
Use the code that created first_plot to write a function plot_sd() that takes as an argument rnd_of_10. The body of plot_sd() will contain the code that created first_plot, except wherever there was a 10 you need to replace it with rnd_of_10. Hint: you can test the function by typing plot_sd(10) and it should look identical to first_plot. Use function assert_that() to make sure the input to your function is valid: i.e. rnd_of_10 %in% 1:10. How many lines of code would you have in total for the function, and 10 calls to that function?
#paste a copy of your plot_sd function here.
plot_sd <- function(rnd_of_10){
assert_that(rnd_of_10 %in% 1:10, msg="rnd_of_10 must be a number between 1 and 10")
ggplot(mapping=aes(x=q, y=variable, colour=role))+
geom_step(data=filter(supply_and_demand, round_of_ten==rnd_of_10), direction="vh",lwd=1.5)+
geom_step(data=filter(bid_and_ask, round_of_ten==rnd_of_10), direction="vh", alpha=.5)+
geom_point(data=filter(outcomes, round_of_ten==rnd_of_10), size=5, alpha=.25)+
facet_grid(marketmaker~Rounds)+
ggtitle(paste0("Supply, Demand (thick), bids, asks (thin), marginal bid,ask (dots) in round ",rnd_of_10))
}
The function is 9 lines of code plus 10 calls to the function equals 19 lines.
Use your function plot_sd() to plot the supply, demand bids and asks in round 10.
Copy and paste the code that created first_plot, and rename it third_plot. Add the aesthetic frame=round_of_ten inside the aes(). i.e mapping=aes(q,variable, colour=role, frame=round_of_ten). Remove the filtering of the data used by both the geom_step() calls e.g instead of data=filter(supply_and_demand,round_of_ten==10) use data=supply_and_demand. Run the code to create third_plot by hitting control plus enter but do not look at at the plot. Instead, if third_plot ran without error, copy the following code into your assignment1.R file and hit control plus enter. How many lines of code were required to see the plots for all 10 rounds?
(third_plot <- ggplotly(third_plot)%>%
animation_opts(1000,transition = 100)%>%
hide_legend()%>%
config(displayModeBar = F))
The animation that shows all ten rounds takes 11 lines of code.
Insert your animation (third_plot) here:
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?
The rows correspond to a single player in a single round of the game. The columns are
Explain what the following code snippet does. Hints: <- is the assignment function (give the result on the right the name on the left). %>% is the pipe function, read as THEN (take what is on the left THEN apply the function on the next line). For functions that have alphabetic names you can type ?name in the console to get help. e.g. ?group_by
value_and_cost <- mydf%>%
group_by(marketmaker,round_of_ten, Rounds, role, variable)%>%
count(variable)
value_and_cost the result of taking dataframe mydf,marketmaker ,round_of_ten, Rounds, and role.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?
For example consider the demand when marketmaker==“gain”, round_of_ten==10, and Rounds==“1-10”. The highest value is 29 and there are 1 people with this value. This is the first horizontal step on the demand function. The second highest value is 28 and there are 1 people with this value. This is the second horizontal step on the demand function. The third highest value is 27 and there are 1 people with this value. This is the third horizontal step on the demand function.
For round_of_ten==10, plot the relationship between choice and variable for all combinations of marketmaker and role, using a different colour for Rounds
Copy and paste the code that created fourth_plot, and rename it fifth_plot. Add the aesthetic frame=round_of_ten inside the aes(). i.e mapping=aes(variable,choice,frame=round_of_ten, colour=Rounds). Remove the filtering of the data e.g. instead of data=filter(mydf, round_of_ten==10) use data=mydf. Run the code to create fifth_plot by hitting control plus enter but do not look at at the plot. Instead, if fifth_plot ran without error, copy the following code into your assignment1.R file and hit control plus enter.
(fifth_plot <- ggplotly(fifth_plot)%>%
animation_opts(1000,transition = 100)%>%
hide_legend()%>%
config(displayModeBar = F))