Introduction to R: Assignment

Intensive Statistics R Teaching

This assignment accompanies the “Introduction to R” tutorial session for MCom (Economics) students attending the Intensive Statistics course at Stellenbosch University (2024).

Wihan Marais
2024-01-24

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.

Task 1

Hint: Run getwd() in your console to check the file path of your working directory.

Task 2

Hint: In .R files, comments are created using the pound sign, i.e., #.

Task 3

  1. Read the ts_data.csv file and store it as a data frame in your Global Environment.

  2. Use the tidyverse syntax (%>%) and mutate() to ensure that the Year column is of the class date.

  3. Ensure that the data frame is arranged chronologically.

  4. 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.

  1. Using 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 your ggplot() to distinguish between countries.

Task 4

  1. Read the cs_data.csv file and store it as a data frame in your Global Environment.

  2. 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

  3. Present all the models in the same regression table using huxreg(). You are not required to perform any additional huxtable formatting operations.

Submission

Once you have completed all of the tasks successfully, please save and send your final R Script to wihanmarais@sun.ac.za for grading.

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.

Reuse

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 ...".

Citation

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}
}