/structural-modeling
This skill covers structural econometric models. Use when the user is building, estimating, or debugging structural models — including BLP demand estimation, dynamic discrete choice, auction models, or any workflow involving moment conditions, nested fixed-point algorithms, or
$ npx -y skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill structural-modeling --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/structural-modeling
Context preview
The summary Claude sees to decide when to auto-load this skill.
This skill covers structural econometric models. Use when the user is building, estimating, or debugging structural models — including BLP demand estimation, dynamic discrete choice, auction models, or any workflow involving moment conditions, nested fixed-point algorithms, or
SKILL.md
structural-modeling.SKILL.mdname: structural-modeling
argument-hint: "<model type or estimation problem>"
description: >-
This skill covers structural econometric models. Use when the user is building, estimating, or debugging structural models — including BLP demand estimation, dynamic discrete choice, auction models, or any workflow involving moment conditions, nested fixed-point algorithms, or MPEC formulations. Triggers on "structural model", "moment conditions", "NFXP", "MPEC", "BLP", "random coefficients", "dynamic discrete choice", "CCP", "Rust model", "auction estimation", "GMM objective", "inner loop", "contraction mapping", or convergence/starting value problems in optimization-based estimation.
Structural Modeling
Reference for implementing structural econometric models: from economic model to moment conditions to estimated parameters. Covers the full workflow of taking a theoretical model, deriving its empirical content, and recovering structural parameters from data.
When to Use This Skill
Use when the user is:
- Specifying a structural model and deriving moment conditions
- Implementing NFXP or MPEC estimation routines
- Working with BLP-style demand systems (random coefficients logit)
- Building dynamic discrete choice models (Rust, Hotz-Miller CCP)
- Estimating auction models (first-price, ascending, common value)
- Debugging convergence failures in structural estimation
- Choosing between estimation approaches for a given model
Skip when:
- The task is reduced-form causal inference (use `causal-inference` skill)
- The task is pure simulation design (use `numerical-auditor` agent)
- The user just needs standard regression (statsmodels/linearmodels suffice)
Quick Reference: Structural Methods
| Method | Use Case | Key Package | Estimator | |--------|----------|-------------|-----------| | NFXP | Dynamic discrete choice (small state space) | `scipy.optimize` | MLE / GMM | | MPEC | Dynamic discrete choice (large state space, slow inner loop) | `cyipopt` (IPOPT) | MLE / GMM | | BLP | Differentiated products demand with RC logit | `pyblp` | GMM (2-step) | | CCP (Hotz-Miller) | Dynamic models, counterfactuals not needed | `scipy` | 2-step semiparametric | | GPV | First-price auctions, nonparametric values | `scipy` | Nonparametric | | Ascending auction | English auctions, private values | `scipy` | MLE on order statistics |
The Structural Estimation Workflow
Every structural estimation follows the same logical arc:
Economic Model → Equilibrium/Decision Rule → Observable Implications
→ Moment Conditions → Estimator → Optimization → InferenceStep 1: Model Specification
Define primitives clearly before writing any code:
# model_spec.py — Document structural primitives
"""
Model: Single-agent optimal stopping (Rust 1987 bus engine replacement)
State: x_t ∈ {0, 1, ..., X_max} (mileage bin)
Action: a_t ∈ {0, 1} (0 = maintain, 1 = replace)
Flow payoff:
u(x, 0; θ) = -θ_1 * x - θ_2 * x² (maintenance cost)
u(x, 1; θ) = -RC (replacement cost)
Discount: β = 0.9999 (fixed)
Shocks: ε ~ Type 1 Extreme Value (logit errors)
"""Document these before writing estimation code: agents, information, timing, payoff functional form, equilibrium concept.
Step 2: Derive Moment Conditions
| Source | Example | Estimator | |--------|---------|-----------| | Optimality conditions (FOCs) | Euler equations, Bellman optimality | GMM | | Equilibrium restrictions | Market clearing, Nash conditions | GMM / ML | | Distributional assumptions | Choice probabilities under logit errors | MLE | | Exclusion restrictions | Cost shifters excluded from demand | IV-GMM |
**Key question:** Just-identified → method of moments; over-identified → GMM with optimal weighting matrix; under-identified → revisit assumptions.
NFXP vs MPEC
Two dominant paradigms for models with latent quantities (unobserved heterogeneity, future expectations, equilibrium objects):
**NFXP (Nested Fixed-Point):** Solve the model in an inner loop for each parameter guess, evaluate likelihood/moments in an outer loop. Conceptually simple; inner loop must fully converge at every iteration — requires tight tolerance (1e-12, not 1e-6; see Su & Judd 2012).
**MPEC (Mathematical Programming with Equilibrium Constraints):** Reformulate as a single constrained optimization. No inner loop — solver handles everything; can be faster for large state spaces; requires IPOPT or KNITRO.
| Factor | Favors NFXP | Favors MPEC | |--------|-------------|-------------| | State space | Small (< 500 states) | Large (> 1000 states) | | Inner loop | Fast convergence (rate < 0.9) | Slow or fragile | | Solver availability | `scipy.optimize` sufficient | IPOPT/KNITRO available | | Debugging | Easier — isolate inner vs outer | Harder to diagnose constraint violations |
For full NFXP and MPEC code (Rust 1987 bus engine model), see `references/estimation-methods.md`.
BLP Demand Estimation
BLP (Berry, Levinsohn, Pakes 1995) is the workhorse for differentiated products demand. Use PyBLP whenever possible — it handles the difficult numerical details correctly.
import pyblp
# Define the problem
problem = pyblp.Problem(
product_formulations=(
pyblp.Formulation('1 + prices + x1 + x2'), # linear (β)
pyblp.Formulation('1 + prices + x1'), # random coefficients (Σ)
),
product_data=product_data,
agent_data=agent_data
)
# Solve — always use multiple starting values; BLP objective is non-convex
results = problem.solve(
sigma=sigma_init,
optimization=pyblp.Optimization('l-bfgs-b', {'gtol': 1e-8}),
iteration=pyblp.Iteration('squarem', {'atol': 1e-14}),
method='2s'
)For the full multi-start loop, two-step GMM, elasticity checks, instrument selection, and marginal cost computation, see `references/estimation-methods.md`.
**BLP Diagnostics Checklist:**
- [ ] First-stage F > 10 for price instruments
- [ ] Run 10+ ra
Read more
name: structural-modeling argument-hint: "<model type or estimation problem>" description: >- This skill covers structural econometric models. Use when the user is building, estimating, or debugging structural models — including BLP demand estimation, dynamic discrete choice, auction models, or any workflow involving moment conditions, nested fixed-point algorithms, or MPEC formulations. Triggers on "structural model", "moment conditions", "NFXP", "MPEC", "BLP", "random coefficients", "dynamic discrete choice", "CCP", "Rust model", "auction estimation", "GMM objective", "inner loop", "contraction mapping", or convergence/starting value problems in optimization-based estimation.
Structural Modeling
Reference for implementing structural econometric models: from economic model to moment conditions to estimated parameters. Covers the full workflow of taking a theoretical model, deriving its empirical content, and recovering structural parameters from data.
When to Use This Skill
Use when the user is:
- Specifying a structural model and deriving moment conditions
- Implementing NFXP or MPEC estimation routines
- Working with BLP-style demand systems (random coefficients logit)
- Building dynamic discrete choice models (Rust, Hotz-Miller CCP)
- Estimating auction models (first-price, ascending, common value)
- Debugging convergence failures in structural estimation
- Choosing between estimation approaches for a given model
Skip when:
- The task is reduced-form causal inference (use `causal-inference` skill)
- The task is pure simulation design (use `numerical-auditor` agent)
- The user just needs standard regression (statsmodels/linearmodels suffice)
Quick Reference: Structural Methods
| Method | Use Case | Key Package | Estimator | |--------|----------|-------------|-----------| | NFXP | Dynamic discrete choice (small state space) | `scipy.optimize` | MLE / GMM | | MPEC | Dynamic discrete choice (large state space, slow inner loop) | `cyipopt` (IPOPT) | MLE / GMM | | BLP | Differentiated products demand with RC logit | `pyblp` | GMM (2-step) | | CCP (Hotz-Miller) | Dynamic models, counterfactuals not needed | `scipy` | 2-step semiparametric | | GPV | First-price auctions, nonparametric values | `scipy` | Nonparametric | | Ascending auction | English auctions, private values | `scipy` | MLE on order statistics |
The Structural Estimation Workflow
Every structural estimation follows the same logical arc:
Economic Model → Equilibrium/Decision Rule → Observable Implications
→ Moment Conditions → Estimator → Optimization → InferenceStep 1: Model Specification
Define primitives clearly before writing any code:
# model_spec.py — Document structural primitives
"""
Model: Single-agent optimal stopping (Rust 1987 bus engine replacement)
State: x_t ∈ {0, 1, ..., X_max} (mileage bin)
Action: a_t ∈ {0, 1} (0 = maintain, 1 = replace)
Flow payoff:
u(x, 0; θ) = -θ_1 * x - θ_2 * x² (maintenance cost)
u(x, 1; θ) = -RC (replacement cost)
Discount: β = 0.9999 (fixed)
Shocks: ε ~ Type 1 Extreme Value (logit errors)
"""Document these before writing estimation code: agents, information, timing, payoff functional form, equilibrium concept.
Step 2: Derive Moment Conditions
| Source | Example | Estimator | |--------|---------|-----------| | Optimality conditions (FOCs) | Euler equations, Bellman optimality | GMM | | Equilibrium restrictions | Market clearing, Nash conditions | GMM / ML | | Distributional assumptions | Choice probabilities under logit errors | MLE | | Exclusion restrictions | Cost shifters excluded from demand | IV-GMM |
**Key question:** Just-identified → method of moments; over-identified → GMM with optimal weighting matrix; under-identified → revisit assumptions.
NFXP vs MPEC
Two dominant paradigms for models with latent quantities (unobserved heterogeneity, future expectations, equilibrium objects):
**NFXP (Nested Fixed-Point):** Solve the model in an inner loop for each parameter guess, evaluate likelihood/moments in an outer loop. Conceptually simple; inner loop must fully converge at every iteration — requires tight tolerance (1e-12, not 1e-6; see Su & Judd 2012).
**MPEC (Mathematical Programming with Equilibrium Constraints):** Reformulate as a single constrained optimization. No inner loop — solver handles everything; can be faster for large state spaces; requires IPOPT or KNITRO.
| Factor | Favors NFXP | Favors MPEC | |--------|-------------|-------------| | State space | Small (< 500 states) | Large (> 1000 states) | | Inner loop | Fast convergence (rate < 0.9) | Slow or fragile | | Solver availability | `scipy.optimize` sufficient | IPOPT/KNITRO available | | Debugging | Easier — isolate inner vs outer | Harder to diagnose constraint violations |
For full NFXP and MPEC code (Rust 1987 bus engine model), see `references/estimation-methods.md`.
BLP Demand Estimation
BLP (Berry, Levinsohn, Pakes 1995) is the workhorse for differentiated products demand. Use PyBLP whenever possible — it handles the difficult numerical details correctly.
import pyblp
# Define the problem
problem = pyblp.Problem(
product_formulations=(
pyblp.Formulation('1 + prices + x1 + x2'), # linear (β)
pyblp.Formulation('1 + prices + x1'), # random coefficients (Σ)
),
product_data=product_data,
agent_data=agent_data
)
# Solve — always use multiple starting values; BLP objective is non-convex
results = problem.solve(
sigma=sigma_init,
optimization=pyblp.Optimization('l-bfgs-b', {'gtol': 1e-8}),
iteration=pyblp.Iteration('squarem', {'atol': 1e-14}),
method='2s'
)For the full multi-start loop, two-step GMM, elasticity checks, instrument selection, and marginal cost computation, see `references/estimation-methods.md`.
**BLP Diagnostics Checklist:**
- [ ] First-stage F > 10 for price instruments
- [ ] Run 10+ ra
📌 文档结构(2026-07-22 起): 本文件是中文默认入口 —— banner + badges + 信任面 + 9 阶段流水线速览 + 76 行合集总表。 每个合集的完整描述、按用途分组、精确数字、验证方法在 docs/CONTENT_ZH.md(扩展正文,总表行内的 → 直接跳转到对应锚点)。 English version: README-en.md · 中文扩展正文:docs/CONTENT_ZH.md · README-zh-CN.md 已弃用(重定向占位) 🌐 语言: English |
Other skills on auto-empirical-research-skills.
- /pipeline
Classical end-to-end empirical analysis workflow in the traditional Python econometric stack — pandas + numpy + scipy + statsmodels + linearmodels + pyfixest + rdrobust + econml + causalml + matplotlib/seaborn. **Defaults to economics empirical-paper style** (AER / QJE / AEJ) —
Open skill - /pipeline
Classical end-to-end empirical analysis workflow in the modern tidyverse + econometrics R ecosystem — dplyr + tidyr + haven + fixest + sandwich + lmtest + clubSandwich + AER + ivreg + did + bacondecomp + HonestDiD + eventstudyr + rdrobust + rddensity + Synth + gsynth + synthdid
Open skill - /pipeline
Classical end-to-end empirical analysis workflow in the traditional Stata ecosystem — native Stata + reghdfe + ivreg2 + csdid + did_imputation + eventstudyinteract + sdid + rdrobust + rddensity + synth + synth_runner + psmatch2 + teffects + ebalance + coefplot + esttab + asdoc +
Open skill - /00-Full-empirical-analysis-skill_StatsPAI
Use when the user asks to run a full empirical / causal analysis in Python — by default in the style of an applied economics paper (AER / QJE / JPE / ReStud / AEJ) with DID / RD / IV / SCM / DML / matching, written-out estimating equation + identifying assumption, Table 1 /
Open skill - /00.1-Full-empirical-analysis-skill_Python
Classical end-to-end empirical analysis workflow in the traditional Python econometric stack — pandas + numpy + scipy + statsmodels + linearmodels + pyfixest + rdrobust + econml + causalml + matplotlib/seaborn. **Defaults to economics empirical-paper style** (AER / QJE / AEJ) —
Open skill - /00.2-Full-empirical-analysis-skill_Stata
Classical end-to-end empirical analysis workflow in the traditional Stata ecosystem — native Stata + reghdfe + ivreg2 + csdid + did_imputation + eventstudyinteract + sdid + rdrobust + rddensity + synth + synth_runner + psmatch2 + teffects + ebalance + coefplot + esttab + asdoc +
Open skill

