policyengine-aggregation

Sum variables across PolicyEngine entities using adds or add().

31|6|Updated Oct 19, 2025
One-click install
npx skills add https://github.com/PolicyEngine/policyengine-claude --skill policyengine-aggregation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: policyengine-aggregation
Source: https://github.com/PolicyEngine/policyengine-claude/tree/main/skills/technical-patterns/policyengine-aggregation-skill
Command: npx skills add https://github.com/PolicyEngine/policyengine-claude --skill policyengine-aggregation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill teaches how to sum variables across entities using declarative adds or the add() function, reducing boilerplate code and errors.

Core Features & Use Cases

  • Simple sums with adds: Define adds to sum across members without a formula.
  • Complex sums with add(): Use add() to incorporate conditions or transformations.
  • Use Case: Aggregate multiple income streams across a household with minimal code.

Quick Start

Define a final variable that uses adds = ["employment_income", "self_employment_income"] to compute total earned income.

Frequently Asked Questions about policyengine-aggregation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I sum variables across entities in PolicyEngine?▼

Use the adds property to sum variables across related entities like households or tax units. For simple aggregation, list source variables in adds without a formula. For conditional or transformed sums, write a formula() that calls add() with conditions, max_, or where logic to compute totals across entity members.

What's the difference between using adds and add() for aggregation?▼

The adds property performs straightforward summation across entity members with minimal code. The add() function within a formula() enables complex logic: conditional sums, maximum values, filtered aggregation, and parameter-based calculations. Use adds for simple totals; use add() when you need conditions or transformations.

Can I aggregate multiple income streams across a household?▼

Yes. Define a final variable with adds listing income sources such as employment_income and self_employment_income. PolicyEngine automatically sums these across household members. For weighted or conditional income aggregation, use add() in a formula() to apply custom logic before summing.

Does aggregation work across different entity types in PolicyEngine?▼

Aggregation patterns support cross-entity summation: from SPMUnit to Household, or TaxUnit to SPMUnit. Use adds or add() to declare which entity members contribute to the total. The Skill handles automatic entity traversal; you specify the source variables and aggregation logic.

Can I count boolean values or sum with conditions using aggregation?▼

Yes. Use add() in a formula() to count qualifying members by applying boolean logic or where clauses. This enables counting dependents, summing only positive values, or aggregating based on entity attributes without writing custom iteration code.