Dissertation Replication Materials
  • Website Info
  • Background Info
  • Q1: FEMA FIRM Info
    • Q1 Figures and Tables
  • Q2: Flood Factor Info
    • Q2 Figures and Tables
    • FF Variable Checks
  • Additional Details
    • File Overview

On this page

  • Project: Flood Risk and Property Values

File Overview

  • Show All Code
  • Hide All Code

  • View Source

Project: Flood Risk and Property Values

Code
library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.5.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   4.0.2     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Code
library(glue)
library(kableExtra)

Attaching package: 'kableExtra'

The following object is masked from 'package:dplyr':

    group_rows
Code
library(stringr)

files <- readxl::read_xlsx("readme_file_information.xlsx")
Code
files |> 
  select(File, Purpose, Inputs, Outputs, `Analysis Step`) |>
  mutate(markdown = glue::glue("
### {row_number()}. `{File}`  
**Purpose:**  
{Purpose}  

**Inputs:**   

- {str_replace_all(Inputs, ', ', '\n- ')}  

**Outputs:**  

- {str_replace_all(Outputs, ', ', '\n- ')}  
")) |> 
  pull(markdown) |> 
  cat(sep = "\n\n")

1. AssessedValues _andFIRMS.qmd

Purpose:
Early exploration of AV trends in SFHA and flood-prone parcels using CCAO data

Inputs:

  • Parcel universe
  • AV data

Outputs:

  • Exploratory graphs and maps

2. building_footprint_clips.R

Purpose:
Identifies parcels that have a building in them where the building is within the SFHA. Specifically uses premade SFHA parcels and intersects it with building outlines to see which SFHA parcels to keep. (earlier SFHA parcel files were created from the land polygon intersecting with the SFHA and was over inclusive.)

Inputs:

  • cook_MS.shp (building outlines)
  • SFHA shapefiles

Outputs:

  • processed/buildings_in_sfha_w_parcelinfo.shp
  • processed/buildings_distinct_in_sfha.csv

3. buyouts.R

Purpose:
Identifies PINs that were bought out due to high flood risk

Inputs:

  • Illinois Buyout Database BuyoutPoints_Statewide.xlsx

Outputs:

  • none

4. CC_Individual_ FEMA_Assistance.qmd

Purpose:
Analyzes FEMA IA aid at ZIP level during recent flood events; descriptive stats on applicants and aid granted

Inputs:

  • data/raw/indiv_assistance_CookCounty.csv
  • data/processed/treated_zipcodes.csv

Outputs:

  • census block
  • tract
  • zip code
  • and muni level post-disaster aid data

5. clean_damanged City_names

Purpose:
Used to assign municipality names to individual aid data from FEMA that had typos in names. Join to IA data. Takes damagedCity variable from Open FEMA individual assistance, exports city names which had tons of typos. This was put in chatGPT to match with clean names.

Inputs:

  • Open FEMA API
  • City_Name_Mapping.csv

Outputs:

  • data/raw/ia_city_names.csv which becomes data/processed/City_Mapping_Names.csv
  • indiv_assistance_V2_CookCounty_wNames.csv

6. Cook_flood_policies _and_claims.qmd

Purpose:
Summarizes NFIP claims and policies across geographies (ZIP, block, tract, muni)

Inputs:

  • data/raw/nfipclaims_CookCounty.csv
  • data/raw/nfippolicies_CookCounty_all.csv

Outputs:

  • Aggregated claim/policy stats. Not used except to show that there are not many claims or insurance policies in cook county. But there are a lot of post-disaster FEMA aid.

7. Cook_Sales_data.qmd

Purpose:
Links sales data with flood risk indicators (SFHA, LOMR, Flood Factor); identifies multi-sale parcels and treatment status

Inputs:

  • data/raw/assessor_parcel_sales.csv, parcels_sfha_2018.gpkg, parcels_sfha_2024.gpkg
  • parcels_lomrs.gpkg, data/raw/pins_floodfactor_2019.csv

Outputs:

  • Counts of PINs by treatment status
  • sales trends

8. CookCounty _ParcelMaps.qmd - ARCHIVED

Purpose:
Early mapping of parcels marked SFHA in CCAO data; not currently used

Inputs:

  • CCAO parcel universe

Outputs:

  • Static SFHA parcel maps

9. data_prep.R

Purpose:
Takes sales data and joins FIRM variables and SFHA indicator variables to the sales. Makes the res_sales.RDS file that goes to 2_create_dataframes which creates the dataframes for files that run models (Question1, Question2, Question3)

Inputs:

  • raw/Assessor_Parcel_Sales_20250105.csv
  • processed/parcels_wFIRMS.csv, processed/sfha_indicator_pins.csv, processed/lomr_pins_2024.csv

Outputs:

  • sales_prepped.rds
  • res_sales.rds

10. descriptive_stats _singlefam.qmd

Purpose:
Naïve OLS and FE models using the “easy” PINs that were always residential

Inputs:

  • singlefamily_assessed_values.csv

Outputs:

  • NA

11. detect_flood_variable _change_in_CCAO

Purpose:
Tries to identify if CCAO removed PINs that were in LOMRs from SFHA indicator or what year they stopped updating the LOMR data if removed

Inputs:

  • Open FEMA API

Outputs:

  • None

12. Flood_Appeal_PINs.qmd - ARCHIVED

Purpose:
Identifies and summarizes AV appeal activity for PINs affected by 2023 flood; compares AV changes for appeal vs. neighbor parcels

Inputs:

  • PTAX-245 appeal forms
  • assessed values

Outputs:

  • Graphs of average AV changes
  • summary stats

13. Flood_factor_pins.qmd - ARCHIVED

Purpose:
Filter for PINs with Flood Factor ≥ 5; analyze post-2023 PTAX-245 flood appeals; calculates AV changes in affected land blocks. Mapped berwyn and cicero

Inputs:

  • Parcel universe API
  • PTAX-245 appeal forms

Outputs:

  • Summary tables and figures

14. make_panel_data.qmd - ARCHIVED

Purpose:
Combine files created by scripts. Combine data necessary for creating variables in models. Code for combining files was rough draft for creating data_prep.R script

Inputs:

  • res_pins_ever.csv
  • sfha_indicator_pins.csv
  • Assessor_Parcel_Sales.csv
  • parcels_wFIRMs.csv
  • floodfactor_scores.csv

Outputs:

  • singlefamily_assessed_values.csv
  • treated.csv

15. mcmillen_salescomparison.qmd

Purpose:
reads in McMillens Sales Data

Inputs:

  • parquet file from McMillen
  • Assessor_sales file from CCAO

Outputs:

  • NA

16. pull_addresses_pins_wo_ffscores.R

Purpose:
Takes PINs that didn’t have flood factor scores and pulls addresses to make searching flood factor score faster. Otherwise you have to search the PIN to get the address, and then search the address to get the Risk Score.

Inputs:

  • missing_floodfactor_scores.xlsx
  • API for Cook County parcel addresses

Outputs:

  • pins_with_some_addresses.csv

17. pull_distinct_ resPINs.R

Purpose:
Extract all parcels that were residential from 2006–2023 and pull assessed values

Inputs:

  • PTAXSIM database

Outputs:

  • data/raw/residential_pins_ever.csv, pin_muni_key.csv, muniname_taxcode_key.csv

18. pull_floodfactor _pin_list.R

Purpose:
Join Flood Factor risk scores (2019 snapshot) to Cook County parcel universe

Inputs:

  • Parcel universe with PINs
  • Flood Factor data

Outputs:

  • data/raw/floodfactor_scores.csv
  • data/processed/floodfactor_scores.csv

19. pull_individual_ assistance_applicants.R

Purpose:
Pull FEMA Individual Assistance (IA) application data for Cook County (accepted and denied)

Inputs:

  • FEMA IA API

Outputs:

  • data/raw/indiv_assistance_CookCounty.csv, data/processed/treated_zipcodes.csv

20. pull_NFIP_ redactedclaims.R

Purpose:
Pull NFIP policy and claims data for Cook County from FEMA API

Inputs:

  • NFIP Policies API
  • NFIP Claims API

Outputs:

  • data/raw/nfippolicies_CookCounty_all.csv, data/raw/nfipclaims_CookCounty.csv

21. pull_parcel_sfs.R

Purpose:
Download and convert Cook County parcel shapefiles for 2018 and 2023

Inputs:

  • ptaxsim parcel centroids

Outputs:

  • S_FIRM_PAN.csv, parcels_wFIRMS.csv

22. shapefile_sfha_changes.R

Purpose:
Compares CCAO flood variables to NFHL. Makes shapefiles and also CSV versions of PINs that are in each SFHA or LOMR

Inputs:

  • NFHL 2018 and NFHL 2024 (NFHL_17_20180129.gdb
  • Statewide_NFHL_17_20240628.gdb)

Outputs:

  • sfha_indicator_pins.csv
  • S_FIRM_PAN.csv
  • parcels_sfha_2018.csv(shp)
  • parcels_lomrs_2018.csv(shp)
  • sfha_pins_2024.csv
  • lomr_pins_2024.csv,

23. waterbasins_map.R

Purpose:
Makes visualization of cook county with rivers and water basins. Not actually used for dissertation.

Inputs:

  • Water Basins shapefiles online. River shapefiles

Outputs:

  • NA

24. 2_create_datasets.qmd

Purpose:
Creates df_prep and df_pairs for files that run the models. Reads in sales data and turns it into repeat sales data format

Inputs:

  • res_sales.rds
  • pin_muni_key.csv
  • muni_shortnames.xlsx

Outputs:

  • df_pairs.RDS
  • ff_pairs.RDS
  • df_prep.RDS

25. 3_check_assumptions

Purpose:
Check for parallel trends for models

Inputs:

  • NA

Outputs:

  • NA

26. Question1

Purpose:
NA

Inputs:

  • NA

Outputs:

  • NA

27. Question2

Purpose:
NA

Inputs:

  • NA

Outputs:

  • NA

28. Question3

Purpose:
NA

Inputs:

  • city_name_mapping.csv
  • FEMA API for individual assistance

Outputs:

  • NA

29. data_prep_buildings.R

Purpose:
NA

Inputs:

  • NA

Outputs:

  • NA

30. didFF_test.R

Purpose:
Implied density tests of distributional parallel trends. Saves model and plot output because it takes a long time to run.

Inputs:

  • df_prep_buildings.RDS

Outputs:

  • outputs/didFF_model_out.rds
  • outputs/didFF_plot_out.rds
  • outputs/didFF_model_out2.rds
  • outputs/didFF_plot_out2.rds

31. q1_assumption_tests.qmd

Purpose:
NOT USED 11/23/2025: use did packageto by Callaway & Sant’Anna but didn’t do treatment within the cohorts. Instead it just compared pre and post event trends of the cohorts, where it ran the models as if each cohort was treated.

Inputs:

  • NA

Outputs:

  • NA

32. Question1_continued_staggered.qmd

Purpose:
Compares Fixed Effects models for question 1 to fixest::sunab() estimates. Creates staggered treatment plots and staggered model estimates for Question 1.

Inputs:

  • df_prep_buildings.RDS

Outputs:

  • NA

33. comparison_2variables.R

Purpose:
uses high_ff _post variable

Inputs:

  • df_prep_bldg_v2026_03.RDS

Outputs:

  • outputs/compared_by2variables.rds

34. comparison_3variables.R

Purpose:
splits high_ff_score & post variable

Inputs:

  • df_prep_bldg_v2026_03.RDS

Outputs:

  • outputs/compared_by3variables.rds
Code
#DT::datatable(files)


files |> kable(booktabs = TRUE) |> #kable_paper(full_width = F) |>
  column_spec(1, width = "1in") |>
  column_spec(2, width = "3in") |>
  column_spec(3, width = "1in") |>
  column_spec(4, width = "1in") |>
  column_spec(5, width = "1in")
File Purpose Inputs Outputs Analysis Step DV Model Type For dissertation Became targets pipeline?
AssessedValues _andFIRMS.qmd Early exploration of AV trends in SFHA and flood-prone parcels using CCAO data Parcel universe, AV data Exploratory graphs and maps Exploratory & Descriptive Analysis Assessed Value No NA
building_footprint_clips.R Identifies parcels that have a building in them where the building is within the SFHA. Specifically uses premade SFHA parcels and intersects it with building outlines to see which SFHA parcels to keep. (earlier SFHA parcel files were created from the land polygon intersecting with the SFHA and was over inclusive.) cook_MS.shp (building outlines), SFHA shapefiles processed/buildings_in_sfha_w_parcelinfo.shp, processed/buildings_distinct_in_sfha.csv Data Preparation Scripts NA Y NA
buyouts.R Identifies PINs that were bought out due to high flood risk Illinois Buyout Database BuyoutPoints_Statewide.xlsx none Other External Data Exploration NA dropped - q3 NA
CC_Individual_ FEMA_Assistance.qmd Analyzes FEMA IA aid at ZIP level during recent flood events; descriptive stats on applicants and aid granted data/raw/indiv_assistance_CookCounty.csv, data/processed/treated_zipcodes.csv census block, tract, zip code, and muni level post-disaster aid data Exploratory & Descriptive Analysis NA dropped - q3 NA
clean_damanged City_names Used to assign municipality names to individual aid data from FEMA that had typos in names. Join to IA data. Takes damagedCity variable from Open FEMA individual assistance, exports city names which had tons of typos. This was put in chatGPT to match with clean names. Open FEMA API, City_Name_Mapping.csv data/raw/ia_city_names.csv which becomes data/processed/City_Mapping_Names.csv, indiv_assistance_V2_CookCounty_wNames.csv Data Preparation Scripts NA dropped - q3 NA
Cook_flood_policies _and_claims.qmd Summarizes NFIP claims and policies across geographies (ZIP, block, tract, muni) data/raw/nfipclaims_CookCounty.csv, data/raw/nfippolicies_CookCounty_all.csv Aggregated claim/policy stats. Not used except to show that there are not many claims or insurance policies in cook county. But there are a lot of post-disaster FEMA aid. Exploratory & Descriptive Analysis NA Background info / Intro NA
Cook_Sales_data.qmd Links sales data with flood risk indicators (SFHA, LOMR, Flood Factor); identifies multi-sale parcels and treatment status data/raw/assessor_parcel_sales.csv, parcels_sfha_2018.gpkg, parcels_sfha_2024.gpkg, parcels_lomrs.gpkg, data/raw/pins_floodfactor_2019.csv Counts of PINs by treatment status, sales trends Exploratory & Descriptive Analysis Sales No NA
CookCounty _ParcelMaps.qmd - ARCHIVED Early mapping of parcels marked SFHA in CCAO data; not currently used CCAO parcel universe Static SFHA parcel maps Exploratory & Descriptive Analysis NA No NA
data_prep.R Takes sales data and joins FIRM variables and SFHA indicator variables to the sales. Makes the res_sales.RDS file that goes to 2_create_dataframes which creates the dataframes for files that run models (Question1, Question2, Question3) raw/Assessor_Parcel_Sales_20250105.csv, processed/parcels_wFIRMS.csv, processed/sfha_indicator_pins.csv, processed/lomr_pins_2024.csv |sales_prepped.rds, res_sales.rds |Data Preparation Scripts |NA |NA |Y
descriptive_stats _singlefam.qmd Naïve OLS and FE models using the "easy" PINs that were always residential singlefamily_assessed_values.csv NA Exploratory & Descriptive Analysis NA No NA
detect_flood_variable _change_in_CCAO Tries to identify if CCAO removed PINs that were in LOMRs from SFHA indicator or what year they stopped updating the LOMR data if removed Open FEMA API None Data Preparation Scripts NA No No
Flood_Appeal_PINs.qmd - ARCHIVED Identifies and summarizes AV appeal activity for PINs affected by 2023 flood; compares AV changes for appeal vs. neighbor parcels PTAX-245 appeal forms, assessed values Graphs of average AV changes, summary stats Exploratory & Descriptive Analysis Assessed Value dropped - q3 NA
Flood_factor_pins.qmd - ARCHIVED Filter for PINs with Flood Factor ≥ 5; analyze post-2023 PTAX-245 flood appeals; calculates AV changes in affected land blocks. Mapped berwyn and cicero Parcel universe API, PTAX-245 appeal forms Summary tables and figures Exploratory & Descriptive Analysis Assessed Value No NA
make_panel_data.qmd - ARCHIVED Combine files created by scripts. Combine data necessary for creating variables in models. Code for combining files was rough draft for creating data_prep.R script res_pins_ever.csv, sfha_indicator_pins.csv, Assessor_Parcel_Sales.csv, parcels_wFIRMs.csv, floodfactor_scores.csv singlefamily_assessed_values.csv, treated.csv Data Preparation Scripts Assessed Value No Y
mcmillen_salescomparison.qmd reads in McMillens Sales Data parquet file from McMillen, Assessor_sales file from CCAO NA Exploratory & Descriptive Analysis Sales No NA
pull_addresses_pins_wo_ffscores.R Takes PINs that didn't have flood factor scores and pulls addresses to make searching flood factor score faster. Otherwise you have to search the PIN to get the address, and then search the address to get the Risk Score. missing_floodfactor_scores.xlsx, API for Cook County parcel addresses pins_with_some_addresses.csv Data Preparation Scripts NA Y - Q2 prep NA
pull_distinct_ resPINs.R Extract all parcels that were residential from 2006–2023 and pull assessed values PTAXSIM database data/raw/residential_pins_ever.csv, pin_muni_key.csv, muniname_taxcode_key.csv Data Preparation Scripts Assessed Value Y NA
pull_floodfactor _pin_list.R Join Flood Factor risk scores (2019 snapshot) to Cook County parcel universe Parcel universe with PINs, Flood Factor data data/raw/floodfactor_scores.csv, data/processed/floodfactor_scores.csv Data Preparation Scripts NA Y - Q2 NA
pull_individual_ assistance_applicants.R Pull FEMA Individual Assistance (IA) application data for Cook County (accepted and denied) FEMA IA API data/raw/indiv_assistance_CookCounty.csv, data/processed/treated_zipcodes.csv Other External Data Exploration NA dropped - q3 NA
pull_NFIP_ redactedclaims.R Pull NFIP policy and claims data for Cook County from FEMA API NFIP Policies API, NFIP Claims API data/raw/nfippolicies_CookCounty_all.csv, data/raw/nfipclaims_CookCounty.csv Other External Data Exploration NA dropped - q3 NA
pull_parcel_sfs.R Download and convert Cook County parcel shapefiles for 2018 and 2023 ptaxsim parcel centroids S_FIRM_PAN.csv, parcels_wFIRMS.csv Data Preparation Scripts NA NA Y
shapefile_sfha_changes.R Compares CCAO flood variables to NFHL. Makes shapefiles and also CSV versions of PINs that are in each SFHA or LOMR NFHL 2018 and NFHL 2024 (NFHL_17_20180129.gdb, Statewide_NFHL_17_20240628.gdb) sfha_indicator_pins.csv, S_FIRM_PAN.csv, parcels_sfha_2018.csv(shp), parcels_lomrs_2018.csv(shp), sfha_pins_2024.csv, lomr_pins_2024.csv, Data Preparation Scripts NA NA Y
waterbasins_map.R Makes visualization of cook county with rivers and water basins. Not actually used for dissertation. Water Basins shapefiles online. River shapefiles NA Other External Data Exploration NA No N
2_create_datasets.qmd Creates df_prep and df_pairs for files that run the models. Reads in sales data and turns it into repeat sales data format res_sales.rds, pin_muni_key.csv, muni_shortnames.xlsx df_pairs.RDS, ff_pairs.RDS, df_prep.RDS Data Preparation Scripts Sales NA NA
3_check_assumptions Check for parallel trends for models NA NA Analysis NA NA NA
Question1 NA NA NA Analysis NA NA NA
Question2 NA NA NA NA NA NA NA
Question3 NA city_name_mapping.csv, FEMA API for individual assistance NA NA NA dropped - q3 NA
data_prep_buildings.R NA NA NA NA NA NA NA
didFF_test.R Implied density tests of distributional parallel trends. Saves model and plot output because it takes a long time to run. df_prep_buildings.RDS outputs/didFF_model_out.rds, outputs/didFF_plot_out.rds, outputs/didFF_model_out2.rds, outputs/didFF_plot_out2.rds Data Preparation Scripts Sales NA NA
q1_assumption_tests.qmd NOT USED 11/23/2025: use `did` packageto by Callaway & Sant'Anna but didn't do treatment within the cohorts. Instead it just compared pre and post event trends of the cohorts, where it ran the models as if each cohort was treated. NA NA Data Preparation Scripts Sales NA NA
Question1_continued_staggered.qmd Compares Fixed Effects models for question 1 to fixest::sunab() estimates. Creates staggered treatment plots and staggered model estimates for Question 1. df_prep_buildings.RDS NA Analysis NA NA NA
comparison_2variables.R uses high_ff _post variable df_prep_bldg_v2026_03.RDS outputs/compared_by2variables.rds NA NA Y - Q2 NA
comparison_3variables.R splits high_ff_score & post variable df_prep_bldg_v2026_03.RDS outputs/compared_by3variables.rds NA NA Y - Q2 NA

Output Files

Output Created By
data/raw/parcels_2018.gpkg pull_parcel_sfs.R
data/raw/parcels_2023.gpkg pull_parcel_sfs.R
data/raw/nfippolicies_CookCounty_all.csv pull_NFIP_redactedclaims.R
data/raw/nfipclaims_CookCounty.csv pull_NFIP_redactedclaims.R
data/raw/indiv_assistance_CookCounty.csv pull_individual_assistance_applicants.R
data/raw/residential_pins_ever.csv pull_distinct_resPINs.R
data/raw/pin_muni_key.csv pull_distinct_resPINs.R
data/raw/muniname_taxcode_key.csv pull_distinct_resPINs.R
data/raw/pins_floodfactor_2019.csv pull_floodfactor_pin_list.R
processed/ treated.csv make_panel_data.qmd
raw/floodfactor_scores.csv pull_floodfactor_pin_list.R
outputs/nbh_pins_parceluniversepull2022.csv ??
outputs/pins_in_Blocks_2006_2023_20241126.csv ??

Data Cleaning Notes

Do filtering steps last. Keep all property classes until creating the panel dataset for analysis.


Create a long-format dataset with:

PIN | year | in_sfha | flood_factor_score | in_lomr | av | sale_price | sold | treatment | post

Key Variables:

  • year: Matching the time of assessment or sale

  • in_sfha: 0/1 for floodplain presence that year

  • flood_factor_score: Ordinal flood risk score (e.g., 1–10)

  • in_lomr: 0/1 if parcel is in a LOMR revision area that year

  • av: Assessed value that year

  • sale_price: Sale price (if sold that year)

  • sold: 0/1 if there was a sale

  • treatment: 1 if the PIN was ever added to (or removed from) the SFHA (i.e., eligible for treatment)

  • post: 1 if observation is after the map change

  • added_to_sfha = (in_sfha_2024 == 1 & in_sfha_2018 == 0) removed_from_sfha = (in_sfha_2024 == 0 & in_sfha_2018 == 1)

  • treatment = 1 if added_to_sfha | removed_from_sfha

If you’re using multiple years of sales and assessed values, define:

  • post = 1 for all years after the map change

  • pre = 1 for years before

Optionally use event_time = year - treatment_year to do event study style DiD

Source Code
---
title: "File Overview"
format: # html
  html:
    page-layout: full
    code-fold: true
    #toc: true
    #toc-location: left
---

## Project: Flood Risk and Property Values

```{r}
library(tidyverse)
library(glue)
library(kableExtra)
library(stringr)

files <- readxl::read_xlsx("readme_file_information.xlsx")
```

```{r eval = FALSE, include = FALSE}
files <- files %>% 
  mutate(
    # turn any literal newline into a comma
    Inputs_clean  = str_replace_all(Inputs,  "\\s*\\n\\s*",  ", "),
    Outputs_clean = str_replace_all(Outputs, "\\u00A0",   ""),           # drop NBSP
    Outputs_clean = str_replace_all(Outputs_clean,  "\\s*\\n\\s*", ", ")
  )

```
```{r eval=FALSE, results='asis', include = FALSE}
files %>% 
  mutate(
    # split your comma-separated text into character vectors
    Inputs_list  = str_split(Inputs,  ",\\s*"),
    Outputs_list = str_split(Outputs, ",\\s*"),
    
    # build the markdown string for each row
    markdown = pmap_chr(
      list(
        idx    = row_number(),
        file   = File,
        purpose= Purpose,
        in_lst = Inputs_list,
        out_lst= Outputs_list,
        status = `Analysis Step`
        ),
      function(idx, file, purpose, in_lst, out_lst, status) {
        glue("
### {idx}. `{file}`  
**Purpose:**  
{purpose}

**Inputs:**  

- {paste(in_lst, collapse = '\n- ')}

**Outputs:**  

- {paste(out_lst, collapse = '\n- ')}

**Analysis Step:** {status}
")
      }
    )
  ) %>% 
  pull(markdown) %>% 
  cat(sep = "\n\n")

```

```{r results='asis'}
files |> 
  select(File, Purpose, Inputs, Outputs, `Analysis Step`) |>
  mutate(markdown = glue::glue("
### {row_number()}. `{File}`  
**Purpose:**  
{Purpose}  

**Inputs:**   

- {str_replace_all(Inputs, ', ', '\n- ')}  

**Outputs:**  

- {str_replace_all(Outputs, ', ', '\n- ')}  
")) |> 
  pull(markdown) |> 
  cat(sep = "\n\n")
```

```{r}
#| label: tbl-kabletable
#| tbl-colwidths: [15, 40, 10, 10, 10]


#DT::datatable(files)


files |> kable(booktabs = TRUE) |> #kable_paper(full_width = F) |>
  column_spec(1, width = "1in") |>
  column_spec(2, width = "3in") |>
  column_spec(3, width = "1in") |>
  column_spec(4, width = "1in") |>
  column_spec(5, width = "1in")
  
```

### Output Files


| Output                                                             | Created By                                |
|--------------------------------------------------------------------|-------------------------------------------|
| `data/raw/parcels_2018.gpkg`                                       | `pull_parcel_sfs.R`                       |
| `data/raw/parcels_2023.gpkg`                                       | `pull_parcel_sfs.R`                       | `data/processed/parcels_wFIRMs.csv`                                | `pull_parcel_sfs.R`                       | outputs/pins_in_Blocks_2006_2023_20241126.csv" | ?? |
|
| `data/raw/nfippolicies_CookCounty_all.csv`                         | `pull_NFIP_redactedclaims.R`              |
| `data/raw/nfipclaims_CookCounty.csv`                               | `pull_NFIP_redactedclaims.R`              |
| `data/raw/indiv_assistance_CookCounty.csv`                         | `pull_individual_assistance_applicants.R` |
| `data/raw/residential_pins_ever.csv`                               | `pull_distinct_resPINs.R`                 |
| `data/raw/pin_muni_key.csv`                                        | `pull_distinct_resPINs.R`                 |
| `data/raw/muniname_taxcode_key.csv`                                | `pull_distinct_resPINs.R`                 |
| `data/raw/pins_floodfactor_2019.csv`                               | `pull_floodfactor_pin_list.R`             |
| processed/ treated.csv                                                        | `make_panel_data.qmd`                     |
| raw/floodfactor_scores.csv | pull_floodfactor_pin_list.R |
| outputs/nbh_pins_parceluniversepull2022.csv | ?? |
| outputs/pins_in_Blocks_2006_2023_20241126.csv| ?? |

```{r, include=FALSE, eval=FALSE}

## Keeping just in case

### Data Preparation Scripts



| File | Purpose | Inputs | Outputs |
|-------|-----------------|-----------------|---------------------|
| `pull_distinct_resPINs.R` | Extract all parcels that were residential from 2006–2023 and pull assessed values | PTAXSIM database | `data/raw/residential_pins_ever.csv`, `pin_muni_key.csv`, `muniname_taxcode_key.csv` |
| `pull_parcel_sfs.R` | Download and convert Cook County parcel shapefiles for 2018 and 2023 | ptaxsim parcel centroids | `S_FIRM_PAN.csv`, `parcels_wFIRMS.csv` |
| `pull_floodfactor` `_pin_list.R` | Join Flood Factor risk scores (2019 snapshot) to Cook County parcel universe | Parcel universe with PINs, Flood Factor data | `data/raw/floodfactor_scores.csv` |
| `shapefile_sfha_changes.R` | Compares CCAO flood variables to NFHL. Makes shapefiles and also CSV versions of PINs that are in each SFHA or LOMR | NFHL 2018 and NFHL 2024 (NFHL_17_20180129.gdb and Statewide_NFHL_17_20240628.gdb) | sfha_indicator_pins.csv, S_FIRM_PAN.csv, parcels_sfha_2018.csv(shp), parcels_lomrs_2018.csv(shp), sfha_pins_2024.csv, lomr_pins_2024.csv, |
| `detect_flood_variable` `_change_in_CCAO` | Tries to identify if CCAO removed PINs that were in LOMRs from SFHA indicator or what year they stopped updating the LOMR data if removed | Open FEMA API | None |
| `clean_damangedCity` `_names` | Takes damagedCity variable from Open FEMA individual assistance, exports city names which had tons of typos. This was put in chatGPT to match with clean names | Open FEMA API | `data/raw/ia.city_names.csv` which becomes `data/processed/City_Mapping_Names.csv` |

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

### Other External Data Exploration

| File | Purpose | Inputs | Outputs |
|-----------------|---------------------|-----------------|-----------------|
| `pull_NFIP_redactedclaims.R` | Pull NFIP policy and claims data for Cook County from FEMA API | NFIP Policies API, NFIP Claims API | `data/raw/nfippolicies_CookCounty_all.csv`, `data/raw/nfipclaims_CookCounty.csv` |
| `pull_individual_assis` `tance_applicants.R` | Pull FEMA Individual Assistance (IA) application data for Cook County (accepted and denied) | FEMA IA API | `data/raw/indiv_assistance_CookCounty.csv`, `data/processed/treated_zipcodes.csv`|
| `buyouts.R` | Identifies PINs that were bought out due to high flood risk | Illinois Buyout Database `BuyoutPoints_Statewide.xlsx` | none |

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

### Exploratory & Descriptive Analysis

| File | Purpose | Inputs | Outputs |
|-----------------|----------------------|-----------------|-----------------|
| `CC_Individual_FEMA` `_Assistance.qmd` | Analyzes FEMA IA aid at ZIP level during recent flood events; descriptive stats on applicants and aid granted | `data/raw/indiv_assistance_CookCounty.csv`, `data/processed/treated_zipcodes.csv` | census block, tract, zip code, and muni level post-disaster aid data |
| `Cook_flood_policies` `_and_claims.qmd` | Summarizes NFIP claims and policies across geographies (ZIP, block, tract, muni) | `data/raw/nfipclaims_CookCounty.csv`, `data/raw/nfippolicies_CookCounty_all.csv` | Aggregated claim/policy stats. Not used except to show that there are not many claims or insurance policies in cook county. But there are a lot of post-disaster FEMA aid. |
| `Cook_Sales_data.qmd` | Links sales data with flood risk indicators (SFHA, LOMR, Flood Factor); identifies multi-sale parcels and treatment status | `data/raw/assessor_parcel_sales.csv`, `parcels_sfha_2018.gpkg`, `parcels_sfha_2024.gpkg`, `parcels_lomrs.gpkg`, `data/raw/pins_floodfactor_2019.csv` | Counts of PINs by treatment status, sales trends |
| `make_panel_data.qmd` | | | |
| AssessedValues_ andFIRMS.qmd | | | | 
| descriptive_stats _singlefam.qmd | | | | 
| mcmillen_sales comparison.qmd | | | | 
| `Flood_factor_pins.qmd` ARCHIVED | Filter for PINs with Flood Factor ≥ 5; analyze post-2023 PTAX-245 flood appeals; calculates AV changes in affected land blocks | Parcel universe API, PTAX-245 appeal forms | Summary tables and figures |
| `Flood_Appeal_PINs.qmd` ARCHIVED | Identifies and summarizes AV appeal activity for PINs affected by 2023 flood; compares AV changes for appeal vs. neighbor parcels | PTAX-245 appeal forms, assessed values | Graphs of average AV changes, summary stats |
| `AssessedValue_Explor` `atoryGraphs.rmd` ARCHIVED | Early exploration of AV trends in SFHA and flood-prone parcels using CCAO data | Parcel universe, AV data | Exploratory graphs and maps |
| `CookCounty_ParcelMaps.qmd` ARCHIVED | Early mapping of parcels marked SFHA in CCAO data; not currently used | CCAO parcel universe | Static SFHA parcel maps |


```

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

### Data Cleaning Notes

Do filtering steps last. Keep all property classes until creating the panel dataset for analysis.

```{r eval=FALSE, include=FALSE}

## File Overview




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

### X. `Models.qmd.R`

**Purpose:**\
Based off of cook_sales_Data.qmd but removes a lot of the preliminary coding chunks

**Output:**\


**Status:** Active - update and use more

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

### X. `descriptive_stats_singlefam.qmd`

**Purpose:**\
has checklist of variables/code that needs to be done

**Output:**\


**Status:** Active ? Use more!

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

### 1. `pull_distinct_resPINs.R`

**Purpose:**\
Extracts PINs that were residential at any time (2006–2023) using PTAXSIM and pulls corresponding assessed values. Also generates PIN–municipality key.

**Output:**\
- `data/raw/residential_pins_ever.csv`\
- `data/raw/pin_muni_key.csv`\
- `data/raw/muniname_taxcode_key.csv`

**Status:** Active

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

### 2. `pull_parcel_sfs.R`

**Purpose:**\
Downloads parcel shapefiles for Cook County for two time points: 2018 and 2023. Converts shapefiles into spatial databases.

**Output:**\
- ~~`data/raw/parcels_2018.gpkg`~~\
- ~~`data/raw/parcels_2023.gpkg`~~\
- S_FIRM_PAN.csv\
- parcels_wFIRMS.csv

**Status:** Active

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

### 5. `pull_floodfactor_pin_list.R`

**Purpose:**\
Pulls 2019 Flood Factor scores and SFHA indicator used by Assessor from parcel universe.

**Output:**\
- `data/raw/floodfactor_scores.csv` with variables `env_flood_factor_score`, `env_flood_factor_risk_direction`, `env_flood_fema_sfha`, and `nbhd_code` for the neighborhoods used by the Assessor during property valutation.

**Status:** Active

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

### 6. `Flood_factor_pins.qmd`

**Purpose:**\
Filters for PINs with Flood Factor ≥ 5; integrates PTAX-245 appeal data after the 2023 flood; calculates differences in AV before and after appeals in affected land blocks.

**Output:**\
- Summary tables and figures on AV changes from appeals

**Status:** Archived

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

### 7. `Flood_Appeal_PINs.qmd`

**Purpose:**\
Identifies PINs that submitted PTAX-245 forms after the 2023 flood and compares changes in AV due to appeals across affected and nearby properties.

**Output:**\
- Graphs and summary tables of AV differences

**Status:** Archived

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

### 8. `CC_Individual_FEMA_Assistance.qmd`

**Purpose:**\
Summarizes FEMA IA data by ZIP code. Focuses on descriptive statistics and trends for recent flood events and aid received.
Identifies treated areas of Cook County that experienced flood damage using post-disaster aid data.

**Input:**\
- `data/raw/indiv_assistance_CookCounty.csv`

**Output:**\
- ZIP-level descriptive statistics\
- Summary tables and visualizations by event  
- `data/processed/treated_zipcodes.csv`  


**Status:** Active

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

### 9. `Cook_flood_policies_and_claims.qmd`

**Purpose:**\
Uses NFIP policy and claim data to summarize flood damage at various geographies (ZIP code, census block, census tract, municipality).

**Input:**\
- `data/raw/nfipclaims_CookCounty.csv`\
- `data/raw/nfippolicies_CookCounty_all.csv`

**Output:**\
- Aggregated stats by spatial unit

**Status:** Active

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

### 10. `Cook_Sales_data.qmd`

**Purpose:**\
Integrates sales data with SFHA, LOMR, and Flood Factor overlays. Identifies PINs sold multiple times and tracks treatment exposure.
Models.qmd is based off of this file.

**Input:**\
- `parcels_wFIRMs.csv`
- `data/raw/assessor_parcel_sales.csv`\
- `pin_muni_key.csv`\ 
- `parcels_sfha_2018.shp`\
- `parcels_sfha_2024.shp`\
- `parcels_lomrs_2024.shp` becomes `lomr_pins_2024.csv`\
- `data/raw/pins_floodfactor_2019.csv`\
- nbh_pins_parceluniversepull2022.csv\
- Parcels_in_PrelimFIRMSFHA_NWCook.xlsx\

**Output:**\
- Summary of sales by treatment group\
- Stats on repeat sales and exposure

**Status:** Active? Archived? 

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

### 11. `AssessedValue_andFIRMs.qmd`

**Purpose:**\
Early exploration of AV trends for parcels inside and outside SFHAs using CCAO data. Includes preliminary figures and mapping.
Codes PINs by if they have a building on the parcel or not. 

**Input:**\
- Parcel universe\
- AV data

**Output:**\
- `outputs/pins_in_Blocks_2006_2023_20241126.csv`


**Status:** New but not used?

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

### 11. `AssessedValue_ExploratoryGraphs.rmd`

**Purpose:**\
Early exploration of AV trends for parcels inside and outside SFHAs using CCAO data. Includes preliminary figures and mapping.
Codes PINs by if they have a building on the parcel or not. 

**Input:**\
- Parcel universe\
- AV data

**Output:**\
- Exploratory maps and graphs of AV trends by risk status  
- `outputs/pins_in_Blocks_2006_2023_20241126.csv`  

**Status:** Archived

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

### 12. `CookCounty_ParcelMaps.qmd`

**Purpose:**\
Initial mapping of parcels marked SFHA using CCAO parcel universe. Made for exploratory purposes and currently unused.

**Input:**\
- CCAO parcel universe

**Output:**\
- Parcel maps with SFHA indicators

**Status:** Archived

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

### 2. `pull_NFIP_redactedclaims.R`

**Purpose:**\
Pulls National Flood Insurance Program (NFIP) claims and policy data from FEMA’s open API, filtered to Cook County, IL.

**Output:**\
- `data/raw/nfippolicies_CookCounty_all.csv`\
- `data/raw/nfipclaims_CookCounty.csv`

**Status:** Active

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

### 3. `pull_individual_assistance_applicants.R`

**Purpose:**\
Downloads FEMA Individual Assistance (IA) data from the OpenFEMA API for Cook County. Includes both approved and denied applications.

**Output:**\
- `data/raw/indiv_assistance_CookCounty.csv`

**Status:** Active

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

### X. `DAG_chart.qmd`

**Purpose:**\
had variable dag charts 

**Output:**\

**Status:** Not Used

```

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


Create a long-format dataset with:

PIN \| year \| in_sfha \| flood_factor_score \| in_lomr \| av \| sale_price \| sold \| treatment \| post

Key Variables:

-   year: Matching the time of assessment or sale

-   in_sfha: 0/1 for floodplain presence that year

-   flood_factor_score: Ordinal flood risk score (e.g., 1–10)

-   in_lomr: 0/1 if parcel is in a LOMR revision area that year

-   av: Assessed value that year

-   sale_price: Sale price (if sold that year)

-   sold: 0/1 if there was a sale

-   treatment: 1 if the PIN was ever added to (or removed from) the SFHA (i.e., eligible for treatment)

-   post: 1 if observation is after the map change

-   added_to_sfha = (in_sfha_2024 == 1 & in_sfha_2018 == 0) removed_from_sfha = (in_sfha_2024 == 0 & in_sfha_2018 == 1)

-   treatment = 1 if added_to_sfha \| removed_from_sfha

If you're using multiple years of sales and assessed values, define:

-   post = 1 for all years after the map change

-   pre = 1 for years before

Optionally use event_time = year - treatment_year to do event study style DiD