{
 "name": "Conversion rules: SBA 7(a), SBA 504 and HMDA records into one loan schema",
 "version": "r1",
 "as_of_date": "2026-09-30",
 "sources": {
  "7A": {"file": "FOIA_7a_FY2020_Present_asof_260930.csv", "segment": "commercial", "lender_fields": ["LocationID", "BankName", "BankFDICNumber"]},
  "504": {"file": "FOIA_504_FY2010_Present_asof_260930.csv", "segment": "commercial", "lender_fields": ["LocationID", "CDC_Name"]},
  "HMDA": {"file": "hmda_2017_mt_all-records_labels.csv", "segment": "residential", "lender_fields": ["agency_code", "respondent_id"]}
 },
 "key": {
  "loan_id": "source system, a dash, then the 1-based data row number in the source file (no source carries a loan number)",
  "duplicates": "keep every source row; rows identical in every field are kept and flagged, because without a loan number two identical rows may be two loans"
 },
 "units": {
  "7A.GrossApproval": 1,
  "7A.SBAGuaranteedApproval": 1,
  "7A.GrossChargeOffAmount": 1,
  "7A.InitialInterestRate": 0.01,
  "504.GrossApproval": 1,
  "504.GrossChargeOffAmount": 1,
  "504.ThirdPartyDollars": 1,
  "HMDA.loan_amount_000s": 1000,
  "HMDA.applicant_income_000s": 1000
 },
 "status_map": {
  "7A": {"COMMIT": "undisbursed", "EXEMPT": "active", "P I F": "paid_in_full", "CHGOFF": "charged_off", "CANCLD": "cancelled"},
  "504": {"NOT FUNDED": "undisbursed", "EXEMPT": "active", "PIF": "paid_in_full", "CHGOFF": "charged_off", "CANCLD": "cancelled", "CLOSED": "closed_other"},
  "HMDA": {"1": "originated", "2": "approved_not_accepted", "3": "denied", "4": "withdrawn", "5": "incomplete", "6": "purchased", "7": "denied", "8": "approved_not_accepted"}
 },
 "record_kind_map": {
  "HMDA": {"1": "loan", "2": "application", "3": "application", "4": "application", "5": "application", "6": "loan", "7": "application", "8": "application"}
 },
 "revolver_map": {"7A": {"N": false, "Y": true}},
 "rate_type_map": {"7A": {"F": "fixed", "V": "variable"}},
 "loan_type_map": {"HMDA": {"1": "conventional", "2": "fha", "3": "va", "4": "fsa_rhs"}},
 "coded_fields": [
  ["7A", "LoanStatus", "status_map"],
  ["504", "LoanStatus", "status_map"],
  ["HMDA", "action_taken", "status_map"],
  ["HMDA", "action_taken", "record_kind_map"],
  ["7A", "RevolverStatus", "revolver_map"],
  ["7A", "FixedorVariableInterestInd", "rate_type_map"],
  ["HMDA", "loan_type", "loan_type_map"]
 ],
 "fields": [
  {"target": "loan_id", "type": "varchar", "7A": "key", "504": "key", "HMDA": "key"},
  {"target": "source_system", "type": "varchar", "7A": "'7A'", "504": "'504'", "HMDA": "'HMDA'"},
  {"target": "source_row", "type": "integer", "7A": "row number", "504": "row number", "HMDA": "row number"},
  {"target": "segment", "type": "varchar", "7A": "'commercial'", "504": "'commercial'", "HMDA": "'residential'"},
  {"target": "record_kind", "type": "varchar", "7A": "'loan'", "504": "'loan'", "HMDA": "record_kind_map[action_taken]"},
  {"target": "status", "type": "varchar", "7A": "status_map[LoanStatus]", "504": "status_map[LoanStatus]", "HMDA": "status_map[action_taken]"},
  {"target": "product", "type": "varchar", "7A": "ProcessingMethod as written", "504": "ProcessingMethod as written", "HMDA": "loan_type_map[loan_type]"},
  {"target": "origination_date", "type": "date", "7A": "ApprovalDate (YYYY-MM-DD)", "504": "ApprovalDate (YYYY-MM-DD)", "HMDA": "null (the public file has no date)"},
  {"target": "fiscal_year", "type": "integer", "7A": "ApprovalFY", "504": "ApprovalFY", "HMDA": "null"},
  {"target": "origination_year", "type": "integer", "7A": "year of ApprovalDate", "504": "year of ApprovalDate", "HMDA": "as_of_year"},
  {"target": "principal_usd", "type": "decimal(14,2)", "7A": "GrossApproval x unit", "504": "GrossApproval x unit", "HMDA": "loan_amount_000s x unit"},
  {"target": "guaranteed_usd", "type": "decimal(14,2)", "7A": "SBAGuaranteedApproval x unit", "504": "null", "HMDA": "null"},
  {"target": "third_party_usd", "type": "decimal(14,2)", "7A": "null", "504": "ThirdPartyDollars x unit", "HMDA": "null"},
  {"target": "rate_decimal", "type": "double", "7A": "InitialInterestRate x unit", "504": "null", "HMDA": "null"},
  {"target": "rate_type", "type": "varchar", "7A": "rate_type_map[FixedorVariableInterestInd]", "504": "null", "HMDA": "null"},
  {"target": "term_months", "type": "integer", "7A": "TermInMonths", "504": "TermInMonths", "HMDA": "null"},
  {"target": "is_revolver", "type": "boolean", "7A": "revolver_map[RevolverStatus]", "504": "false", "HMDA": "false"},
  {"target": "paid_in_full_date", "type": "date", "7A": "PaidInFullDate", "504": "PaidInFullDate", "HMDA": "null"},
  {"target": "chargeoff_date", "type": "date", "7A": "ChargeOffDate", "504": "ChargeOffDate", "HMDA": "null"},
  {"target": "chargeoff_usd", "type": "decimal(14,2)", "7A": "GrossChargeOffAmount x unit", "504": "GrossChargeOffAmount x unit", "HMDA": "null"},
  {"target": "lender_key", "type": "varchar", "7A": "'SBA-' || LocationID", "504": "'SBA-' || LocationID", "HMDA": "'HMDA-' || agency_code || '-' || respondent_id"},
  {"target": "lender_name", "type": "varchar", "7A": "BankName", "504": "CDC_Name", "HMDA": "panel Respondent Name for (agency_code, respondent_id)"},
  {"target": "lender_fdic_cert", "type": "integer", "7A": "BankFDICNumber", "504": "null", "HMDA": "null"},
  {"target": "borrower_state", "type": "varchar", "7A": "BorrState", "504": "BorrState", "HMDA": "state_abbr"},
  {"target": "borrower_zip5", "type": "varchar", "7A": "first 5 of BorrZip", "504": "first 5 of BorrZip", "HMDA": "null"},
  {"target": "applicant_income_usd", "type": "decimal(14,2)", "7A": "null", "504": "null", "HMDA": "applicant_income_000s x unit"},
  {"target": "sold_secondary", "type": "boolean", "7A": "SoldSecMrktInd = 'Y'", "504": "null", "HMDA": "purchaser_type in 1 to 9"},
  {"target": "exact_duplicate", "type": "boolean", "7A": "row identical in every field to an earlier row", "504": "same", "HMDA": "same"}
 ],
 "rounding": "amounts are parsed as decimals, multiplied by their unit and rounded to the cent, half away from zero (amendment A1)",
 "lender_lookup": "a LEFT join: a loan whose lender is missing from a lookup keeps its row and gets a null in the looked-up field",
 "empty_values": "an empty string is null; HMDA 'NA' and blank are null; numbers are parsed after removing nothing (no thousands separators occur)",
 "access": "borrower name and street are not carried into the target; analysts read the target; the raw source files are readable by the conversion team only"
}
