Soci–269
Coding Assignment in Python

  Deadline

Friday, November 21st at 8:00 PM

Basic Expectations

As noted in your syllabus, you are required to submit a coding assignment by Friday, November 21st at 8:00 PM. For this assignment, you will clean a dataset in Python , report basic descriptive statistics, create simple data visualizations, and provide some substantive interpretations. You must also include your script file (a .ipynb document) as part of your submission. Once you’re done, please submit your materials via Moodle.

You Must Submit Two Separate Files

Please remember to submit (i) the code you used to complete the assignment along with (ii) a text-based summary of your results and interpretations.

The Data

Description

You will be working with a truncated version of the 2020 American National Elections Studies (ANES) Time Series. The dataset was prepared using the {anesr} package.

You can access the data through one of three channels:

  1. By copying and pasting the script below directly into Colab:
import pandas as pd

pd.read_csv("https://github.com/sakeefkarim/soci-269-f25/raw/refs/heads/main/data/assignments/coding%20assignment%202/anes_2020_truncated.csv")
  1. By directly downloading the .csv file.

  2. By cloning our companion GitHub repository.

Variables

Learn more about the variables in your data by using the codebook embedded below.

Coding Tasks

  1. Report the mean for all numeric variables in the data.1

  2. Report the distribution—i.e., percentage share—of Democrats and Republicans across three age groups: under 40 years old, between 40 and 60 years old, and above 60 years old. Provide separate estimates for individuals who identify as Democrats and those who identify as Republicans. Your estimates should include partisan “leaners”: to wit, Independents who lean Democrat should be classified as Democrats, and Independents who lean Republican should be classified as Republicans.

  3. Report the percentage of Democrats and Republicans who have never married. As before, classify Independents who lean Republican as Republicans, and Independents who lean Democrat as Democrats.

Summarizing Descriptive Results

When writing up your results for Questions 1-3, please use simple tables and plots to present your results in lieu of detailed narrative exposition.

If you can generate weighted estimates for Questions 1-3, you will receive a small bonus.

  1. Once again, explore the numeric (read: float) variables in your data. What are they capturing? Are they meaningfully patterned by the sociodemographic variables included in your truncated dataset? Using seaborn, generate four visualizations that provide preliminary insights based on your exploratory assessments and hunches. Include figure captions.

Narrative Interpretation

Pick one or two of your plots from Question 4. Then, drawing on relevant social scientific research,2 carefully interpret the results. Clearly articulate how your findings relate to (i.e., refine or complicate) extant understandings of \(x\), your social phenomenon of interest. Do your results offer novel or interesting insights? Are there any unexpected patterns that emerge, and if so, how can you account for them? Thoughtfully connect your interpretation to existing work, highlighting areas of convergence or disjuncture before clarifying what your graphic reveals about the social mechanisms animating \(x\). Remember, you have to be brief: papers must be between 5 and 10 pages.

Formatting Guidelines

You are free to prepare your second assignment in Microsoft Word, Google Docs, \(\LaTeX\), RMarkdown or Quarto. Concretely, this means you can submit your assignment as a .docx file or as a . Your main text must be double-spaced and formatted in a 12-point font. Margins should be set to 1 inch on all sides (top, bottom, left, and right). You are free to use either an APA or ASA citation style to manage the references you include.

If you haven’t done so already, you may want to invest in Zotero to manage your citations.

A Note About Subheadings

You must use subheadings to organize your arguments.

Footnotes

  1. You do not need to provide means for the weighting variables or ID indicators.↩︎

  2. Most of the papers you engage with should be quantitatively oriented.↩︎