Skip to main content
Glama
vikranthviki

Causal Decision Agent

by vikranthviki

stacked_did

Read-only

Estimates staggered-adoption treatment effects by stacking per-cohort sub-experiments with clean controls, avoiding contamination from late-treated units.

Instructions

Stacked DiD (Cengiz, Dube, Lindner, Zipperer 2019). For each treatment cohort, constructs a sub-experiment with only that cohort + clean (never-treated or not-yet-treated) controls, then TWFE on the stacked panel. Robust to staggered-adoption contamination at the cost of dropping late-treated units in early sub-experiments. Validation: certified parity evidence. Do NOT use when: there is a single adoption cohort -- stacking produces one sub-experiment and is equivalent to sp.did(method='2x2'). Cost: Duplicates rows into one sub-experiment per treated cohort: the stacked dataset is roughly O(n x number of cohorts) before the event window trims it. Narrow window= to bound memory. Assumptions: Parallel trends within each sub-experiment; No anticipation within window; SUTVA. Pre-conditions: staggered adoption with >= 2 cohorts; window horizon available per cohort (else dropped). Failure modes: No clean controls for the latest cohort -> Late cohort's sub-experiment is dropped; check coverage in model_info. Consider sp.callaway_santanna. Alternatives: sp.callaway_santanna, sp.sun_abraham, sp.did_imputation. Typical minimum N: 100.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
yYesOutcome variable column name or outcome array.
timeYesTime period column.
alphaNoSignificance level for confidence intervals and tests.
groupYesUnit identifier
detailNoPayload depth: 'minimal' (~150 tokens) for sub-step calls where only the point estimate is needed; 'standard' (~1K tokens) for diagnostics + coefficient table; 'agent' (~2K tokens, default) adds violations / next_steps / suggested_functions so the LLM can plan its next call without another round-trip.agent
windowNoEvent-time (lead, lag) window per sub-experiment
clusterNoCluster identifier column for clustered standard errors.
controlsNoControl-variable column names.
as_handleNoIf true, cache the fitted result on the server and return result_id + result_uri alongside the JSON payload so a subsequent tools/call can chain without re-running.
data_pathYesAbsolute path or URL to a data file. Supported: .csv / .tsv / .txt (delimited), .parquet / .pq, .feather / .arrow, .xlsx / .xls, .dta (Stata), .json / .jsonl. Schemes: file://, s3://, gs://, https://.
result_idNoOptional handle to a previously-fitted result (returned by an earlier call when as_handle=true). Tools that operate on a fitted object accept this in place of re-supplying data_path + columns.
first_treatYesfirst_treat parameter (str).
data_columnsNoOptional column projection. Parquet/Feather/Stata loaders honour this for fast partial reads.
data_sample_nNoOptional uniform random subsample size (seed=0, deterministic) — useful on huge panels.
never_treated_onlyNoUse only never-treated as controls (drops late-treated)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations declare readOnlyHint: true and openWorldHint: false. The description adds substantial behavioral context beyond that: it explains the cost of row duplication (O(n x cohorts)), the risk of dropping late-treated units, and the need to check coverage in model_info if no clean controls exist. It does not contradict annotations—the tool is a read-only estimation operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is dense but well-organized: it starts with the core methodology, then caveats, then alternatives and costs. However, it is somewhat long and could be tightened—some information is repeated (e.g., dropping late-treated units appears in both the robustness note and failure modes). Still, every major point is useful and front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (staggered DiD with multiple cohorts, sub-experiments, memory concerns), the description covers all necessary aspects: method, assumptions, pre-conditions, failure modes, costs, and typical sample size. The output schema is present, so return values are already specified. Nothing critical is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so parameters like data_path, y, time, etc. are already documented. The description adds value by explaining the cost implications of window size (narrow window to bound memory), and the never_treated_only parameter's effect on control selection. It doesn't deeply elaborate on every parameter but the schema covers them, so this meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly identifies the tool as implementing the stacked DiD estimator with a citation, and explains the core methodology (constructing sub-experiments per cohort, TWFE on stacked panel). It distinguishes itself from alternatives like callaway_santanna and sun_abraham, and even specifies when not to use it (single cohort). This goes beyond a simple verb+resource statement.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use (staggered adoption with >=2 cohorts) and not to use (single cohort), and names concrete alternatives (sp.callaway_santanna, sp.sun_abraham, sp.did_imputation). It also lists failure modes and pre-conditions, giving an agent clear decision rules.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools