Logo Causal Iv

Causal Iv

Cộng đồng
RobsonTigre
causal-iv

Triển khai biến công cụ và 2SLS bằng R hoặc Python, kèm chẩn đoán giai đoạn đầu, phát hiện công cụ yếu và kiểm định quá xác định. Dùng khi người dùng nhắc đến IV, biến công cụ, 2SLS, không tuân thủ hoặc nội sinh. Không dùng khi không có biến công cụ hợp lý.

Tổng quan

Nhà phát hànhRobsonTigre
Kho mãeveryday-causal-skills
Tên kỹ năngcausal-iv
Sao
83
Bản fork
10
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được RobsonTigre công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Causal Iv trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/RobsonTigre/everyday-causal-skills/tree/main/skills/causal-iv
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/RobsonTigre/everyday-causal-skills.git /tmp/everyday-causal-skills
mkdir -p .claude/skills
cp -r /tmp/everyday-causal-skills/skills/causal-iv .claude/skills/causal-iv
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Causal Iv trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Causal Iv ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Causal Iv với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Causal IV

You guide users through a complete instrumental variables analysis following a 5-stage pattern.

Before You Begin

  1. Read references/lessons.md — known mistakes. Do not repeat them.
  2. Read references/assumptions/iv.md — the assumption checklist for IV.
  3. Read references/method-registry.md → "Instrumental Variables (IV)" section.
  4. Check if a plan exists at docs/causal-plans/*/plan.md. If it does, read it for context.
  • Explain the why: When walking through assumptions, recommending methods, or flagging concerns, always explain why it matters — not just what to do. Help the user build intuition, not just follow instructions.

Quality Standards

  • Complete every stage. Do not skip assumption checks or robustness tests.
  • Quality over speed. A thorough analysis with caveats beats a fast one without.
  • When uncertain, say so. Flag limitations rather than presenting weak evidence as strong.

Stage 1: Setup

If a plan document from /causal-planner is provided: Extract the study design (treatment, population, outcome, data structure, language) directly from the plan. Do not re-ask questions the planner already answered. Acknowledge the plan and build on it.

If plan exists: Read it. Extract business objective, instrument, endogenous treatment, outcome, language, data structure. Confirm: "I've read your analysis plan. You're using [instrument] as an instrument for [treatment] on [outcome]. Does that sound right?"

If no plan: Ask:

  1. "What's the endogenous treatment variable — the variable whose causal effect you want to estimate?"
  2. "What's the proposed instrument — the variable that shifts the treatment but (arguably) doesn't directly affect the outcome?"
  3. "What's the outcome?"
  4. "Is this a case of non-compliance (e.g., randomized encouragement but voluntary take-up)? One-sided (only treated group can deviate) or two-sided (both groups can deviate)?"
  5. "Do you have more than one instrument? If so, list them."
  6. "Any covariates you want to control for?"
  7. "R or Python?"

When instrument, treatment, outcome, and language are already supplied: Do not stop at another setup interview. In the first response, teach and operationalize all four IV conditions:

  • relevance: the instrument must materially move treatment, checked with the first stage and its F statistic/partial R-squared;
  • independence: the instrument must be as-if randomly assigned relative to causes of the outcome;
  • exclusion: the instrument may affect the outcome only through treatment, an untestable causal claim that needs a substantive argument; and
  • monotonicity: the instrument must not push some units toward treatment while pushing others away.

Explain that 2SLS identifies a LATE for compliers, not automatically the population ATE. End with a concrete first-stage/ITT/2SLS diagnostic and estimation deliverable. If the observed first stage is weak, issue the required severity verdict and propose weak-instrument-robust inference or a stronger instrument rather than promising ordinary 2SLS.

Canonical runnable block: When emitting executable code, put the exact line # EVAL_EXECUTABLE as the first nonblank program line inside exactly one correct-language code fence. Do not indent it or add other text on that line. That fence must contain the complete program to run. Keep preflight snippets and illustrative alternatives outside it; do not mark more than one block.

Determine variant:

  • Single instrument, single endogenous variable → Standard 2SLS
  • Multiple instruments, single endogenous variable → 2SLS with overidentification test
  • Fuzzy RDD framing → Fuzzy RDD (suggest causal-rdd instead)
  • Weak instrument suspected → Flag for careful diagnostics

Stage 2: Assumptions

Read references/assumptions/iv.md. Walk through each assumption interactively:

For each assumption:

  1. Explain in plain language what it means for their specific context.
  2. Ask if it's plausible.
  3. If testable, offer diagnostic code.
  4. Note the concern level.

Key assumptions to walk through:

  1. Relevance (first-stage strength): "Does the instrument actually predict the treatment? We need a strong first stage — an F-statistic well above 10 (ideally above 100 for modern standards)."

    • This IS testable. Offer first-stage regression code.
  2. Exclusion restriction: "Does the instrument affect the outcome ONLY through its effect on the treatment? There must be no direct path from instrument to outcome."

    • This is NOT directly testable. Must be argued on substantive grounds.
    • Ask: "Can you think of any way [instrument] could affect [outcome] other than through [treatment]?"
  3. Independence (as-if random): "Is the instrument independent of the potential outcomes and unobserved confounders? It should be as good as randomly assigned."

    • Partially testable: check balance of instrument with observables.
  4. Monotonicity: "Does the instrument push everyone in the same direction? No 'defiers' — units who do the opposite of what the instrument encourages."

    • Needed for LATE interpretation. Discuss plausibility.

After all assumptions, summarize with status indicators per assumption.

Pedagogy checkpoint (especially for first-time IV users):

  • Explain the ITT vs LATE distinction: The intent-to-treat (ITT) estimate — the reduced-form effect of the instrument on the outcome — answers "what is the effect of being assigned to treatment?" The LATE answers "what is the effect of actually taking the treatment, among those who comply?" Both are useful, for different questions.
  • Explain who the compliers are: LATE applies only to compliers — units whose treatment status was changed by the instrument. Always describe who these are in the user's specific context (e.g., "people who would use the savings product when encouraged but would not use it otherwise").
  • Explain what the first-stage F tells you: A high F (>10, ideally >100) means the instrument strongly predicts treatment. A low F means 2SLS is unreliable — estimates are biased toward OLS and confidence intervals are wrong. This is the single most important diagnostic in IV.

If fatal violations exist (especially weak instrument or clearly violated exclusion restriction), warn clearly and suggest alternatives. If you cannot yet confirm the violation (because the user hasn't run diagnostic code), use the CONDITIONAL FATAL verdict format from Red Flags. Do not generate full analysis code before a fatal-level diagnostic has been resolved — require the user to report the diagnostic result first.

Stage 3: Implementation

Generate complete analysis code. Read the appropriate template from templates/r/iv.md or templates/python/iv.md for code patterns.

Missing-package preflight: The template's Prerequisites block detects (never installs) missing packages. Follow references/preflight.md: report what's missing, then ask the user whether they want you to install it for them or do it themselves — install only on an explicit yes.

IMPORTANT — Template adherence: Copy the code pattern from the appropriate template (templates/r/iv.md or templates/python/iv.md) exactly, then adapt only variable names to match the user's data. Do not restructure the code, use alternative function APIs, or improvise accessor patterns. The templates have been tested; deviations introduce bugs.

Always include:

  • First-stage regression with F-statistic
  • 2SLS / IV estimation
  • Comparison with naive OLS (to show bias direction)
  • Proper standard errors
  • Confidence interval for the IV estimate

IV estimation (R — fixest):

r
library(fixest)
library(modelsummary)

# First stage: check instrument relevance
# F < 10 = weak instrument — estimates biased toward OLS, standard errors misleading
first_stage <- feols(treatment ~ instrument + X1 + X2, data = df)
summary(first_stage)
cat("First-stage F-statistic:", fitstat(first_stage, "ivf")$ivf$stat, "\n")

# 2SLS estimation
iv_model <- feols(outcome ~ X1 + X2 | treatment ~ instrument, data = df)
summary(iv_model)

# Naive OLS for comparison
ols_model <- feols(outcome ~ treatment + X1 + X2, data = df)

modelsummary(list("OLS" = ols_model, "IV/2SLS" = iv_model),
             stars = TRUE)

IV estimation (R — AER):

r
library(AER)

iv_model <- ivreg(outcome ~ treatment + X1 + X2 |
                   instrument + X1 + X2, data = df)
summary(iv_model, diagnostics = TRUE)

IV estimation (Python):

python
from linearmodels.iv import IV2SLS
import statsmodels.formula.api as smf

# First stage
# F < 10 = weak instrument — 2SLS unreliable, use Anderson-Rubin CIs instead
first_stage = smf.ols('treatment ~ instrument + X1 + X2', data=df).fit()
print("First-stage F-statistic:", first_stage.fvalue)
print(first_stage.summary())

# 2SLS estimation
iv_model = IV2SLS.from_formula(
    'outcome ~ 1 + X1 + X2 + [treatment ~ instrument]', data=df
).fit(cov_type='robust')
print(iv_model.summary)

# Naive OLS for comparison
ols_model = smf.ols('outcome ~ treatment + X1 + X2', data=df).fit()
print(ols_model.summary())

Adapt code to the user's variable names and data structure.

Stage 4: Falsification / Robustness

Propose at least one check. Generate the code.

Options (offer the most relevant):

  1. Reduced form: Regress outcome directly on instrument (skipping treatment). If the instrument is valid and relevant, this should show a significant effect in the same direction. The reduced form is often more robust than 2SLS.
  2. Placebo instrument: Use a variable that should NOT be a valid instrument. If it produces similar IV estimates, something is wrong.
  3. Overidentification test (if >1 instrument): Sargan/Hansen J-test. A rejection suggests at least one instrument is invalid.
  4. Sensitivity to controls: Add or remove covariates. A stable IV estimate is reassuring.
  5. Balance on observables: Check if the instrument is balanced on pre-treatment covariates (supports the independence assumption).

Verification Gate

Before proceeding to interpretation, confirm ALL of the following from actual code output:

  • Main estimation ran without errors
  • You can quote the point estimate from the output
  • You can quote the standard error and 95% CI from the output
  • At least one robustness/falsification check ran and you can compare its result to the main estimate
  • Assumption diagnostics produced output (not just discussed)

If any box is unchecked: Flag it to the user — explain which evidence is missing and why it matters. Offer to run the missing step before interpreting. If the user chooses to continue anyway, carry the gap forward as a caveat in the interpretation.

Watch for premature conclusions — phrases like "The results suggest..." or "Based on the analysis..." before the gate passes. These imply conclusions without evidence. Quote actual output instead.

Severity verdicts must appear BEFORE this gate. If a Fatal or Serious issue was identified during Stage 2 (Assumptions) or Stage 3 (Implementation), the severity verdict block must already be visible in the output above. Do not defer severity communication to after the user runs the code if the data or context already reveals the violation.

Red Flags

Data Diagnostic Signals

SignalSeverityAction
First-stage F < 10🚨 FatalWeak instrument. 2SLS estimates are unreliable. Warn user before continuing.
No substantive argument for exclusion restriction🚨 FatalWithout an economic argument, IV is not identified. Warn user before continuing.
Hausman test fails to reject (OLS ~ IV)⚠️ SeriousEndogeneity may not be a problem. Report both estimates, discuss.
Overidentification test rejects (Hansen J)⚠️ SeriousAt least one instrument may be invalid. Investigate which.

🚨 Fatal = Emit this verdict block immediately after the diagnostic that reveals the violation:

FATAL: [violation name] [One sentence: what was found in the data.] This analysis should not proceed without addressing this issue. Results produced under this violation are not trustworthy. If you cannot yet confirm the violation (because the user hasn't run diagnostic code), use CONDITIONAL FATAL: [violation name] with the same format but replace the consequence line with: "If [specific diagnostic condition], this analysis should not proceed. Run the diagnostic above and report the result before continuing." If the user chooses to continue despite a Fatal verdict, repeat the verdict verbatim in Stage 5 interpretation.

⚠️ Serious = Emit this block:

SERIOUS: [limitation name] [One sentence: what was found.] Proceeding is possible, but the interpretation must prominently acknowledge this limitation and its consequences.

Use only FATAL and SERIOUS severity labels. Do not invent additional tiers (Critical, Yellow, Minor, etc.). When in doubt, round UP to the next severity level.

Rationalization Shortcuts

ShortcutReality
"This is just an exploratory analysis"If results will influence a decision, it's not exploratory. Apply full rigor.
"We don't need robustness checks -- the main result is strong"Strong results without robustness checks are more suspicious, not less.
"The sample is too small for formal tests"Small samples need more caution, not less. Flag the limitation explicitly.
"The instrument is probably valid"Exclusion restriction is untestable. You need an economic argument, not a feeling.
"First-stage F is close to 10"Stock-Yogo critical values exist for a reason. Report the exact F and compare.
"IV gives us the ATE"IV gives the LATE (complier effect). State who the compliers are.

Stage 5: Interpretation

Help write a plain-language summary:

"Based on the IV analysis:

  • The IV estimate of the effect of [treatment] on [outcome] is [coefficient] (95% CI: [lower, upper]).
  • For comparison, the naive OLS estimate was [OLS coefficient] — the difference suggests [direction of bias].
  • The first-stage F-statistic is [F] ([strong/weak] instrument).

LATE interpretation: This estimate applies to compliers — units whose treatment status was changed by the instrument. It does NOT estimate the average treatment effect for the full population.

  • Compliers are units who [specific description in context — e.g., 'would enroll in the program when encouraged but would not enroll otherwise'].
  • If the treatment effect is heterogeneous, the LATE may differ from the ATE.

Caveats:

  • [Exclusion restriction plausibility — strongest or weakest argument]
  • [Weak instrument concerns if F < 100]
  • [Monotonicity plausibility]"

Reading Your Results

First-stage F-statistic: If F < 10: "Your instrument is weak — it barely moves treatment. The 2SLS estimates are unreliable: biased toward OLS, with misleading standard errors. Use Anderson-Rubin confidence sets instead, or find a stronger instrument." If 10-25: "Moderate instrument strength. Standard 2SLS is usable, but report Anderson-Rubin CIs alongside for robustness." If 25-100: "Adequate instrument. Standard inference is reliable, though modern standards prefer F > 100." If > 100: "Strong instrument by modern standards. Standard inference is fully reliable."

OLS vs IV gap: "OLS estimates [X], IV estimates [Y]. The gap suggests the OLS estimate has [upward/downward] bias from [endogeneity source]. If IV is larger than OLS, the naive estimate was attenuated — common with measurement error in the treatment. If IV is smaller, OLS was inflated — common with positive selection into treatment."

LATE interpretation: "This estimate applies to compliers — people whose treatment changed because of the instrument. In your context, compliers are [description]. If you think treatment effects vary across people, the LATE may differ substantially from the population average effect. Consider whether compliers are the group you care about."

Wu-Hausman test: If p < 0.05: "The Hausman test rejects exogeneity — OLS and IV give significantly different answers, confirming the endogeneity problem. IV is the appropriate estimator." If p > 0.05: "OLS and IV aren't significantly different. You might not need IV, but the test has limited power — a non-rejection doesn't prove exogeneity."

Saving Output

Save alongside the plan (or create a new directory if standalone):

docs/causal-plans/YYYY-MM-DD-<project>/
├── plan.md              # From planner (or created here if standalone)
├── implementation.md    # This skill's stage-by-stage summary
└── analysis.[R|py]      # Generated code

Use the Write tool. Tell the user where files are saved.

Handoff

"Your IV analysis is complete. Recommended next steps:

  1. Audit: /causal-auditor to stress-test for threats to validity.
  2. Refine: If the instrument is weak or the exclusion restriction is shaky, we can discuss mitigations.
  3. Report: I can help write up findings for a non-technical audience."

Common Issues

  • Weak instruments: First-stage F-statistic below 10 signals a weak instrument. Report the F-stat and consider weak-instrument-robust methods (Anderson-Rubin, LIML).
  • Exclusion restriction asserted without argument: The instrument must affect the outcome only through the treatment. This is untestable — require the user to articulate the economic or theoretical argument.
  • Multiple endogenous variables with insufficient instruments: The order condition requires at least as many instruments as endogenous regressors. Check before estimating.

Integration

Before this skill:

  • /causal-planner -- Identifies method and saves analysis plan (recommended)

After this skill:

  • /causal-auditor -- Stress-test results for threats to validity (recommended)
  • /causal-hte -- Explore who benefits more or less from treatment (heterogeneous effects)
  • /causal-exercises -- Practice a similar analysis on simulated data (optional)

If assumptions fail:

  • /causal-rdd -- If the instrument is a threshold with a cutoff
  • /causal-matching -- If instrument is invalid but covariates are available

Self-Correction

If the user corrects you, append to references/lessons.md:

### IV: [Short description]
**Trigger**: [When this tends to happen]
**Mistake**: [What went wrong]
**Rule**: [What to do instead]
**Source**: User correction, [date]

Câu hỏi thường gặp

Kỹ năng AI Causal Iv làm được gì?

Triển khai biến công cụ và 2SLS bằng R hoặc Python, kèm chẩn đoán giai đoạn đầu, phát hiện công cụ yếu và kiểm định quá xác định. Dùng khi người dùng nhắc đến IV, biến công cụ, 2SLS, không tuân thủ hoặc nội sinh. Không dùng khi không có biến công cụ hợp lý.

Vì sao nên dùng Causal Iv trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Causal Iv là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Causal Iv trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/RobsonTigre/everyday-causal-skills/tree/main/skills/causal-iv. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Causal Iv?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Causal Iv với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Causal Iv với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Causal Iv có miễn phí không?

Có. Kỹ năng này được RobsonTigre phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇