Nason commited on
Commit
f8b1fe6
·
verified ·
1 Parent(s): e78738b

Publish reviewed dataset guide, preserving later R examples

Browse files
Files changed (1) hide show
  1. README.md +89 -9
README.md CHANGED
@@ -18,20 +18,88 @@ size_categories:
18
 
19
  # Stanford Open Policing Project Database
20
 
21
- Every standardized police stop released by the Stanford Open Policing Project: 35 state
22
- patrols and 53 city or county departments, roughly 2000-2020, in one `stops` table with
23
- the project's standardized columns typed (date, time, place, subject race/sex/age,
24
- outcome, search, contraband, vehicle) and each location's raw_* source columns kept as
25
- text. `locations` documents every source file with its observed and stated coverage and
26
- the project's data notes; `v_stops_by_year` gives per-location annual counts.
27
- **230,002,705 rows across 2 tables.**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  | Table | Description | Row Count | Column Count |
30
  |---|---|---|---|
31
- | `stops` | One row per police stop (traffic and pedestrian) from every Stanford Open Policing Project location, 2000s-2020s: the project's standardized columns (date, time, place, subject demographics, outcome, search, contraband, vehicle) typed, plus each location's raw_* source columns as text; location_id/state/city say where a row came from | 230,002,617 | 223 |
32
  | `locations` | One row per source file: state, city or statewide, release date, rows loaded, observed first/last stop dates, the data readme's stated coverage and data notes | 88 | 14 |
33
 
34
- ## Query it remotely
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  ```sql
37
  INSTALL httpfs; LOAD httpfs;
@@ -43,6 +111,18 @@ FROM policing.stops WHERE date >= '2015-01-01' AND subject_race IN ('white', 'bl
43
  GROUP BY 1, 2 ORDER BY 1, 2;
44
  ```
45
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  ### R with DBI and duckdb
47
 
48
  Install the dependencies once with `install.packages(c("DBI", "duckdb"))`.
 
18
 
19
  # Stanford Open Policing Project Database
20
 
21
+ Traffic and pedestrian stops released by the Stanford Open Policing Project for 35 state patrols and 53 city or county departments, roughly 2000–2020. Use stops for individual stop records and locations to choose a department, time window and fields with usable coverage. Agencies report different years and outcomes; a state-patrol file is not all policing in that state.
22
+
23
+ ## Start querying
24
+
25
+ Preview Connecticut stop records from 2015 onward. Participating agency coverage is uneven; this is not all policing in Connecticut.
26
+
27
+ Choose R or Python. Install datapond once: use `install.packages("datapond")` in R, or run `python -m pip install datapond` in a terminal.
28
+
29
+ ### R
30
+
31
+ ```r
32
+ library(datapond)
33
+ con <- dp_connect("open-policing")
34
+ tryCatch({
35
+ DBI::dbExecute(con, "SET threads=1")
36
+ DBI::dbExecute(con, "SET memory_limit='128MiB'")
37
+ DBI::dbExecute(con, "SET max_temp_directory_size='0B'")
38
+ print(DBI::dbGetQuery(con, "SELECT state,date,subject_race,search_conducted FROM stops WHERE date>=DATE '2015-01-01' AND state='CT' LIMIT 5"))
39
+ }, finally = dp_disconnect(con))
40
+ ```
41
+
42
+ ### Python
43
+
44
+ ```python
45
+ import datapond
46
+ con = datapond.connect('open-policing')
47
+ try:
48
+ con.execute("SET threads=1")
49
+ con.execute("SET memory_limit='128MiB'")
50
+ con.execute("SET max_temp_directory_size='0B'")
51
+ print(con.execute("""SELECT state,date,subject_race,search_conducted FROM stops WHERE date>=DATE '2015-01-01' AND state='CT' LIMIT 5""").fetchall())
52
+ finally:
53
+ con.close()
54
+ ```
55
+
56
+ Queries run on your computer and read the byte ranges they need. A small result can still require a large scan. These examples limit DuckDB to one thread and a 128 MiB buffer pool with disk spill disabled; that is not a limit on the entire R or Python process. Larger analyses may need more memory or a local download with enough disk space.
57
+
58
+ <a id="additional-dataset-notes"></a>
59
+
60
+ ## Tables, fields and joins
61
+
62
+ See the [data dictionary](https://github.com/ian-nason/open-policing-database/blob/main/DICTIONARY.md) for column definitions.
63
+
64
+ **230,002,705 rows across 2 tables.** The 88 source locations use the project’s standardized stop schema.
65
 
66
  | Table | Description | Row Count | Column Count |
67
  |---|---|---|---|
68
+ | `stops` | One row per traffic or pedestrian stop; `location_id`, `state` and `city` identify its source | 230,002,617 | 223 |
69
  | `locations` | One row per source file: state, city or statewide, release date, rows loaded, observed first/last stop dates, the data readme's stated coverage and data notes | 88 | 14 |
70
 
71
+ `location_id` (for example `ca_statewide`, `il_chicago`) joins `stops` to `locations`. The `v_stops_by_year` view gives one row per location and year, with stops, searches, contraband hits, arrests, citations and warnings.
72
+
73
+ ### Common fields and missing values
74
+
75
+ The common fields describe date, time, place, subject race/sex/age, outcome, search, contraband and vehicle. `date` is a DATE, `time` is a TIME, and the twelve yes/no fields (including `search_conducted`, `contraband_found` and `arrest_made`) are BOOLEAN. `subject_age`, `vehicle_year` and `officer_age` are INTEGER; `lat`, `lng` and speeds are DOUBLE; other fields are text.
76
+
77
+ The project’s `NA` is stored as NULL, not false or zero. Columns named `raw_*` preserve location-specific source fields as lower-case text; they are NULL for other locations. The project’s per-location readme explains these extra fields.
78
+
79
+ ## Researcher caveats
80
+
81
+ - **Coverage differs by location and field.** Not every agency records searches,
82
+ contraband, race or outcomes, and date ranges vary from a single year to two decades.
83
+ `locations.readme_coverage` and the per-location null rates in `DICTIONARY.md` say what
84
+ exists; `v_stops_by_year` shows when. Do not compare rates across locations without
85
+ checking that the field is populated in both.
86
+ - **Two releases.** 2023-01-26 files replaced the 2020-04-01 files for the locations the
87
+ project updated (`locations.release_date`); the others are the 2020 release.
88
+ - **Privacy sanitisation by the project.** Most free-text fields have digits replaced by
89
+ `-`; `officer_id_hash` is consistent only within a location; some fields were removed
90
+ before public release (see the readme's asterisked columns).
91
+ - **Statewide files are state patrols**, not all policing in the state; city files are
92
+ single departments.
93
+
94
+ <a id="advanced-access-query-it-remotely"></a>
95
+
96
+ ## Other ways to connect: direct DuckDB SQL
97
+
98
+ This direct example does not set resource limits; the first R/Python examples above do.
99
+
100
+ This alternative uses a DuckDB SQL client and the `policing` catalog alias. The query compares search percentages by state and recorded race for stops from 2015 onward.
101
+
102
+ The search percentage uses stops with a recorded search flag as its denominator, not all stops. A missing flag is excluded rather than treated as “not searched.” Check location and field coverage before interpreting differences between groups.
103
 
104
  ```sql
105
  INSTALL httpfs; LOAD httpfs;
 
111
  GROUP BY 1, 2 ORDER BY 1, 2;
112
  ```
113
 
114
+ <a id="coverage-fields-and-sources"></a>
115
+
116
+ ## Sources and maintenance
117
+
118
+ ### Sources, license and build
119
+
120
+ Source: [Stanford Open Policing Project](https://openpolicing.stanford.edu/data/). License: ODC-By 1.0.
121
+
122
+ Build pipeline, the project’s data readme and caveats: https://github.com/ian-nason/open-policing-database
123
+ Source: Stanford Open Policing Project, https://openpolicing.stanford.edu (ODC-By 1.0; cite Pierson et al. 2020).
124
+
125
+
126
  ### R with DBI and duckdb
127
 
128
  Install the dependencies once with `install.packages(c("DBI", "duckdb"))`.