ECON 216 Problem Set 3
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
ECON 216 Problem Set 3
Introduction
This exercise uses an extract from the American Time Use Survey. This survey interviews a sample of Americans every year about how they spent their time during the previous day using a time diary. The individuals who complete the survey in each year are different.
In a time diary people record their activities during short time blocks for 24 hours. We saw an example analysis of the ATUS in the first class.
I have prepared an extract of the dataset that you will use to investigate how the time people spend gaming has evolved since 2003 for different groups.
You will need to have the ggridges package installed on your computer as well as the tidyverse. This
should have been installed if you followed the procedure in the second class. If you haven't installed ggridges yet enter install.packages(ggridges) in the console to do so.
Grading
The problem set has seven parts worth a total of 45 points. You will be graded based on the HTML output you create from your RMarkdown file. You must upload BOTH your RMarkdown AND HTML files.
NOTE that you do not need to create a PDF. Recent updates to some R packages have made knitting to PDF unreliable.
Instructions
Make a project and an RMarkdown document
Go to your workspace on posit.cloud (posit.cloud) and create a new RStudio Project called PS3.Create a new RMarkdown document using the File >New File menu item in RStudio. Then save it into the project's folder
using the name abc123 ps3.Rmd, where abc123 is your CWRUID.
Delete all the material in the new markdown document after the first code chunk.
When you are done with the PS, you will submit the HTML knitted version of this document, which will be
called abc123 ps3.html ,in Canvas.You can export the file from Posit to your computer by selecting it in the file pane and using the“Export.” command in the blue gear menu as shown.
Files |
Plots |
Packages |
Help |
Viewer |
Presentation |
||||
New Folder New Blank File -] Upload Delete Rename More |
|||||||||
Cloud >project >Class 8 |
Copy… Copy To… Move. Copy Folder Path to Clipboard |
|
|||||||
|
|
▲ Name |
|
||||||
|
企 … CL8 -mprvn gC meosRmd CL8- mprng-Cm-Pohm CL8-Im povng-Cme- CL8- - ncaodeRmd ViolentCrimeUSCities1975 2015.RDa |
023, 023, 023, 023, 023, |
|||||||
Open Selected in Source Pane Open Each File in New Columns |
|||||||||
Export… |
|||||||||
|
Set As Working Directory |
Place the data in your project
Upload the data file ATUS PS3.RData using the "Upload files" button in the Files pane in RStudio.
Files Plots Packages Help Viewer Presentation
Q 身 ·
Cloudproject
▲ Name Size Modified
.
Labeling your document
There are three numbered parts to this exercise, each with several lettered subparts.
I n your RMarkdown document, please label each subpart with a heading beginning with two hash signs.
E.g.## Part 1A.Your heading should begin the row it is on.
Note that code chunks and their output must be displayed in your knitted abc123 ps3.html file to get full credit! They will be by default.
Formatting your code
Please use good formatting practice to make your code easy to read. Place arguments to functions separ ated by a comma on separate lines and use argument names when practice. For example:
∴`{r} plotdata <- data %>% filter(career plans!="Other")%>% select(gender, career plans, credits)%>% group by(gender, career plans)%>% summarize(credits = mean(credits))%>% pivot wider(values from ="credits", names from ="career plans")%>% rename(more ed =`More Education )%>% mutate(credits more ed minus work = more ed -Work) ggplot(data = plotdata mapping = aes(y=gender, x=credits more ed minus work))+ geom col() |
HINT
Reviewing the markdown files I have presented in class ought to be very helpful in understanding the techniques used in this exercise.
Part 1 (3 points)
1. Write a code chunk that loads into R the tidyverse and ggridges packages and the
ATUS PS3.RData. You will see a dataset called data in the environment. Display the properties of data by making glimpse(data)the final line of your code chunk.
2. Use in the console View() to inspect the data. Write a sentence or two explaining what the unit of observation is and what information you used to determine your answer.(Do NOT place View() in a
code chunk because it will cause knitting to fail.)
Part 2(4 points)
Write a code chunk that does the following.
a. Creates a new dataset called exdata that contains a modified version of data.
b. Filter exdata so that only people 15 to 64 years old are included.
C. Create a new numeric variable ACT ANYGAMING in exdata that is equal to o if ACT GAMING is zero and 1 if ACT GAMING is greater than zero.You will need to use the functions if else()or case when() to do this.
d.Make the final line of your code chunk glimpse the resulting dataset.
Part 3(8 points)
Write a code chunk that does the following.
a.Create plotdatal from exdata.
b. Create a new numeric variable ANYGAMING mean in plotdatal equal to the mean of ACT ANYGAMING for groups defined by the variables age and gender.
c.Determine what ANYGAMING mean measures and write a short explanation.
d. Create a properly labeled scatterplot using plotdatal with age on the x-axis and ANYGAMING mean the
y-axis. Use one of the techniques we have discussed to show gender. Connect the points for each
gender using geom line().
Part 4 (8 points)
Write a code chunk that does the following.
a.Create exdata2 from exdata.
b. Add a character variable to exdata2 that categorizes year into the three-year groups:“03-05”,“06-08”,
“09-11",“12-14”,“15-17”,and“18-19” .Name the variable you create period.You will need to use case when() within a mutate()to do this.
C. Add a character variable agegroup to exdata2 equal to"Young" for people aged 15-30 and equal to “Old”for people aged 31-64.
d.Convert both period and agegroup from character to factor variables.
e. Create plotdata2 from exdata2.Then recreate ANYGAMING mean grouped by period,agegroup and gender .
f. Create a properly labeled line plot using plotdata2 that shows the share who game for different
periods. Use the techniques we have covered to distinguish age group and gender.(Note that you may need to set the group aesthetic in your ggplot() call.)
Part 5(8 points)
Write a code chunk that does the following.
a.Takes the exdata2 dataset and creates a new dataset plotdata3.
b. Restrict the observations in plotdata3 to those who have done some gaming.
c. Create a variable ACT GAMING wk equal to the number of hours spent gaming per week.
d.Use the geom stat density ridges and plotdata3 to create a properly labeled plot of densities of
gaming hours per week. Using an argument to that geom, add lines at the 25th, 50th, and 90th quantiles of the distributions. The plot should show densities for male and female separately.
Part 6 (8 points)
Write a code chunk that does the following.
a.Takes exdata2 and makes a new dataset plotdata4
b. Restrict the observations in plotdata4 to people 15-30 and for whom !is.na(famincome) is true.
C.Summarize ACT ANYGAMING by grouping by family income, gender, and period and taking the mean of the variable. This shows the share who game for each group.
d.Create a properly labeled bar chart with geom col() that shows the summarized ACT ANYGAMING on the x-axis and family income on the y-axis. Make the plot show a separate bar chart for each
combination of gender and period.
Part 7(6 points)
Write a short paragraph that briefly describes what you have learned about gaming from the patterns you see in each of the four plots. Be sure to mention something about each plot.
2023-03-22