{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 1.0.1 - Beginner - Review of Basic Statistics using R\n", "\n", "COMET Team
\\_William Co, Anneke Dresselhuis, Jonathan Graves, Emrul\n", "Hasan, Jonah Heyl, Mridul Manas, Shiming Wu. \n", "2023-05-08\n", "\n", "## Outline\n", "\n", "### Prerequisites\n", "\n", "- Introduction to Jupyter\n", "- Introduction to R\n", "\n", "### Outcomes\n", "\n", "In this notebook, you will learn how to:\n", "\n", "- Import data from the Survey of Financial Security (Statistics\n", " Canada, 2019)\n", "- Wrangle, reshape and visualize `SFS_data` as part of an Exploratory\n", " Data Analysis (EDA)\n", "- Run statistical tests, such as the $t$-test, to compare mean income\n", " of male-led vs. female-led households\n", "- Generate summary statistics tables and other data-representations of\n", " the data using `group_by()`\n", "- Optional: Run a formal two sample t-test to check for heterogeneity\n", " in how gender affects income and compare the returns to education\n", "\n", "## Part 1: Import Data into R\n", "\n", "The data we use comes from the 2019 Survey of Financial Security\n", "released by Statistics Canada[1](#fn1)." ], "id": "72190f65-857f-471c-bd36-edf53d3be847" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Run this cell to load necessary packages for this tutorial\n", "library(tidyverse)\n", "library(haven)\n", "library(dplyr)\n", "install.packages('vtable')\n", "install.packages('viridis')\n", "\n", "source(\"beginner_review_of_basic_statistics_functions.r\")\n", "#warning messages are okay" ], "id": "f96a1968-5636-476b-8b02-c1fb2a81c3f5" }, { "cell_type": "markdown", "metadata": {}, "source": [ "The **tidyverse** is a collection of R packages developed by Hadley\n", "Wickham and his colleagues as a cohesive set of tools for data\n", "manipulation, visualization, and analysis. In a **tidy** data set, each\n", "variable forms a column and each observation forms a row.\n", "\n", "> `tidyverse` packages such as the `tidyr` and `dplyr` are recommended\n", "> for cleaning and transforming your data into tidy formats.\n", "\n", "Let’s import the `.dta` file from Statistics Canada using the `read_dta`\n", "function." ], "id": "ff403ad3-bf79-4ef0-abb1-fa802df21309" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#If this is your first time using Jupyter Lab, the shortcut to run a cell is `Shift + Enter`.\n", "SFS_data <- read_dta(\"../datasets_beginner/SFS_2019_Eng.dta\")" ], "id": "9a12f263-df29-4e6f-8d27-91b7c334bbae" }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here are some of the common File Extensions and Import Methods in R:\n", "\n", "- `.dta` and `read_dta()` for STATA files\n", "- `.csv` and `read_csv()` for data stored as comma-separated values\n", "- `.Rda` and `load()` for RStudio files and other files formatted for\n", " R" ], "id": "f4b92c56-90dc-4b27-a292-1bd6f1f2821b" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "head(SFS_data, 5)" ], "id": "3731739f-3ea3-4874-8cad-009cb204d3e1" }, { "cell_type": "markdown", "metadata": {}, "source": [ "> `head(df, n)` displays first n rows of the data frame. Other popular\n", "> methods include `glance()` and `print()`" ], "id": "fbd104a4-ac18-4275-8f78-5dbcd9e7aec8" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#You can read the documentation for a given function by adding a question-mark\n", "?head\n", "#Run this" ], "id": "7db3587e-09df-4cd1-9c82-31c27bc56bd6" }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Part 2: Exploratory Data Analysis in R\n", "\n", "There are a routine of steps you should generally follow as part of your\n", "*EDA* or *Exploratory Data Analysis.* Normally, you would analyze and\n", "visualize the variation, correlation, and distribution of your variables\n", "of interest. We do this to gain an intuitive understanding of the data\n", "before we undetake any formal hypothesis tests or model-fitting.\n", "\n", "Let’s think of our key variables of interest. Given our research\n", "question, here are a few:\n", "\n", "- gender of the highest income earner **(independent variable)**\n", "\n", "- income after tax for each individual (variable of interest)\n", "\n", "- income before tax for each individual (variable of interest)\n", "\n", "- wealth for the household (control)\n", "\n", "- education (control)\n", "\n", "**Cleaning and Reshaping `SFS_data`**\n", "\n", "For now, it’d be convenient to work with a new data frame containing\n", "only the key variables (columns) listed above. Moreover, the columns\n", "need to be renamed so they are easier for the reader to remember." ], "id": "19b74ce4-fb60-4d7e-bdcf-936d2e8678ed" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#rename columns\n", "SFS_data <- SFS_data %>%\n", " rename(income_before_tax = pefmtinc) %>% \n", " rename(income_after_tax = pefatinc) %>%\n", " rename(wealth = pwnetwpg) %>%\n", " rename(gender = pgdrmie) %>%\n", " rename(education = peducmie) \n", "\n", "#Drop rows where tax info is missing, ie. pefmtinc = 'NA'.\n", "SFS_data <- filter(SFS_data, !is.na(SFS_data$income_before_tax))\n", "\n", "keep <- c(\"pefamid\", \"gender\", \"education\", \"wealth\", \"income_before_tax\", \"income_after_tax\")\n", "\n", "#new df with chosen columns\n", "df_gender_on_wealth <- SFS_data[keep]\n", "\n", "#preview\n", "head(df_gender_on_wealth, 5)" ], "id": "97541026-d73c-437e-82c8-573eafa85c45" }, { "cell_type": "markdown", "metadata": {}, "source": [ "> This is another **tidy representation** of the original data but with\n", "> less number of variables. The original data set is still stored as\n", "> `SFS_data`.\n", "\n", "**Ensuring correct data-types**\n", "\n", "Notice that education is stored as `` and generally qualitative\n", "variables should be *encoded* and stored as `factors`.\n", "\n", "> The variable `education` in the data-set came as *encoded* as it is\n", "> from a set of values {1, 2, 3, 4, 9}, each of which represent a level\n", "> of education obtained." ], "id": "e8620a2d-b391-415a-80f9-6b9c3e0bb2e0" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df_gender_on_wealth <- df_gender_on_wealth %>%\n", " mutate(education = as.factor(education), \n", " gender = as.factor(gender),\n", " income_before_tax = as.numeric(income_before_tax),\n", " income_after_tax = as.numeric(income_after_tax))\n", "\n", "head(df_gender_on_wealth, 2)" ], "id": "b8c0c03b-7d03-4026-b4c6-341f1fa12f43" }, { "cell_type": "markdown", "metadata": {}, "source": [ "All good! Let’s understand how each of the numbers in the set {1, 2, 3,\n", "9} represent an individual’s educational background.\n", "\n", "**Computing Descriptive Statistics using `vtable` in R**\n", "\n", "Next, I can calculate summary statistics for income and wealth, both\n", "overall and for male-led vs. female-led households." ], "id": "457be1eb-6f29-4cce-b483-c6ef0d4cea24" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "library(vtable)" ], "id": "ecfe5a61-3e2a-496e-a317-bb3d48c7ec1a" }, { "cell_type": "markdown", "metadata": {}, "source": [ "> `sumtable` method from the `vtable` package can be used to display the\n", "> table in different formats including LaTeX, HTML, and data.frame." ], "id": "e8ea6c8d-d915-4a9c-8597-b0a289b63b7f" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sumtbl <- sumtable(df_gender_on_wealth, out = \"kable\")\n", "#out = \"kable\" tells it to return a knitr::kable()\n", "#Replace \"kable\" with \"latex\" and see what happens!\n", "sumtbl" ], "id": "94d48fbd-3ba7-4dbd-94dc-e483ebfcd759" }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is like having a birds-eye view at our data*.* As researcher, we\n", "should take note of outliers and other irregularities in how data for\n", "variables is distributed and ask how it might affect the *validity* of\n", "our models and tests.\n", "\n", "> See Appendix for a common method to remove outliers using Z-score\n", "> thresholds\n", "\n", "**Grouping observations by their characteristics**\n", "\n", "Wouldn’t it be neat to see how mean or median incomes for male and\n", "female-led households look like based on the level of education obtained\n", "by the main income-earner?" ], "id": "ee02aeab-5c85-434c-860a-089817ef3395" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "by_gender_education <- df_gender_on_wealth %>%\n", " \n", " group_by(gender, education) %>%\n", " summarise(mean_income = mean(income_before_tax, na.rm = TRUE),\n", " median_income = median(income_before_tax, na.rm = TRUE),\n", " mean_wealth = mean(wealth, na.rm = TRUE),\n", " median_wealth = median(wealth, na.rm = TRUE))\n", "\n", "by_gender_education" ], "id": "0b1a8b2a-06fe-46b3-b2bc-f969bc9120fc" }, { "cell_type": "markdown", "metadata": {}, "source": [ "> This is again a **tidy representation** of the SFS_data. *Grouping*\n", "> observations by gender and education makes it a bit easier to analyze\n", "> how the different groups compare.\n", "\n", "We can take this chain-of-thought further and generate a `heatmap` using\n", "the `ggplot` package." ], "id": "53e179b3-2da0-41ca-a5db-a4be24e8c634" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "library(ggplot2)\n", "library(viridis)\n", "\n", "# Create the heatmap with an accessible color palette\n", "heatmap_plot <- ggplot(by_gender_education, aes(x = education, y = gender, fill = mean_income)) +\n", " geom_tile() +\n", " scale_fill_viridis_c(option = \"plasma\", na.value = \"grey\", name = \"Mean Income\") +\n", " labs(x = \"Education\", y = \"Gender\")\n", "\n", "# Display the heatmap\n", "heatmap_plot" ], "id": "bc579e5b-09a4-4314-b591-b8e661741426" }, { "cell_type": "markdown", "metadata": {}, "source": [ "> I used the `scale_fill_viridis_c()` method from the `viridis` package\n", "> to ensure that the color palette used for this plot is as per the\n", "> standards of DS.\n", ">\n", "> Now, what does this tell you about how male-led households (gender\n", "> = 1) compare with female-led households in terms of the mean household\n", "> income? Does this tell if education widens the income gap between\n", "> male-led and female-led households with the same level of education?\n", "\n", "We can claim from the visualization that the female-led households with\n", "the same level of education have different mean incomes as compared to\n", "male-led households. This smells of *heterogeneity* and we can explore\n", "regression and other empirical methods to formally test this claim.\n", "\n", "However, we shouldn’t *yet* draw any conclusive statements about the\n", "relationships between gender (of the main income earner), income,\n", "education and other con-founders such as wealth.\n", "\n", "As researchers, we should ask if the differences in the mean or median\n", "incomes for the two groups are significant at all. **Think about how you\n", "would specify the null and alternative hypotheses!** We can then go a\n", "bit further and test if education indeed widens the gap or not.\n", "\n", "### Part 3: Running $t$-test and $Chi$-square test in R" ], "id": "5a491068-3036-4484-bb8b-b73fac3f7599" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Performs a t-test for means comparison\n", "t_test_result <- t.test(income_before_tax ~ gender, data = df_gender_on_wealth)\n", "print(t_test_result)" ], "id": "a7788318-c957-436f-a028-fc08fc32a384" }, { "cell_type": "markdown", "metadata": {}, "source": [ "The 95% C.I does not include 0 and we can confirm that the male-led\n", "households on average earn more as income before tax than the female-led\n", "households, and the gap is statistically significant.\n", "\n", "> How about the medians for the two groups?" ], "id": "53ab5337-809e-4e06-aeb3-dff87a454587" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Perform a Mann-Whitney U test for median comparison\n", "mannwhitneyu_test_result <- wilcox.test(income_before_tax ~ gender, data = df_gender_on_wealth)\n", "print(mannwhitneyu_test_result)" ], "id": "6ff31f39-ad3b-4bb7-b821-df03b191eae6" }, { "cell_type": "markdown", "metadata": {}, "source": [ "This p-value is again highly significant, and based on our data, the\n", "median incomes for the two groups are not equal.\n", "\n", "Our variable of interest is income, and so far, we have provided\n", "statistical evidence for the case that the gender of the main\n", "income-earner is correlated with the household’s income.\n", "\n", "We are however more interested in the causal mechanisms through which\n", "education and wealth *determine* how gender affects household income.\n", "\n", "> Think deeper: According to Ortiz-Ospina and Roser (2018), women are\n", "> overrepresented in low-paying jobs but are underrepresented in\n", "> high-paying ones.\n", ">\n", "> What role does the attainment of education play in sorting genders\n", "> into high vs. low-paying jobs. Can we test this formally with the\n", "> data?\n", "\n", "**Optional: Studying how Wealth and Education might impact the\n", "income-gap**\n", "\n", "There are multiple reasons to study the links between **wealth** and the\n", "**income** gap? DFor instance, we might want to answer whether having\n", "more wealth affects an individual’s income? Moreover, are certain\n", "genders inheriting more wealth than the others, and if so, what can we\n", "say about the gender wage gap?\n", "\n", "We can use some of the methods we have learned in R to analyze and\n", "visualize relationships between income, gender, education and wealth.\n", "\n", "> Let’s see if having a university degree widens the gender income gap?" ], "id": "b1a055e2-6d85-429f-8869-5aaddf1c6988" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SFS_data <- SFS_data %>% \n", " mutate( # more information on mutate in introduction to r modules\n", " university = case_when( \n", " education == \"4\" ~ \"Yes\", #the ~ seperates the original from the new name\n", " TRUE ~ \"No\")) %>% #changes the non university variable to\n", " mutate(university = as_factor(university)) #remember, it's a factor!\n", "\n", "head(SFS_data$university, 10)" ], "id": "c6c5b47c-0216-4ab6-b96d-ac0ae38ee338" }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let’s visualize how the mean wealth compares for male-led vs. female-led\n", "households conditional on whether the main-income earner went to\n", "university!" ], "id": "ab8ae8e2-05d4-425c-9b80-bbd23ab5d0e5" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "results <- \n", " SFS_data %>%\n", " group_by(university,gender) %>%\n", " summarize(m_wealth = mean(wealth), sd_wealth = sd(wealth))\n", "\n", "results \n", "\n", "f <- ggplot(data = SFS_data, aes(x = gender, y = wealth)) + xlab(\"Gender\") + ylab(\"Wealth\") #label and define our x and y axis\n", "f <- f + geom_bar(stat = \"summary\", fun = \"mean\", fill = \"lightblue\") #produce a summary statistic, the mean\n", "f <- f + facet_grid(. ~ university) #add a grid by education\n", "\n", "f" ], "id": "572f3f26-98f7-40de-a2ea-272d1ef04487" }, { "cell_type": "markdown", "metadata": {}, "source": [ "It smells like the wealth gap between the two types of households widens\n", "for groups that have obtained an university degree.\n", "\n", "Similarly, let’s look at the difference in wealth gap in percent terms.\n", "We use `results` generated in previous cell (the $4\\times 4$ table) as\n", "the inputs this time." ], "id": "45cace26-21ff-408e-a36b-b11c99c37b5b" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "library(scales)\n", "percentage_table <- SFS_data %>%\n", " group_by(university) %>%\n", " group_modify(~ data.frame(wealth_gap = mean(filter(., gender == 2)$wealth)/mean(filter(., gender == 1)$wealth) - 1)) %>%\n", " mutate(wealth_gap = scales::percent(wealth_gap))\n", "\n", "percentage_table" ], "id": "19cae2af-e789-414e-9188-da8bab3c6359" }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice the signs are both negative, hence on average, female-led\n", "households have less wealth regardless of whether they have an\n", "university degree or not.\n", "\n", "More importantly, based on our data, female-led households with\n", "university degrees on average have 28% less wealth than male-led\n", "households with university degrees. Comparing the two groups given they\n", "don’t have university degrees, the gap is quite smaller: 18%.\n", "\n", "So, we have shown that the gap widens by about 10% when conditioned for\n", "university degree.\n", "\n", "Let’s test this further by creating sub-samples of “university degree”\n", "and “no university degree” respectively and then running formal two\n", "sample t-test." ], "id": "47f9dedf-313b-487c-ada2-6f9949c81e3a" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "university_data = filter(SFS_data, university == \"Yes\") # university only data \n", "nuniversity_data = filter(SFS_data, university == \"No\") # non university data\n", "\n", "t2 = t.test(\n", " x = filter(university_data, gender == 1)$wealth,\n", " y = filter(university_data, gender == 2)$wealth,\n", " alternative = \"two.sided\",\n", " mu = 0,\n", " conf.level = 0.95)\n", "\n", "t2 # test for the wealth gap in university data\n", "\n", "round(t2$estimate[1] - t2$estimate[2],2) #rounds our estimate\n", "\n", "\n", "t3 = t.test(\n", " x = filter(nuniversity_data, gender == 1)$wealth,\n", " y = filter(nuniversity_data, gender == 2)$wealth,\n", " alternative = \"two.sided\",\n", " mu = 0,\n", " conf.level = 0.95)\n", "\n", "t3 # test for the wealth gap in non-university data\n", "\n", "round(t3$estimate[1] - t3$estimate[2],2) #rounds our estimate" ], "id": "467a8858-bd17-4edc-8525-7c24f6e945e3" }, { "cell_type": "markdown", "metadata": {}, "source": [ "In both tests, the p-values are very small, indicating strong\n", "statistical evidence to reject the null hypothesis. The confidence\n", "intervals also provide a range of plausible values for the difference in\n", "means, further supporting the alternative hypothesis.\n", "\n", "Based on these results, there appears to be a significant difference in\n", "wealth between the two gender groups regardless of university-status,\n", "with gender 1 consistently having higher mean wealth compared to gender\n", "2.\n", "\n", "### Optional: Returns to HS diploma\n", "\n", "Next, examine whether returns to education differ between genders. For\n", "our purposes, we will define:\n", "\n", "**Returns to Education**: The difference in average income before tax\n", "between two subsequent education levels.\n", "\n", "*The following t-test* finds the returns to education of a high school\n", "diploma for males (`retHS`) and for females(`retHSF`), and returns to\n", "education of a university’s degree for males (`retU`) and for females\n", "(`retUF`)." ], "id": "9eb72e1a-d8cb-40a3-bf4a-494a4d7a99b0" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Returns to education: High school diploma\n", "\n", "##Males\n", "less_than_high_school_data = filter(SFS_data, education == 1) #Less than high school\n", "high_school_data = filter(SFS_data, education == 2) #High school\n", "post_secondary_data = filter(SFS_data, education == 3) #Non-university post-secondary\n", "university_data = filter(SFS_data, education == 4) #University\n", "\n", "\n", "retHS = t.test(\n", " x = filter(high_school_data, gender == 1)$income_before_tax,\n", " y = filter(less_than_high_school_data, gender == 1)$income_before_tax,\n", " alternative = \"two.sided\",\n", " mu = 0,\n", " conf.level = 0.95)\n", "retHS_ans=round(retHS$estimate[1] - retHS$estimate[2],2)\n", "\n", "retHSF = t.test(\n", " x = filter(high_school_data, gender == 2)$income_before_tax,\n", " y = filter(less_than_high_school_data, gender == 2)$income_before_tax,\n", " alternative = \"two.sided\",\n", " mu = 0,\n", " conf.level = 0.95)\n", "\n", "retHS\n", "retHSF\n", "#retHS_ans=round(retHS$estimate[1] - retHS$estimate[2],2)\n", "#retHSF_ans=round(retHSF$estimate[1] - retHSF$estimate[2],2)" ], "id": "4efdeb58-af79-4027-a40b-0cee576ea284" }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have found statistically significant evidence for the case that\n", "returns to graduating with a high school diploma are indeed positive for\n", "individuals living in both male-led and female-led households.\n", "\n", "> We could also compute the average returns to a university diploma as\n", "> well by changing a few pieces of the code above.\n", "\n", "### Wrapping Up\n", "\n", "Congratulations on completing this tutorial! We really got started\n", "exploring the gender-wage gap from an empirical point-of-view. We also\n", "spent a few minutes exploring the relationships between gender, income,\n", "wealth and education. These early or preliminary-level explorations are\n", "quite helpful for specifying a regression model that is appropriate!\n", "\n", "You can head to **Appendix** to see further examples of R code working\n", "with data.\n", "\n", "### Appendix\n", "\n", "> If your data set comes with *meta-data*, you try `dictionary()` or\n", "> `str()` to know more about the **variables**." ], "id": "bd81d582-9a44-4a8a-9b3f-73d2c1fe9ebf" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dictionary('peducmie')" ], "id": "0462c0c1-2d16-49ec-8a03-02fa277323d2" }, { "cell_type": "markdown", "metadata": {}, "source": [ "> The `$` operator in `data$variable` points to your variable" ], "id": "167c3a68-8e60-4f88-99ab-83cca92a048f" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Computes the mean networth of the family units in the dataset\n", "mean(SFS_data$pwnetwpg)" ], "id": "a87e8223-443b-4f20-b1be-369b4a99c6dd" }, { "cell_type": "markdown", "metadata": {}, "source": [ "> Removing outliers is a common practice in DS. Here’s the code for\n", "> removing outliers based on a custom Z-score threshold.\n", ">\n", "> Alternatively, you can first visualize your data with box plots and\n", "> then find a convenient threshold to remove outliers in the variables\n", "> of interest." ], "id": "fa736149-ca7a-4a77-bc10-1f5bec027fed" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Calculate the 75th percentile values for wealth, income_before_tax and income_after_tax\n", "\n", "#Drop all rows where any of the variables exceed their 75th percentile value\n", "\n", "# Function to remove outliers based on z-score\n", "remove_outliers_zscore <- function(data, variable, threshold) {\n", " z_scores <- scale(data[[variable]])\n", " data_without_outliers <- data[abs(z_scores) <= threshold, ]\n", " return(data_without_outliers)\n", "}\n", "\n", "# Set the threshold for z-score outlier removal\n", "zscore_threshold <- 3 # Adjust as needed\n", "\n", "# Remove outliers based on z-score for the desired variable\n", "df_filtered <- remove_outliers_zscore(df_gender_on_wealth, \"wealth\", zscore_threshold)\n", "\n", "df_filtered" ], "id": "5d38d7cf-b80d-449a-b984-307ffa882a2e" }, { "cell_type": "markdown", "metadata": {}, "source": [ "> In many places throughout this notebook, we have used the pipe\n", "> operator, ie. `%>%`. In essence, it tells R what to do next and breaks\n", "> the code into incremental steps for the reader including yourself." ], "id": "a3e1be76-191e-4703-82d2-1e698098e1ae" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#df <- df %>% rename(income_before_tax = pefmtinc)\n", "#is the same as\n", "#df <- rename(df, income_before_tax = pefmtinc)" ], "id": "8d6ba963-8b35-4877-903c-cd8362c98e46" }, { "cell_type": "markdown", "metadata": {}, "source": [ "[1](#fn1s)Statistics Canada, Survey of\n", "Financial Security, 2019, 2021. Reproduced and distributed on an “as is”\n", "basis with the permission of Statistics Canada.Adapted from Statistics\n", "Canada, Survey of Financial Security, 2019, 2021. This does not\n", "constitute an endorsement by Statistics Canada of this product.\n", "\n", " Esteban Ortiz-Ospina and Max Roseqoifhoihr (2018) - \"Economic inequality by gender\". Published online at OurWorldInData.org. Retrieved from: 'https://ourworldindata.org/economic-inequality-by-gender' [Online Resource]" ], "id": "535f455a-c42e-45f6-aaa3-8a50567d744a" } ], "nbformat": 4, "nbformat_minor": 5, "metadata": { "kernelspec": { "name": "ir", "display_name": "R", "language": "r" } } }