Look at the Data SOCL 3633 Research Methods · Lab 2 · Midwestern State University

Today you open the General Social Survey data, find out what is in it, and find out what is missing from it. Last week the script was complete. This week you fill in blanks and run the lines yourself, one at a time. Keep this page open next to RStudio and work through the tabs in order. Before you leave, you submit two things in the Lab 2 submission on D2L: your response sheet and the picture file of your own chart.

Get set up

Check off each step as you finish it.

Two new things today

Blanks
A blank looks like ____. Delete the four underscores and type the word the comment above the line asks for. A line with a blank still in it will not run.
Running one line
Put your cursor on a line and press Ctrl+Enter (Mac: Cmd+Enter). R runs that line and prints the result in the Console. Do not click Source today.
Start here. Run the three lines in Step 0 and the four lines in Step 1, one at a time. Red text in the Console after library(dplyr) that says "The following objects are masked" is a normal message, not an error.

Fill in and run: Steps 2 to 5

These steps answer three questions about the data: how many people are in it, what was recorded about each person, and how many people were surveyed in each year.

Step 2: how big is the data?

  1. Fill in both blanks with gss:
    nrow(gss)
    ncol(gss)
  2. Run each line with Ctrl+Enter.
Checkpoint. The Console shows [1] 21483 and then [1] 9. The data has 21,483 rows and 9 columns. Each row stands for one person who answered the survey. Each column is one variable: one survey question, or one fact recorded about the person.

Step 3: what is in each column?

Run glimpse(gss). Each line of the output is one variable, with its type and its first few values. In the tvhours line, some values are NA. You will come back to those in tab 3.

Step 4: how many people in each year?

  1. Fill in the blank with year and run the line:
    count(gss, year)
  2. Read the eight counts. One year has far more people than the others.
The GSS runs every two years, so the years go 2000, 2002, 2004, and so on. Most years have between about 2,000 and 2,800 people. 2006 has 4,510. A count tells you how many people the survey interviewed. It does not tell you why one year was larger. That is a question for the survey's documentation.

Step 5: keep only one year

  1. Fill in the blank with 2014. Numbers do not need quotation marks.
    gss_2014 <- filter(gss, year == 2014)
  2. Run it. Nothing prints. R stored the result under the name gss_2014, which now appears in the Environment pane.
  3. Fill in the next blank with gss_2014 and run nrow(gss_2014). Then run the count(gss_2014, marital) line.
Checkpoint. nrow(gss_2014) gives 2538, the same number Step 4 showed for 2014. The filter() function keeps the rows that match a rule. The double equals sign == asks "is this equal to?" A single = does something else in R, so a rule always uses two.

If something goes wrong

What you seeWhat to do
"unexpected input" or "unexpected symbol"A blank is still in the line, or part of it is. Delete all four underscores and type the word.
"object 'gss' not found"Step 1 did not run in this session. Run the lines in Step 1 again, then come back.
"could not find function"The library() lines did not run. Run Step 1 again.
"object 'Year' not found" or a similar nameR is case-sensitive. Variable names in this data are all lower case.
Error that mentions = inside filter()Use two equals signs: year == 2014.
A + sign in the Console and nothing happensA parenthesis or quotation mark is missing. Click in the Console, press Escape, fix the line, and run it again.

What the counts leave out: Steps 6 to 8

Every dataset has people with no answer recorded for some questions. Before you report anything from a variable, you need to know who has no answer and why. These steps look at two variables where the answer is "many people."

Step 6: the income categories

  1. Fill in the blank with rincome and run the line:
    count(gss, rincome)
  2. Read all 16 categories. Most are amounts of money. ("Lt $1000" means less than $1,000.) Four categories are not amounts of money: the first three and the last one.
No answer, Don't know, Refused
The person was asked about their income and did not give an amount.
Not applicable
The question did not apply to the person, so it was not asked. 7,043 people are in this category.
You will think about who the "Not applicable" people are in question 2 of the response sheet. A hint: rincome is income from the person's own work.

Step 7: who has no TV hours?

Before you run Step 7: out of all 21,483 people, what percent have no value recorded for TV hours?
10%
  1. Run count(gss, is.na(tvhours)). The is.na() function asks "is this value missing?" TRUE means missing. FALSE means a value is there.
  2. Fill in the blank in the next line with 2004. Run that line and the count() line below it.
  3. Change 2004 to 2014. Run both lines again. Compare the two years.
Checkpoint. In 2004, 1,913 of 2,812 people have no TV-hours value. In 2014, 869 of 2,538 do. The GSS does not ask every question of every person. Since 1988, many GSS questions have been asked of a randomly chosen part of each year's sample, often two-thirds. A missing value can mean the person was never asked, or that they were asked and gave no answer. The data on its own does not tell you which.

Step 8: chart the income categories

  1. Fill in the blank with rincome.
  2. Select every line from income_chart <- down to theme_minimal(base_size = 14), and press Ctrl+Enter. Then run print(income_chart).
Checkpoint. Your chart should look like the one below. The two longest bars are "$25000 or more" and "Not applicable."
Horizontal bar chart of the 16 income categories. The two longest bars are $25,000 or more, with about 7,400 people, and Not applicable, with about 7,000 people. Refused has about 1,000. Each dollar range below $25,000 has between about 200 and 1,300 people.

On your own: Step 9

You choose the year and the variable, write the title, and write the line that saves the chart.

  1. Pick a year. In the first blank, put any survey year from Step 4.
  2. Pick a variable. In the second blank, put one of these: marital, race, partyid, or relig.
  3. Write a title. Replace "Write your title here" with a complete sentence that says what the chart shows. Keep it to about ten words so it fits, and keep the quotation marks.
  4. Select every line from my_year <- down to print(my_chart) and press Ctrl+Enter.
  5. Save the chart. Under "Write your ggsave() line here," write one line that saves my_chart, as you did in Lab 1. Name the file with your last name, for example smith_lab2.png. Run the line. The file appears in the Files pane.
Here is one example, using partyid in 2014. Yours will use your own year, variable, and title. Look at the "No answer" and "Don't know" bars in your chart. They are part of what the counts leave out.
Example horizontal bar chart titled Independents were the largest party group in 2014. Independent has about 500 people, Strong democrat about 420, Not strong democrat about 410, and the other categories fewer. No answer has 25 and Don't know has 1.

Then: find a GSS question for your own topic

Question 4 of the response sheet asks you to find one GSS question related to your Writing assignment 1 topic. Use the GSS Data Explorer at gssdataexplorer.norc.org. You do not need an account to search.

  1. Click Search Variables.
  2. Type a keyword from your topic, such as work schedule, church, neighbors, internet, or health.
  3. Open one result. Write down the variable name (a short code in capital letters, such as TVHOURS) and the exact wording of the question.
Before you leave: save the script in your SOCL3633 folder (File, then Save).

Lab 2 response sheet

Answer the four questions in complete sentences. Then assemble your answers into one block of text and paste it into the Lab 2 submission in D2L. In the same submission, upload the picture file of your own chart. Your answers stay on this page and are not sent anywhere until you paste them.

Your name
1. How many people and how many variables are in this data? What does one row stand for?
One to two sentences.
2. 7,043 people have "Not applicable" for income. Who are these people likely to be, and how is that different from the people who "Refused"? What should a researcher do about these people before reporting what share of people earn $25,000 or more?
Three to five sentences.
3. About half of the people in this data have no TV-hours value. What does that mean for a claim like "Americans watch X hours of TV a day"?
Two to four sentences.
4. Find one GSS variable related to your Writing assignment 1 topic in the GSS Data Explorer. Give its name and the exact question wording. Then name one thing it cannot tell you about your research question.
The variable name, the question wording, and two to three sentences.

Sources

NORC at the University of Chicago. General Social Survey, 2000 to 2014. Accessed through the gss_cat extract in the forcats package for R. https://gss.norc.org
NORC at the University of Chicago. n.d. "Frequently Asked Questions." General Social Survey. https://gss.norc.org/faq.html (source for the statement that since 1988 many GSS questions have been asked of a random two-thirds of each sample)
NORC at the University of Chicago. n.d. GSS Data Explorer. https://gssdataexplorer.norc.org
R Core Team. 2024. R: A Language and Environment for Statistical Computing. Vienna: R Foundation for Statistical Computing. https://www.R-project.org
Wickham, Hadley. 2016. ggplot2: Elegant Graphics for Data Analysis. New York: Springer.
Wickham, Hadley. 2023. forcats: Tools for Working with Categorical Variables (Factors). R package version 1.0.0. https://forcats.tidyverse.org
Wickham, Hadley, Romain François, Lionel Henry, Kirill Müller, and Davis Vaughan. 2023. dplyr: A Grammar of Data Manipulation. R package. https://dplyr.tidyverse.org

All counts on this page come from the gss_cat extract and were checked by running the lab script.