Skip to content

Commit

Permalink
Initial public commit
Browse files Browse the repository at this point in the history
  • Loading branch information
khwilson committed Mar 22, 2022
0 parents commit b89628c
Show file tree
Hide file tree
Showing 44 changed files with 83,333 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CENSUS_API_KEY=
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Python cruft
*.pyc
__pycache__
*.egg-info
.venv
.pytest_cache
dist
.ipynb_checkpoints
.mypy_cache

# Editor cruft
.vscode
.*.swp

# Secrets
.env
.env.test
/data/unvax_data
.Rproj.user

# Mac cruft
.DS_Store

# Build
/.snakemake
/Build
/gurobi.log
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8.6
18 changes: 18 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Software license:

Copyright © 2021 The Policy Lab at Brown University

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--------------------------------

HUD and Census data are provided by the US government and are in the public domain.

Elections data are licensed under a CC0 public domain license. See https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/VOQCHQ for details.

All other data provided in this repository are © 2021 The Policy Lab at Brown University
and are licensable under a CC-BY 4.0 license. Text available at https://creativecommons.org/licenses/by/4.0/legalcode
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Health Exchange Advertisement Valences

This repository reproduces the analyses described in our paper "Can Moral Framing Drive
Insurance Enrollment in the US?" In this analysis, we looked at whether “green halo” and
“noble edge” effects demonstrated in other markets would carry over to the health
insurance marketplace.

Using an online advertising platform (Google), we purchased 5.6 million advertising
impressions in English and Spanish, targeting higher-income Americans nationwide during
the 2021 open-enrollment period. Consumers saw advertisements from a control group
(representing status quo ads highlighting economic self-interest, collected from the
field) versus three experimental groups (helping others, helping community, or personal
responsibility). We measured whether consumers clicked to “shop now” on the
[healthcare.gov](https://www.healthcare.gov/) website (1.01% in English and 1.38% in
Spanish at baseline).

This repository represents the code for our analysis of this experiment.

## Requirements

### Software

To run the code in this repository, you will need Python 3.8+ and Stata 16 pre-installed.

In Python, we use [`poetry`](https://python-poetry.org/) to manage our dependencies. To
install this dependency manager, you can run (assumes Mac or Linux; see tool's
documentation for other operating systems):

```bash
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 -
```
Once this is installed, you can install all dependencies with

```bash
poetry install
```

### Census API

In order to run some of this code, you will also need a [Census API Key](https://api.census.gov/data/key_signup.html). Once you have the key, copy the `.env.sample` file to `.env` and fill in your API key in the specified location.

### Running the analysis

Once the dependencies are setup, then you should be able to run the command:

```bash
poetry run snakemake -c 1 all
```

This will produce output in the `build` folder. Note that this does _not_ reproduce
the regressions that are performed in Stata. For those, you will need to open Stata,
point it at the file called `data/phase2/exploded_data_by_demographics.csv.gz`,
and run the do file `src/stata/040_ads_analysis.do`.

### HUD Data

Crosswalks between ZIP codes and Census tracts are made available by the US Department
of Housing and Urban Development [here](https://www.huduser.gov/portal/datasets/usps_crosswalk.html).
We have utilized the third quarter 2021 files, which crosswalk to the 2010 Census
boundaries. For convenience, these files are reproduced in the `data/hud` folder of this
repository.

Din, Alexander and Wilson, Ron, 2020. "Crosswalking ZIP Codes to Census Geographies: Geoprocessing the U.S. Department of Housing & Urban Development’s ZIP Code Crosswalk Files," Cityscape: A Journal of Policy Development and Research, Volume 22, Number 1, https://www.huduser.gov/portal/periodicals/cityscpe/vol22num1/ch12.pdf

### Elections data

Election data is available from MEDSL at their [GitHub repo](https://github.com/MEDSL/2020-elections-official) and the [dataverse](https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/VOQCHQ). For convenience, these data have been reproduced in the `data/medsl` folder of this repository.

MIT Election Data and Science Lab, 2018, "County Presidential Election Returns 2000-2020", https://doi.org/10.7910/DVN/VOQCHQ, Harvard Dataverse, V9, UNF:6:qSwUYo7FKxI6vd/3Xev2Ng==


## Code layout

All of our code lives in the `src` directory. It contains three folders described below:

### `hxpr`: Python utilities

These are a few python utilities that are useful throughout the project. No analysis
occurs in these folders.

### `notebooks`: Data wrangling in Python

This folder contains all of the python notebooks used for data wrangling. Each notebook
handles a different type of data we interacted with.

### `stata`: Analyses in Stata

Our principal statistical analyses were performed in Stata. These may be found in this
folder.
62 changes: 62 additions & 0 deletions Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
rule all:
input:
"data/phase2/merged/data_by_zipcode.parquet",
"data/phase2/demographics_by_zipcode.csv.gz",
"data/phase2/zip_code_with_two_party_vote_share_crude.csv"


rule convert_data:
input:
"data/hud/COUNTY_ZIP_092021.xlsx",
"data/hud/ZIP_COUNTY_092021.xlsx",
"data/hud/TRACT_ZIP_092021.xlsx",
"data/hud/ZIP_TRACT_092021.xlsx"
output:
"data/hud/COUNTY_ZIP_092021.parquet",
"data/hud/ZIP_COUNTY_092021.parquet",
"data/hud/TRACT_ZIP_092021.parquet",
"data/hud/ZIP_TRACT_092021.parquet"
shell:
"mkdir -p build && poetry run papermill src/notebooks/000_Data_to_Parquet.ipynb build/000_Data_to_Parquet.ipynb"

rule parse_data:
input:
"data/phase2/original/DePaul Campaign Data - Demographics.xlsx",
"data/phase2/original/DePaul Campaign Data - State.xlsx",
"data/phase2/original/Depaul Campaign Data - Zip Codes.xlsx",
"data/phase2/original/DePaul Campaign Data - Campaign & Ad Performance.xlsx"
output:
"data/phase2/merged/data_by_zipcode.parquet",
"data/phase2/merged/data_by_demographics.parquet",
"data/phase2/merged/data_by_state.parquet",
"data/phase2/merged/data_by_zipcode_merged_census.parquet",
"data/phase2/exploded/exploded_data_by_zipcode.parquet",
"data/phase2/exploded/exploded_data_by_demographics.parquet",
"data/phase2/exploded/exploded_data_by_state.parquet",
"data/phase2/exploded/exploded_data_by_zipcode_merged_census.parquet",
"data/phase2/exploded/exploded_data_by_zipcode.csv.gz",
"data/phase2/exploded/exploded_data_by_demographics.csv.gz",
"data/phase2/exploded/exploded_data_by_state.csv.gz",
"data/phase2/exploded/exploded_data_by_zipcode_merged_census.csv.gz"
shell:
"mkdir -p build && poetry run papermill src/notebooks/010_Parse_Data.ipynb build/010_Parse_Data.ipynb"

rule political_data:
input:
"data/medsl/countypres_2000-2020.csv.xz",
"data/hud/COUNTY_ZIP_092021.parquet",
"data/hud/ZIP_COUNTY_092021.parquet"
output:
"data/phase2/zip_code_with_two_party_vote_share_crude.parquet",
"data/phase2/zip_code_with_two_party_vote_share_crude.csv"
shell:
"mkdir -p build && poetry run papermill src/notebooks/020_Political_Data.ipynb build/020_Political_Data.ipynb"

rule census_data:
input:
"data/hud/TRACT_ZIP_092021.parquet",
"data/hud/ZIP_TRACT_092021.parquet"
output:
"data/phase2/demographics_by_zipcode.csv.gz"
shell:
"mkdir -p build && poetry run papermill src/notebooks/030_Census_Data.ipynb build/030_Census_Data.ipynb"
Binary file added data/hud/COUNTY_ZIP_092021.parquet
Binary file not shown.
Binary file added data/hud/COUNTY_ZIP_092021.xlsx
Binary file not shown.
Binary file added data/hud/TRACT_ZIP_092021.parquet
Binary file not shown.
Binary file added data/hud/TRACT_ZIP_092021.xlsx
Binary file not shown.
Binary file added data/hud/ZIP_COUNTY_092021.parquet
Binary file not shown.
Binary file added data/hud/ZIP_COUNTY_092021.xlsx
Binary file not shown.
Binary file added data/hud/ZIP_TRACT_092021.parquet
Binary file not shown.
Binary file added data/hud/ZIP_TRACT_092021.xlsx
Binary file not shown.
Binary file added data/medsl/PRESIDENT_precinct_general.csv.xz
Binary file not shown.
Binary file added data/medsl/countypres_2000-2020.csv.xz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added data/phase2/merged/data_by_demographics.parquet
Binary file not shown.
Binary file added data/phase2/merged/data_by_state.parquet
Binary file not shown.
Binary file added data/phase2/merged/data_by_zipcode.parquet
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit b89628c

Please sign in to comment.