Skip to content

Causal

Estimate treatment effects (ATE, ATT) and propensity scores from observational data with IPW, regression adjustment, and AIPW

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/causal/index.md to help me query Causal with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Estimate the effect of a treatment

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT method, round(estimate, 2) AS estimate FROM causal.main.ate((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y') ORDER BY method
Result
method estimate
aipw 5
ipw 4.68
regression_adjustment 5

Quick start

Choose where to run Causal, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'causal' AS causal (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-causal-worker'
);

3. Run a query

query.sql
WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT method, round(estimate, 2) AS estimate FROM causal.main.ate((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y') ORDER BY method
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'causal' AS causal (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-causal-worker'
);

Overview

Causal treatment-effect estimation (ATE, ATT, propensity scores) for SQL

Catalog

Everything causal exposes once attached — read straight from the worker's released build.

causal 1 schema
main 1 view · 3 functions

Causal estimators: ate (IPW/RA/AIPW), att (IPW-ATT), and per-row propensity_scores

Schema examples (6)
Examples (6)

Average treatment effect by IPW, regression adjustment, and doubly-robust AIPW.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT method, round(estimate, 2) AS estimate FROM causal.main.ate((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y') ORDER BY method;
Result
method estimate
aipw 5
ipw 4.68
regression_adjustment 5

Average treatment effect on the treated (ATT).

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT round(estimate, 2) AS att FROM causal.main.att((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y');

The five subjects most likely to have been treated, by fitted propensity.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT id, round(propensity, 3) AS propensity, treatment FROM causal.main.propensity_scores((SELECT id, t, x FROM cohort), treatment := 't', id := 'id') ORDER BY propensity DESC LIMIT 5;

Naive treated-minus-control difference of means next to the doubly-robust ATE and the ATT: confounding by x inflates the naive contrast well above both adjusted estimates.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
, naive AS (SELECT avg(y) FILTER (WHERE t = 1) - avg(y) FILTER (WHERE t = 0) AS diff FROM cohort), dr AS (SELECT estimate FROM causal.main.ate((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y') WHERE method = 'aipw'), treated AS (SELECT estimate FROM causal.main.att((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y')) SELECT round(naive.diff, 2) AS naive_diff, round(dr.estimate, 2) AS ate_aipw, round(treated.estimate, 2) AS att FROM naive CROSS JOIN dr CROSS JOIN treated;
2 more examples

Overlap trimming: keep only subjects whose fitted propensity lies in [0.2, 0.8] (44 of the 61), then re-estimate the ATE by every method on that trimmed cohort.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
, ps AS (SELECT id, propensity FROM causal.main.propensity_scores((SELECT id, t, x FROM cohort), treatment := 't', id := 'id')) SELECT method, round(estimate, 2) AS estimate, round(std_error, 3) AS std_error FROM causal.main.ate((SELECT c.t, c.y, c.x FROM cohort AS c JOIN ps USING (id) WHERE ps.propensity BETWEEN 0.2 AND 0.8), treatment := 't', outcome := 'y') ORDER BY method;

Each ATE estimator's estimate and 95% CI next to its doubly-robust flag and one-line summary from the methods reference view (doubly-robust AIPW first).

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT e.method, m.doubly_robust, round(e.estimate, 2) AS estimate, round(e.ci_lower, 2) AS ci_lower, round(e.ci_upper, 2) AS ci_upper, m.description FROM causal.main.ate((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y') AS e JOIN causal.main.methods AS m ON m.method = e.method AND m.function_name = 'ate' ORDER BY m.doubly_robust DESC, e.method;
Views
methods 2 examples5 cols

Reference registry of the estimator methods each causal function emits

Columns
method VARCHAR
Estimator identifier as it appears in output (e.g. the `method` column of `ate`).
function_name VARCHAR
The catalog function that emits this method: ate, att, or propensity_scores.
estimand VARCHAR
The causal quantity estimated: ATE, ATT, or the per-row propensity e(X).
doubly_robust BOOLEAN
TRUE when the estimator is doubly-robust (consistent if either nuisance model is right).
description VARCHAR
One-line summary of the estimator and how it adjusts for confounding.
Examples (2)

Which estimators does the ate function emit, and which are doubly-robust?

SELECT method, doubly_robust
FROM causal.main.methods
WHERE function_name = 'ate'
ORDER BY method;

List every estimator with its estimand and the function that produces it.

SELECT function_name, method, estimand
FROM causal.main.methods
ORDER BY function_name, method;
Link
Table in-out functions
ate (data TABLE, outcome := VARCHAR, random_state := BIGINT, treatment := VARCHAR) 3 examples

Average Treatment Effect E[Y(1)-Y(0)] adjusting for every covariate column. Emits one row per method: ipw, regression_adjustment, aipw (doubly-robust). treatment must be binary 0/1; causal only under unconfoundedness.

Positional arguments
data TABLE
The cohort as a (SELECT ...) subquery. Every column other than the named treatment and outcome roles is treated as an adjusted-for covariate.
Named arguments
outcome := VARCHAR
Outcome column whose treatment effect is estimated. · default "outcome"
random_state := BIGINT
Seed for the deterministic propensity-model fit; vary it to probe estimate stability. · default 0
treatment := VARCHAR
Binary 0/1 treatment column. · default "treatment"
Returns columns
method VARCHAR
Estimator: ipw, regression_adjustment, or aipw. One row per method.
estimate DOUBLE
Estimated average treatment effect E[Y(1)-Y(0)].
std_error DOUBLE
Standard error of the estimate.
ci_lower DOUBLE
Lower bound of the 95% Wald confidence interval.
ci_upper DOUBLE
Upper bound of the 95% Wald confidence interval.
Examples (3)

Average treatment effect by IPW, regression adjustment, and AIPW.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT method, round(estimate, 2) AS estimate FROM causal.main.ate((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y') ORDER BY method;
Result
method estimate
aipw 5
ipw 4.68
regression_adjustment 5

Doubly-robust AIPW estimate with its 95% confidence interval.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT round(estimate, 2) AS estimate, round(ci_lower, 2) AS ci_lower, round(ci_upper, 2) AS ci_upper FROM causal.main.ate((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y') WHERE method = 'aipw';

Each ATE estimator's estimate and 95% CI next to its doubly-robust flag and one-line summary from the methods reference view (doubly-robust AIPW first).

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT e.method, m.doubly_robust, round(e.estimate, 2) AS estimate, round(e.ci_lower, 2) AS ci_lower, round(e.ci_upper, 2) AS ci_upper, m.description FROM causal.main.ate((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y') AS e JOIN causal.main.methods AS m ON m.method = e.method AND m.function_name = 'ate' ORDER BY m.doubly_robust DESC, e.method;
Link
att (data TABLE, outcome := VARCHAR, random_state := BIGINT, treatment := VARCHAR) 2 examples

Average Treatment effect on the Treated E[Y(1)-Y(0)|T=1] via IPW-ATT weighting, adjusting for every covariate column. Emits one row (estimate, std_error). treatment must be binary 0/1.

Positional arguments
data TABLE
The cohort as a (SELECT ...) subquery. Every column other than the named treatment and outcome roles is treated as an adjusted-for covariate.
Named arguments
outcome := VARCHAR
Outcome column whose treatment effect is estimated. · default "outcome"
random_state := BIGINT
Seed for the deterministic propensity fit and bootstrap; vary it to probe SE stability. · default 0
treatment := VARCHAR
Binary 0/1 treatment column. · default "treatment"
Returns columns
estimate DOUBLE
Average treatment effect on the treated E[Y(1)-Y(0)|T=1].
std_error DOUBLE
Bootstrap standard error of the ATT estimate.
Examples (2)

Average treatment effect on the treated (IPW-ATT), with its bootstrap standard error.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT round(estimate, 2) AS estimate, round(std_error, 3) AS std_error FROM causal.main.att((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y');

Naive treated-minus-control difference of means next to the doubly-robust ATE and the ATT: confounding by x inflates the naive contrast well above both adjusted estimates.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
, naive AS (SELECT avg(y) FILTER (WHERE t = 1) - avg(y) FILTER (WHERE t = 0) AS diff FROM cohort), dr AS (SELECT estimate FROM causal.main.ate((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y') WHERE method = 'aipw'), treated AS (SELECT estimate FROM causal.main.att((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y')) SELECT round(naive.diff, 2) AS naive_diff, round(dr.estimate, 2) AS ate_aipw, round(treated.estimate, 2) AS att FROM naive CROSS JOIN dr CROSS JOIN treated;
Link
propensity_scores (data TABLE, id := VARCHAR, random_state := BIGINT, treatment := VARCHAR) 3 examples

Fit a logistic propensity model and emit per-row scores: (id, propensity, treatment). The id column is passed through and excluded from the covariates; every other column is a covariate. treatment must be binary 0/1.

Positional arguments
data TABLE
The cohort as a (SELECT ...) subquery. The named id and treatment roles are excluded from the model; every other column is treated as a covariate.
Named arguments
id := VARCHAR
Row id to pass through (excluded from covariates). · default "id"
random_state := BIGINT
Seed for the deterministic propensity-model fit; vary it to probe score stability. · default 0
treatment := VARCHAR
Binary 0/1 treatment column. · default "treatment"
Returns columns
id BIGINT
Passthrough row identifier (the named id column, excluded from covariates).
propensity DOUBLE
Fitted propensity e(X)=P(T=1|X) in (0,1).
treatment INTEGER
Observed 0/1 treatment indicator for the row.
Examples (3)

The five subjects most likely to have been treated, by fitted propensity.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT id, round(propensity, 3) AS propensity, treatment FROM causal.main.propensity_scores((SELECT id, t, x FROM cohort), treatment := 't', id := 'id') ORDER BY propensity DESC LIMIT 5;

Count subjects whose fitted propensity exceeds one half (an overlap check).

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT count(*) AS n_high_propensity FROM causal.main.propensity_scores((SELECT id, t, x FROM cohort), treatment := 't', id := 'id') WHERE propensity > 0.5;

Overlap trimming: keep only subjects whose fitted propensity lies in [0.2, 0.8] (44 of the 61), then re-estimate the ATE by every method on that trimmed cohort.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
, ps AS (SELECT id, propensity FROM causal.main.propensity_scores((SELECT id, t, x FROM cohort), treatment := 't', id := 'id')) SELECT method, round(estimate, 2) AS estimate, round(std_error, 3) AS std_error FROM causal.main.ate((SELECT c.t, c.y, c.x FROM cohort AS c JOIN ps USING (id) WHERE ps.propensity BETWEEN 0.2 AND 0.8), treatment := 't', outcome := 'y') ORDER BY method;
Link

Try these queries

Average treatment effect on the treated (ATT).

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT round(estimate, 2) AS att FROM causal.main.att((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y')

Uses att

The five subjects most likely to have been treated, by fitted propensity.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT id, round(propensity, 3) AS propensity, treatment FROM causal.main.propensity_scores((SELECT id, t, x FROM cohort), treatment := 't', id := 'id') ORDER BY propensity DESC LIMIT 5

Uses propensity_scores

Naive treated-minus-control difference of means next to the doubly-robust ATE and the ATT: confounding by x inflates the naive contrast well above both adjusted estimates.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
, naive AS (SELECT avg(y) FILTER (WHERE t = 1) - avg(y) FILTER (WHERE t = 0) AS diff FROM cohort), dr AS (SELECT estimate FROM causal.main.ate((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y') WHERE method = 'aipw'), treated AS (SELECT estimate FROM causal.main.att((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y')) SELECT round(naive.diff, 2) AS naive_diff, round(dr.estimate, 2) AS ate_aipw, round(treated.estimate, 2) AS att FROM naive CROSS JOIN dr CROSS JOIN treated

Uses ateatt

Overlap trimming: keep only subjects whose fitted propensity lies in [0.2, 0.8] (44 of the 61), then re-estimate the ATE by every method on that trimmed cohort.

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
, ps AS (SELECT id, propensity FROM causal.main.propensity_scores((SELECT id, t, x FROM cohort), treatment := 't', id := 'id')) SELECT method, round(estimate, 2) AS estimate, round(std_error, 3) AS std_error FROM causal.main.ate((SELECT c.t, c.y, c.x FROM cohort AS c JOIN ps USING (id) WHERE ps.propensity BETWEEN 0.2 AND 0.8), treatment := 't', outcome := 'y') ORDER BY method

Uses propensity_scoresate

Each ATE estimator's estimate and 95% CI next to its doubly-robust flag and one-line summary from the methods reference view (doubly-robust AIPW first).

WITH cohort AS (
  SELECT
    g                                                   AS id,
    (g - 30)::DOUBLE / 10.0                             AS x,
    CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END AS t,
    5.0 * (CASE WHEN ((g * 7 + 3) % 10) < 5 + 3 * sign(g - 30) THEN 1 ELSE 0 END)
      + 2.0 * ((g - 30)::DOUBLE / 10.0)                 AS y
  FROM generate_series(0, 60) AS s(g)
)
SELECT e.method, m.doubly_robust, round(e.estimate, 2) AS estimate, round(e.ci_lower, 2) AS ci_lower, round(e.ci_upper, 2) AS ci_upper, m.description FROM causal.main.ate((SELECT t, y, x FROM cohort), treatment := 't', outcome := 'y') AS e JOIN causal.main.methods AS m ON m.method = e.method AND m.function_name = 'ate' ORDER BY m.doubly_robust DESC, e.method

Uses atemethods

Which estimators does the ate function emit, and which are doubly-robust?

SELECT method, doubly_robust
FROM causal.main.methods
WHERE function_name = 'ate'
ORDER BY method

Uses methods

4 more examples in the Catalog, each listed under the table or function it uses.

Causal is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.