Join 10350+ others. No spamming.
I promise!

Follow us at github.



toddwschneider / agency-loan-level


Loan-level analysis of Fannie Mae and Freddie Mac data


Create a PostgreSQL database with loan-level data from Fannie Mae and Freddie Mac

Scripts used in support of this post: Mortgages Are About Math: Open-Source Loan-Level Analysis of Fannie and Freddie


  1. Make sure you have PostgreSQL installed locally. If you want to use R, install it too
  2. Download data from Fannie Mae and/or Freddie Mac and unzip all files into a directory with fannie/ and freddie/ subdirectories
  3. Make sure to update the proper /path/to/ paths in, create_loans_and_supporting_tables.sql, and
  4. ./ creates a Postgres database called agency-loan-level, creates some tables, and imports supporting data including FHFA home price data and Freddie Mac mortgage rate data
  5. ./db_scripts/ to import the data files. This might take a very long time (~2 days), so you could consider loading the data in chunks. The total database takes up around 215 GB on disk


The analysis/ folder has additional SQL and R scripts used to analyze the data, see more in the full post