Grouping Categories SOCL 3633 Research Methods · Lab 4 · Midwestern State University
Researchers often combine the categories of a variable into a few groups. That is a measurement decision, and it can change the answer. Today you group the same party answers in two ways, group the religion answers your own way, and read four real GSS questions closely. Keep this page open next to RStudio and work through the tabs in order. Before you leave, you submit two things in the Lab 4 submission on D2L: your response sheet and the picture file of your own chart.
Get set up
One new tool today
other_level.Fill in and run: Steps 2 to 4
Step 2: party identification in 2014
- Fill in
2014and run thefilter()line. Then fill inpartyidand run thecount()line. - Read the ten categories. The GSS asks, "Generally speaking, do you usually think of yourself as a Republican, Democrat, Independent, or what?" People who answer Independent are asked whether they are closer to one party. Their answers become "Ind,near dem" and "Ind,near rep." People who study politics call them leaners.
Step 3: version A, leaners counted as independents
- Select all six lines from
party_a <-toother_level = "All other answers"))and press Ctrl+Enter. Nothing prints. - Run
count(party_a, party3).
Step 4: version B, leaners counted with their party
- In the Democrat line, replace
____withInd,near dem, keeping the quotation marks around it. In the Republican line, replace____withInd,near rep. - Select all six lines from
party_b <-and run them. Then runcount(party_b, party3).
If something goes wrong
| What you see | What to do |
|---|---|
| A warning that says "Unknown levels" | A category name is misspelled. Copy it exactly from the Step 2 output, including the comma and lower-case letters: Ind,near dem. |
| Version B shows 674 people in "All other answers" | The two blanks are still empty or misspelled, so the leaners went into "All other answers." Fix the names and run the six lines again. |
| "unexpected symbol" | A quotation mark or comma is missing. Each category is in quotation marks, with a comma between categories. |
A + sign in the Console and nothing happens | A parenthesis is missing. Press Escape in the Console, fix the line, and run all six lines again. |
| "object 'gss_2014' not found" | Step 2 did not run. Run it, then come back. |
Compare the versions: Step 5
Step 5 has no blanks. Select every line from both <- down to print(compare_chart) and run them together. Your chart should look like the one below.
On your own: Steps 6 and 7
- Run
count(gss_2014, relig, sort = TRUE)to see all the religion categories in 2014. - Change the grouping. The script starts with two groups, Christian and No religion, plus "All other answers." Change it to a grouping you think is better for some research question. Make at least one change: for example, give Catholic its own group, or give Jewish its own group, or move "Christian" (people who answered only "Christian") to a different group. Type category names exactly as they appear in the output, including old spellings such as
Moslem/islam. - Select all the lines from
my_groups <-and run them. Then runcount(my_groups, relig_groups). - Write a title in Step 7: a complete sentence of about ten words that says what your chart shows. Run all the chart lines, then
print(my_chart). - Save the chart. Write one ggsave() line that saves
my_chartwith your last name in the file name, for examplesmith_lab4.png. Run it.
Four GSS questions
Every variable starts as a question someone wrote. Here are four GSS questions, worded as the GSS asks them. For each one, choose the concept it measures best. The reference call and a note on the wording appear after you choose. Question 4 on the response sheet asks you to pick one of these.
Lab 4 response sheet
Answer in complete sentences. Then assemble your answers and paste them into the Lab 4 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.
Sources
NORC at the University of Chicago. General Social Survey codebook: question wording for PARTYID, HAPPY, TRUST, ATTEND, and WRKSTAT. https://gss.norc.org (punctuation lightly edited)
Pew Research Center. 2019. "Political Independents: Who They Are, What They Think." March 14. https://www.pewresearch.org/politics/2019/03/14/political-independents-who-they-are-what-they-think/
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. They are unweighted.