This assignment accompanies the “Introduction to R” tutorial session for MCom (Economics) students attending the Intensive Statistics course at Stellenbosch University (2024).
This assignment accompanies the Introduction to R: Tutorial presented on 23 January 2024.
Download the materials needed to complete this assignment here.
This post was last updated on 04 August 2024.
Open R Studio and create a new project in which you will complete the assignment.
Ensure that you are working from the new project and download the necessary assignment materials using this link. Extract the data
folder from the compressed folder you have downloaded and copy it to your root directory.
Hint: Run
getwd()
in your console to check the file path of your working directory.
[yourstudentnumber].R
in your directory. Write and execute the code necessary to complete the rest of the assignment in this R Script.Hint: In
.R
files, comments are created using the pound sign, i.e.,#
.
Load the pacman
package using install.packages("")
(if necessary) and library()
.
Install/load the following packages using the pacman
package:
tidyverse
huxtable
fixest
Read the ts_data.csv
file and store it as a data frame in your Global Environment.
Use the tidyverse
syntax (%>%
) and mutate()
to ensure that the Year
column is of the class date
.
Ensure that the data frame is arranged chronologically.
Subset/filter the data frame to contain only observations for France or Italy between the years 1985-2010.
Hint: When filtering, use the AND (
&
) and OR (|
) operators.
ggplot()
, create a line and scatter plot for the time series ln_consump_pc
of both countries in the same figure. Move the legend to the bottom of the figure and change the label of the y-axis.Hint: Use
aes(x = Year, y = ln_consump_pc, color = Country)
as the mapping for yourggplot()
to distinguish between countries.
Read the cs_data.csv
file and store it as a data frame in your Global Environment.
Using the fixest
package, perform the following three OLS regressions and store each of them in your Global Environment:
wage
on x1
wage
on x1
and x2
wage
on x1
and x2
and the categorical variable nodegree
Present all the models in the same regression table using huxreg()
. You are not required to perform any additional huxtable
formatting operations.
Once you have completed all of the tasks successfully, please save and send your final R Script to wihanmarais@sun.ac.za for grading.
If you see mistakes or want to suggest changes, please create an issue on the source repository.
Text and figures are licensed under Creative Commons Attribution CC BY-SA 4.0. Source code is available at https://github.com/WihanZA/wihan_distill, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".
For attribution, please cite this work as
Marais (2024, Jan. 24). Wihan Marais: Introduction to R: Assignment. Retrieved from https://www.wihanza.com/posts/2024-01-24-introduction-to-r-assignment/
BibTeX citation
@misc{marais2024introduction, author = {Marais, Wihan}, title = {Wihan Marais: Introduction to R: Assignment}, url = {https://www.wihanza.com/posts/2024-01-24-introduction-to-r-assignment/}, year = {2024} }