"""Study: retirement plans with almost no workers left, 2009-2025 (PRD 5.134; rules frozen in docs/linkage/zombie_study_prereg.md before any count). Every published figure comes from this file's outputs. A defined contribution plan cannot close until it pays out everyone with a balance. This finds the plans that keep filing for years with almost no current employees while former workers' balances stay in them. DC plan a defined-contribution feature code (2 + letter); ESOPs (2O, 2P, 2Q) excluded plan-year a Form 5500 or 5500-SF with active participants and participants with account balances; latest filing per year. The index has no active count for the 5500-SF, so for short-form filings it comes from the Labor Department's F_5500_SF "Latest" file of that plan year (SF_TOT_ACT_PARTCP_EOY_CNT), joined by acknowledgement ID (amendment 1 of the pre-registration) zombie year active <= 5% of participants with balances, at least 5 with balances, not a final report zombie plan 3 or more consecutive zombie years (longest run; ties: latest) stuck mean yearly exit of balance holders in the run under 25% data error more balance holders at the end of the run than at its start: excluded current the run's last year is 2023 or later Outputs in OUT_DIR: summary.json (every figure), plans.csv (the current stuck plans whose employer has no plan with workers, the only group named), plans_internal.csv (every zombie plan with its flags; not published), lookup.json (the 25 current stuck plans with the most balance holders, administrator as filed), validation.json (V1, V2, V4). Post-hoc split (amendments 2 and 3), for the current stuck plans: multi-employer or collectively bargained (plan entity code 2 or 3, or the bargaining mark, on the run's last filing, from the Labor Department's F_5500 or F_5500_SF file), inconsistent filing (under $100 of net assets per participant with a balance), employer still has workers (another plan under the same employer ID reported at least 5 active participants, more than 5% of its participants, in the run's last year), or employer has no plan with workers. Only the last group is named in lookup.json. Usage: python -I tools/zombie_study.py DB OUT_DIR SF_ZIP_DIR F5500_ZIP_DIR (DOL "Latest" zips, one per plan year) """ import csv import glob import io import zipfile import json import os import re import sqlite3 import statistics import sys db, out, sfdir, f5dir = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4] os.makedirs(out, exist_ok=True) PY0, PY1, SHARE, MIN_BAL, RUN, STUCK, CURRENT, TOP = 2009, 2025, 0.05, 5, 3, 0.25, 2023, 25 ESOP = ("2O", "2P", "2Q") c = sqlite3.connect(f"file:{db}?mode=ro", uri=True) built = dict(c.execute("select k, v from meta")).get("built", "") def is_dc(codes: str | None) -> bool: codes = codes or "" found = re.findall(r"[1-4][A-Z]", codes) return any(x.startswith("2") for x in found) and not any(x in ESOP for x in found) plans = {r[0]: r for r in c.execute("""select plan_id, ein, pn, plan_name, sponsor, city, state, biz_code, pension_codes, admin_name, admin_city, admin_state from plans""") if is_dc(r[8])} def sf_active(folder: str) -> tuple[dict, set, list, set]: """Active participants at year end for 5500-SF filings, by acknowledgement ID. Exact counts are kept for filings that could be a zombie year (active <= 5% of balances, by the file's own balance count); every other filing in the file is recorded as measured and not a zombie year. Returns (ack -> active, hashes of every ack in the files, years read, hashes of the acks of working plans: at least 5 active, more than 5% of balances or, without balances, participants).""" low, seen, read, work = {}, set(), [], set() for z in sorted(glob.glob(os.path.join(folder, "*.zip"))): with zipfile.ZipFile(z) as zf: name = next(n for n in zf.namelist() if n.lower().endswith(".csv") and "layout" not in n.lower()) with zf.open(name) as fh: rd = csv.reader(io.TextIOWrapper(fh, encoding="latin-1", newline="")) head = [h.strip().upper() for h in next(rd)] if "SF_TOT_ACT_PARTCP_EOY_CNT" not in head: continue ia, iact, ib = head.index("ACK_ID"), head.index("SF_TOT_ACT_PARTCP_EOY_CNT"), head.index("SF_PARTCP_ACCOUNT_BAL_CNT") it = head.index("SF_TOT_PARTCP_EOY_CNT") if "SF_TOT_PARTCP_EOY_CNT" in head else None read.append(os.path.basename(z)) for row in rd: try: act = float(row[iact]) if row[iact].strip() else None bal = float(row[ib]) if row[ib].strip() else None except (ValueError, IndexError): continue if act is None: continue seen.add(hash(row[ia].strip())) if bal is not None and act <= SHARE * bal: low[row[ia].strip()] = act try: base = bal if bal else (float(row[it]) if it is not None and row[it].strip() else 0) except ValueError: base = 0 if act >= 5 and act > SHARE * base: work.add(hash(row[ia].strip())) return low, seen, read, work SF_LOW, SF_SEEN, SF_READ, SF_WORK = sf_active(sfdir) BIG_ACTIVE = float("inf") # measured on the short form, not a zombie year years: dict = {} for pid, py, rid, active, bal, eoy, final, ack, form in c.execute( """select plan_id, py, rowid, active, acct_bal, net_assets_eoy, final, ack_id, form from plan_years where form in ('5500', 'SF') and py between ? and ? and acct_bal is not null""", (PY0, PY1)): if form == "SF": active = SF_LOW.get(ack, BIG_ACTIVE if hash(ack) in SF_SEEN else None) if active is None: continue if pid in plans: cur = years.setdefault(pid, {}).get(py) if cur is None or rid > cur[0]: years[pid][py] = (rid, active, bal, eoy, final, ack) measured = len(years) abandoned = {r[0] for r in c.execute("select plan_id from abandoned_match")} def find(years: dict, py_max: int = PY1) -> list[dict]: """Every zombie plan under the frozen rule, using plan years up to py_max.""" out_rows = [] for pid, ys in years.items(): seq = sorted((py, v) for py, v in ys.items() if py <= py_max) runs, cur = [], [] for py, (rid, active, bal, eoy, final, ack) in seq: z = bal >= MIN_BAL and active <= SHARE * bal and str(final) != "1" if z and cur and py == cur[-1][0] + 1: cur.append((py, active, bal, eoy, ack)) elif z: if cur: runs.append(cur) cur = [(py, active, bal, eoy, ack)] else: if cur: runs.append(cur) cur = [] if cur: runs.append(cur) runs = [r for r in runs if len(r) >= RUN] if not runs: continue run = max(runs, key=lambda r: (len(r), r[-1][0])) exits = [(a[2] - b[2]) / a[2] for a, b in zip(run, run[1:]) if a[2]] mean_exit = sum(exits) / len(exits) if exits else 0.0 p = plans[pid] later = [py for py, v in seq if py > run[-1][0]] final_after = next((py for py, v in seq if py > run[-1][0] and str(v[4]) == "1"), None) out_rows.append({"plan_id": pid, "ein": p[1], "pn": p[2], "plan_name": p[3], "sponsor": p[4], "city": p[5], "state": p[6], "biz_code": p[7], "admin_name": p[9], "admin_city": p[10], "admin_state": p[11], "start": run[0][0], "end": run[-1][0], "years": len(run), "people_first": int(run[0][2]), "people_last": int(run[-1][2]), "active_last": int(run[-1][1]), "usd_last": run[-1][3], "mean_exit": round(mean_exit, 6), "stuck": int(mean_exit < STUCK), "data_error": int(run[-1][2] > run[0][2]), "current": int(run[-1][0] >= CURRENT), "last_ack": run[-1][4], "first_ack": run[0][4], "reports_after_run": len(later), "final_after_run": final_after, "abandoned_program": int(pid in abandoned)}) return out_rows rows = find(years) def entity_codes(acks: set) -> dict: """Plan entity code (1 single employer, 2 multiemployer, 3 multiple-employer) and the collective-bargaining mark of the given filings: ack -> (code, bargained).""" out_codes = {} for folder, col, cb in ((f5dir, "TYPE_PLAN_ENTITY_CD", "COLLECTIVE_BARGAIN_IND"), (sfdir, "SF_PLAN_ENTITY_CD", "COLLECTIVELY_BARGAINED")): for z in sorted(glob.glob(os.path.join(folder, "*.zip"))): with zipfile.ZipFile(z) as zf: name = next(n for n in zf.namelist() if n.lower().endswith(".csv") and "layout" not in n.lower()) with zf.open(name) as fh: rd = csv.reader(io.TextIOWrapper(fh, encoding="latin-1", newline="")) head = [h.strip().upper() for h in next(rd)] if col not in head: continue ia, ic = head.index("ACK_ID"), head.index(col) ib = head.index(cb) if cb in head else None for row in rd: a = row[ia].strip() if len(row) > ia else "" if a in acks and len(row) > ic: out_codes[a] = (row[ic].strip(), ib is not None and len(row) > ib and row[ib].strip().upper() in ("1", "Y", "YES", "TRUE")) return out_codes def employer_working(ein: str, pid: str, py: int) -> bool: """Another plan under the same employer ID reported working participants in that plan year.""" for opid, form, active, total, ack in c.execute( """select y.plan_id, y.form, y.active, y.total_partcp, y.ack_id from plan_years y join plans p using (plan_id) where p.ein = ? and y.plan_id != ? and y.py = ?""", (ein, pid, py)): if form == "SF": if hash(ack) in SF_WORK: return True elif active is not None and active >= 5 and active > SHARE * (total or 0): return True return False ENT = entity_codes({r["last_ack"] for r in rows if r["stuck"] and r["current"] and not r["data_error"]}) for r in rows: r["entity_code"], r["bargained"] = ENT.get(r["last_ack"], ("", False)) r["bargained"] = int(r["bargained"]) r["group"] = "" if r["stuck"] and r["current"] and not r["data_error"]: r["group"] = ("multi_employer_or_bargained" if r["entity_code"] in ("2", "3") or r["bargained"] else "inconsistent_filing" if (r["usd_last"] or 0) < 100 * r["people_last"] else "employer_has_workers" if employer_working(r["ein"], r["plan_id"], r["end"]) else "no_plan_with_workers") rows.sort(key=lambda r: (-r["people_last"], r["plan_id"])) PUBLIC = ("plan_id", "ein", "pn", "plan_name", "sponsor", "city", "state", "admin_name", "admin_city", "admin_state", "start", "end", "years", "people_first", "people_last", "active_last", "usd_last", "mean_exit", "first_ack", "last_ack", "abandoned_program") with open(os.path.join(out, "plans_internal.csv"), "w", newline="") as fh: # every zombie plan: for checking, not published w = csv.DictWriter(fh, fieldnames=list(rows[0].keys())) w.writeheader() w.writerows(rows) with open(os.path.join(out, "plans.csv"), "w", newline="") as fh: # the named group only (amendment 2) w = csv.DictWriter(fh, fieldnames=list(PUBLIC), extrasaction="ignore") w.writeheader() w.writerows(r for r in rows if r["group"] == "no_plan_with_workers") clean = [r for r in rows if not r["data_error"]] stuck = [r for r in clean if r["stuck"]] cur = [r for r in stuck if r["current"]] def pool(rs: list) -> dict: per = [r["usd_last"] / r["people_last"] for r in rs if r["usd_last"] is not None and r["people_last"]] return {"plans": len(rs), "people": sum(r["people_last"] for r in rs), "usd": float(sum(r["usd_last"] or 0 for r in rs)), "median_usd_per_person": round(statistics.median(per), 2) if per else None, "median_years": statistics.median([r["years"] for r in rs]) if rs else None} S = {"window": [PY0, PY1], "data_release": f"data-{built}", "rule": "docs/linkage/zombie_study_prereg.md", "sf_files_read": SF_READ, "measured_dc_plans": measured, "zombie_plans": len(rows), "data_errors": len(rows) - len(clean), "stuck_all": pool(stuck), "current_stuck": pool(cur), "not_stuck": len(clean) - len(stuck), "ended_after_run": {"plans": sum(1 for r in stuck if not r["current"]), "later_final_report": sum(1 for r in stuck if not r["current"] and r["final_after_run"])}} by_state: dict = {} for r in cur: t = by_state.setdefault(r["state"] or "", []) t.append(r) S["current_stuck_by_state"] = sorted(({"state": k, **pool(v)} for k, v in by_state.items()), key=lambda x: -x["people"]) NAICS = {"62": "Health care and social assistance", "31": "Manufacturing", "32": "Manufacturing", "33": "Manufacturing", "52": "Finance and insurance", "54": "Professional, scientific and technical services", "44": "Retail", "45": "Retail", "42": "Wholesale trade", "23": "Construction", "48": "Transportation", "49": "Transportation", "51": "Information", "61": "Educational services", "56": "Administrative and support", "72": "Accommodation and food services", "81": "Other services", "53": "Real estate", "71": "Arts and recreation"} by_sec: dict = {} for r in cur: by_sec.setdefault(NAICS.get((r["biz_code"] or "")[:2], "Other or missing code"), []).append(r) S["current_stuck_by_industry"] = sorted(({"industry": k, **pool(v)} for k, v in by_sec.items()), key=lambda x: -x["people"]) S["post_hoc_split"] = {"note": "amendment 2 of the pre-registration: post-hoc, after reading the plans to be named", **{g: pool([r for r in cur if r["group"] == g]) for g in ("multi_employer_or_bargained", "inconsistent_filing", "employer_has_workers", "no_plan_with_workers")}} S["abandoned_program"] = {"stuck_matched": sum(r["abandoned_program"] for r in stuck), "stuck": len(stuck), "measured_matched": sum(1 for p in years if p in abandoned), "measured": measured} json.dump(S, open(os.path.join(out, "summary.json"), "w"), indent=1, default=str) lk = [{k: r[k] for k in ("plan_id", "ein", "pn", "plan_name", "sponsor", "city", "state", "admin_name", "admin_city", "admin_state", "start", "end", "years", "people_first", "people_last", "active_last", "usd_last", "mean_exit", "first_ack", "last_ack")} for r in [x for x in cur if x["group"] == "no_plan_with_workers"][:TOP]] json.dump({"rule": f"the {TOP} current stuck plans with the most participants with balances whose employer has no plan " "with workers (amendment 2)", "rows": lk}, open(os.path.join(out, "lookup.json"), "w"), indent=1, default=str) # validation (pre-registered): V1 reproduction in four states through 2024, V2 known cases, V4 abandoned program four = [r for r in find({p: y for p, y in years.items() if plans[p][6] in ("OH", "PA", "MI", "IN")}, 2024) if not r["data_error"] and r["stuck"]] V = {"V1_four_states_2024": {"stuck_plans": len(four), "oct30_measured": 311, "within_25pct": abs(len(four) - 311) <= 0.25 * 311}, "V2_known_cases": {}} for label, rx in (("Saint Joseph's College", r"SAINT JOSEPH'?S COLLEGE"), ("Marquette General Hospital", r"MARQUETTE GENERAL"), ("Dispatch Printing", r"DISPATCH PRINTING"), ("Indalex", r"INDALEX"), ("The Mills Corporation", r"\bTHE MILLS CORPORATION 401")): hit = [r for r in rows if re.search(rx, (r["sponsor"] or "") + " " + (r["plan_name"] or ""), re.I)] V["V2_known_cases"][label] = [{"plan_id": r["plan_id"], "stuck": r["stuck"], "years": r["years"], "people_last": r["people_last"]} for r in hit] V["V2_pass"] = sum(1 for v in V["V2_known_cases"].values() if any(x["years"] >= RUN for x in v)) >= 4 ab = S["abandoned_program"] V["V4_abandoned_share"] = {"stuck": ab["stuck_matched"] / max(1, ab["stuck"]), "all_measured": ab["measured_matched"] / max(1, ab["measured"])} json.dump(V, open(os.path.join(out, "validation.json"), "w"), indent=1, default=str) print(json.dumps({k: S[k] for k in ("measured_dc_plans", "zombie_plans", "data_errors", "stuck_all", "current_stuck")}, indent=1))