Stata Ai Fusion 标志

Stata Ai Fusion

社区
haoyu-haoyu
stata-ai-fusion

全能 Stata AI 助手,覆盖代码生成、执行和调试的完整工作流。用户提及 Stata、.do 文件、.dta 文件、回归分析、面板数据、生存分析、计量经济学、因果推断、数据清理或任何统计分析任务时,都应触发此技能。即使用户没有明确提到 Stata,只要之前的对话涉及 Stata,也应触发。也适用于调试 Stata .log 文件中的错误。

Add to TypingMind

概览

发布者haoyu-haoyu
代码仓库stata-ai-fusion
技能名称stata-ai-fusion
星标数
45
复刻数
7
附带文件
14
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 14 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 haoyu-haoyu 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Stata Ai Fusion AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/haoyu-haoyu/stata-ai-fusion/tree/main/skill
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/haoyu-haoyu/stata-ai-fusion.git /tmp/stata-ai-fusion
mkdir -p .claude/skills
cp -r /tmp/stata-ai-fusion/skill .claude/skills/stata-ai-fusion
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Stata Ai Fusion,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Stata Ai Fusion。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Stata Ai Fusion 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Stata AI Fusion Skill

You have access to comprehensive Stata reference files. Do not load all files. Read only the 1-3 files relevant to the user's current task using the routing table below.


1. Execution Mode Detection

Detect which execution mode is available and adapt accordingly.

MCP Mode (Stata MCP Server Available)

When the MCP server is connected, you can execute Stata code directly:

  • Use stata_run_command to run code and return results
  • Use stata_run_do_file to run full .do files
  • Use stata_inspect_data to inspect loaded datasets (summary stats, variable info)
  • Use stata_codebook to generate a codebook for the current dataset
  • Use stata_get_results to retrieve stored estimation results (r(), e(), s())
  • Use stata_export_graph to export the current Stata graph to an image
  • Use stata_search_log to search through Stata log output
  • Use stata_install_package to install community-contributed packages
  • Use stata_cancel_command to cancel a running Stata command
  • Use stata_list_sessions to list all active Stata sessions
  • Use stata_close_session to close a specific Stata session
  • Always check execution results before proceeding
  • If execution fails, read references/error-codes.md for diagnosis

Offline Mode (No MCP Server)

When MCP is not available, generate code for the user to run manually:

  • Write complete, self-contained .do files
  • Include version, clear all, set more off preamble
  • Add log using for output capture
  • Comment every non-obvious line
  • Wrap risky operations with capture and check _rc

Detection Logic

IF MCP tools are listed in available tools:
    -> Use MCP execution mode
    -> Run code incrementally, check results between steps
ELSE:
    -> Use offline code generation mode
    -> Produce complete .do file with full preamble

2. Core Coding Standards (Mandatory Rules)

Every piece of Stata code you generate MUST follow these rules. Violations cause silent bugs.

Missing Values Sort to +Infinity

Stata . (and .a-.z) are greater than all numbers.

stata
* WRONG -- includes observations where income is missing!
gen high_income = (income > 50000)

* RIGHT
gen high_income = (income > 50000) if !missing(income)

* WRONG -- missing ages appear in this list
list if age > 60

* RIGHT
list if age > 60 & !missing(age)

= vs ==

= is assignment; == is comparison. Mixing them is a syntax error or silent bug.

stata
* WRONG -- syntax error
gen employed = 1 if status = 1

* RIGHT
gen employed = 1 if status == 1

Local Macro Syntax

Locals use `name' (backtick + single-quote). Globals use $name or ${name}. Forgetting the closing quote is the number-one macro bug.

stata
local controls "age education income"
regress wage `controls'        // correct
regress wage `controls         // WRONG -- missing closing quote
regress wage 'controls'        // WRONG -- wrong quote characters

by Requires Prior Sort (Use bysort)

stata
* WRONG -- error if data not sorted by id
by id: gen first = (_n == 1)

* RIGHT -- bysort sorts automatically
bysort id: gen first = (_n == 1)

Factor Variable Notation (i. and c.)

stata
* WRONG -- treats race as continuous
regress wage race education

* RIGHT -- creates dummies automatically
regress wage i.race education

* Interactions
regress wage i.race##c.education    // full interaction
regress wage i.race#c.education     // interaction only (no main effects)

generate vs replace

generate creates new variables; replace modifies existing ones.

stata
gen x = 1
gen x = 2          // ERROR: x already defined
replace x = 2      // correct

String Comparison Is Case-Sensitive

stata
* May miss "Male", "MALE", etc.
keep if gender == "male"

* Safer
keep if lower(gender) == "male"

merge Always Check _merge

stata
merge 1:1 id using other.dta
tab _merge                      // always inspect
assert _merge == 3              // or handle mismatches
drop _merge

Line Continuation Uses ///

stata
regress y x1 x2 x3 ///
    x4 x5 x6, ///
    vce(robust)

Stored Results: r() vs e() vs s()

  • r() -- r-class commands (summarize, tabulate, etc.)
  • e() -- e-class commands (estimation: regress, logit, etc.)
  • s() -- s-class commands (parsing)

A new estimation command overwrites previous e() results. Store them first:

stata
regress y x1 x2
estimates store model1

Weights Are Not Interchangeable

  • fweight -- frequency weights (replication)
  • aweight -- analytic/regression weights (inverse variance)
  • pweight -- probability/sampling weights (survey data, implies robust SE)
  • iweight -- importance weights (rarely used)

preserve / restore for Temporary Changes

stata
preserve
collapse (mean) income, by(state)
* ... do something with collapsed data ...
restore   // original data is back

capture Swallows Errors

stata
capture some_command
if _rc != 0 {
    di as error "Failed with code: " _rc
    exit _rc
}

3. Workflow Templates

Data Cleaning Pipeline

stata
* 1. Load and inspect
import delimited "raw_data.csv", clear varnames(1)
describe
codebook, compact

* 2. Clean
rename *, lower
destring income, replace force
replace income = . if income < 0

* 3. Label
label variable income "Annual household income (USD)"
label define yesno 0 "No" 1 "Yes"
label values employed yesno

* 4. Save
compress
save "clean_data.dta", replace

Regression Table Workflow

stata
eststo clear
eststo: regress y x1 x2, vce(robust)
eststo: regress y x1 x2 x3, vce(robust)
eststo: regress y x1 x2 x3 x4, vce(cluster id)

esttab using "results.tex", replace ///
    se star(* 0.10 ** 0.05 *** 0.01) ///
    label booktabs ///
    title("Main Results") ///
    mtitles("(1)" "(2)" "(3)")

Panel Data Setup

stata
xtset panelid timevar
xtdescribe
xtsum outcome

xtreg y x1 x2, fe vce(cluster panelid)
* Or with reghdfe
reghdfe y x1 x2, absorb(panelid timevar) vce(cluster panelid)

Difference-in-Differences

stata
* Classic 2x2 DiD
gen post = (year >= treatment_year)
gen treat_post = treated * post
regress y treated post treat_post, vce(cluster id)

* Modern staggered DiD (Callaway & Sant'Anna)
csdid y x1 x2, ivar(id) time(year) gvar(first_treat) agg(event)
csdid_plot

Publication-Quality Graph

stata
twoway (scatter y x, mcolor(navy%50) msize(small)) ///
       (lfit y x, lcolor(cranberry) lwidth(medthick)), ///
    title("Title Here") ///
    xtitle("X Label") ytitle("Y Label") ///
    legend(off) scheme(plotplain)
graph export "figure1.pdf", replace as(pdf)
graph export "figure1.png", replace as(png) width(2400)

Multiple Imputation

stata
mi set mlong
mi register imputed income education
mi impute chained (regress) income (ologit) education ///
    = age i.gender, add(20) rseed(12345)
mi estimate: regress wage income education age i.gender

Survival Analysis Quick Start

stata
stset time_var, failure(event_var)
stsum
sts graph, by(group)
sts test group
stcox i.group age, vce(robust)
estat phtest, detail

4. Reference Document Navigation (Routing Table)

Read only the files relevant to the user's task. Paths are relative to this SKILL.md file.

Data Operations

FileTopics & Key Commands
references/syntax-core.mdVariable types, operators, conditionals, loops, macros, string/numeric/date functions
references/data-management.mdimport/export, merge, reshape, collapse, egen, encode/decode, append, tempfile
references/defensive-coding.mdassert, confirm, capture, isid, version, log management

Econometrics & Statistics

FileTopics & Key Commands
references/econometrics.mdOLS, IV/2SLS, GMM, Panel FE/RE, Hausman, cluster SE, robust SE, reghdfe
references/causal-inference.mdDID, Event Study, RDD, Synthetic Control, Matching, PSM, IPTW
references/survival-analysis.mdstset, KM curves, stcox, streg, competing risks, estat phtest

Clinical & Domain-Specific

FileTopics & Key Commands
references/clinical-data.mdMIMIC-IV, ICD coding, lab values, Sepsis-3, KDIGO, mi impute

Output & Visualization

FileTopics & Key Commands
references/graphics.mdtwoway, graph bar/box/dot/pie, schemes, coefplot, binscatter
references/tables-export.mdesttab/estout, outreg2, putexcel, collect framework, LaTeX/Word/CSV

Programming & Advanced

FileTopics & Key Commands
references/mata.mdMata basics, matrix ops, st_view/st_store, custom functions
references/error-codes.mdCommon Stata error codes with explanations and solutions

Community Packages

FileWhat It Does
references/packages/reghdfe.mdHigh-dimensional FE regression with multi-way clustering
references/packages/coefplot.mdCoefficient plots, event study plots, multi-model comparison
references/packages/gtools.mdgcollapse, gegen, greshape -- fast data manipulation

5. MCP Tools Usage Guide

Tool Combination Patterns

Pattern A: Iterative Analysis

1. stata_run_command("use mydata.dta, clear")  -> load data
2. stata_run_command("describe")               -> understand structure
3. stata_run_command("regress y x1 x2")        -> run model
4. Read results, decide next step
5. stata_run_command("esttab using ...")        -> export table

Pattern B: Debug Workflow

1. User pastes error from .log file
2. Read references/error-codes.md for the error code
3. Identify the root cause
4. stata_run_command(corrected_code)      -> verify fix
5. Explain what went wrong

Pattern C: Full Pipeline

1. stata_run_command("import delimited ...")  -> load raw data
2. stata_run_command("describe \n codebook")  -> inspect
3. Generate cleaning code based on inspection
4. stata_run_command(cleaning_code)           -> clean
5. stata_run_command(analysis_code)           -> analyze
6. stata_run_command(export_code)             -> export results

Error Recovery in MCP Mode

When an MCP execution returns an error:

  1. Parse the error code (e.g., r(111), r(198), r(601))
  2. Look up in references/error-codes.md
  3. Apply the documented fix
  4. Re-execute the corrected code
  5. If still failing, try alternative approaches

Code Generation for Offline Mode

When generating .do files for users to run manually:

stata
/* ============================================================
   Project:  [Project Name]
   Purpose:  [What this do-file does]
   Author:   AI-generated via stata-ai-fusion
   Date:     [Current Date]
   Input:    [Input files]
   Output:   [Output files]
   ============================================================ */

version 17
clear all
set more off
set maxvar 10000

* -- Set paths --
global root "[USER_PATH]"
global data "$root/data"
global output "$root/output"

log using "$output/logs/analysis_log.txt", replace text

* -- Body --
// ... analysis code ...

log close

6. Common Code Snippets

Quick Summary Statistics

stata
summarize price mpg weight, detail
tabstat price mpg, by(foreign) stat(n mean sd p25 p50 p75)

Winsorize at 1%/99%

stata
foreach var of varlist income wealth {
    quietly summarize `var', detail
    replace `var' = r(p1) if `var' < r(p1) & !missing(`var')
    replace `var' = r(p99) if `var' > r(p99) & !missing(`var')
}

Create Balanced Panel

stata
xtset id year
bysort id: gen n_years = _N
tab n_years
keep if n_years == [expected_T]

Standardize Variables (Z-score)

stata
foreach var of varlist x1 x2 x3 {
    quietly summarize `var'
    gen `var'_z = (`var' - r(mean)) / r(sd)
}

Lag and Lead Variables in Panel

stata
xtset id year
gen y_lag1 = L.y
gen y_lag2 = L2.y
gen y_lead1 = F.y
gen y_diff = D.y

Quick Coefficient Plot

stata
regress y x1 x2 x3 x4, vce(robust)
coefplot, drop(_cons) xline(0, lcolor(red) lpattern(dash)) ///
    title("Coefficient Estimates") scheme(plotplain)
graph export "coefplot.png", replace width(2000)

Export Summary Table to Excel

stata
putexcel set "summary.xlsx", replace sheet("Summary")
putexcel A1 = "Variable" B1 = "N" C1 = "Mean" D1 = "SD"
local row = 2
foreach var of varlist income age education {
    quietly summarize `var'
    putexcel A`row' = "`var'" B`row' = r(N) ///
        C`row' = r(mean) D`row' = r(sd)
    local ++row
}

Propensity Score Matching (Quick)

stata
logit treatment x1 x2 x3
predict pscore, pr
psmatch2 treatment, pscore(pscore) outcome(y) n(1) common

Event Study Plot (Quick)

stata
gen rel_time = year - treatment_year
forvalues k = -5/5 {
    if `k' < 0 local j = abs(`k')
    else       local j = `k'
    gen D`j'_`=cond(`k'<0,"pre","post")' = (rel_time == `k')
}
* Omit period -1 as reference
reghdfe y D*_pre D*_post, absorb(id year) vce(cluster id)
coefplot, keep(D*) vertical yline(0) xline(5.5, lpattern(dash))

Check for Multicollinearity

stata
regress y x1 x2 x3 x4
estat vif
* VIF > 10 indicates concern

Robust Hausman Test (with clustered SE)

stata
* Standard Hausman fails with robust/cluster SE. Use this instead:
xtreg y x1 x2, fe vce(cluster id)
estimates store fe
xtreg y x1 x2, re vce(cluster id)
estimates store re
hausman fe re, sigmamore

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Stata Ai Fusion AI 技能有什么作用?

全能 Stata AI 助手,覆盖代码生成、执行和调试的完整工作流。用户提及 Stata、.do 文件、.dta 文件、回归分析、面板数据、生存分析、计量经济学、因果推断、数据清理或任何统计分析任务时,都应触发此技能。即使用户没有明确提到 Stata,只要之前的对话涉及 Stata,也应触发。也适用于调试 Stata .log 文件中的错误。

为什么在 TypingMind 中使用 Stata Ai Fusion?

因为您只需安装一次,就能搭配任何模型使用。Stata Ai Fusion 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Stata Ai Fusion?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/haoyu-haoyu/stata-ai-fusion/tree/main/skill。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Stata Ai Fusion?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Stata Ai Fusion 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Stata Ai Fusion 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Stata Ai Fusion AI 技能免费吗?

是的。haoyu-haoyu 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇