
MODULE 1 Solutions
An R Script with the solutions can be found here: https://drive.google.com/file/d/1SI-McRI_CK2jRU2z9NWFn2eFxjcw9Unc/view?usp=sharing
Task:
Question 1:
Download the task folder. Use the R script in the /script subfolder. Load the task dataset AER 2000-2022.csv by referencing the correct directory. Do not shift files around to accomplish this. You may add lines of code in the R script as you see fit.
Answer:
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
aer = read.csv("../aer/deeper/AER 2000-2022.csv",
encoding = "UTF-8")
You can set the working directory to the source file location by following the answer here (https://stackoverflow.com/questions/13672720/r-command-for-setting-working-directory-to-source-file-location-in-rstudio)
The two dots tells the script to go up a folder. Then we go into /aer/deeper/ to reference the correct directory.
Question 2:
Load the QJE 2000-2022.RData file.
Answer:
load(file = "../QJE 2000-2022.RData")
You should delete “qje <- …” because loading an .RData file automatically loads qje into the environment.
Question 3:
Look at the aer and qje databases, specifically paying attention to the id, title, and author_names variables.
Question 4:
Now, run the code enclosed by the DO NOT EDIT (Part 4) comments. The aer and qje databases are manipulated. Look at the aer and qje databases again after running lines 20 to 24. What happened? (Hint: Pay attention to the id, title, and author_names variables)
Answer:
The dataframe is manipulated so that each author for a given paper is a single observation.
Question 5:
Let’s find out which authors have published in both AER and QJE within the database’s timeframe. Run the code enclosed by the DO NOT EDIT (Part 5) comments. What is the resulting dataframe like? Comment briefly. Do you recognize some of these economists?
Answer:
The resulting dataframe is a single column of authors.
Question 6:
Save the resulting dataframe as a .txt file in a subfolder called Results, separating by line. (Hint: “\n” is line break.)
dir.create(file.path("..", "Results"))
write.table(x = authors_in_both,
file = "../Results/results.txt",
sep = "\n")
You would want to create a directory to save the file in.