Stata Reference Guideのロゴ

Stata Reference Guide

コミュニティ
wentorai
stata-reference-guide

Comprehensive Stata reference covering syntax, econometrics, and 20+ packages

概要

公開者wentorai
リポジトリresearch-plugins
スキル名stata-reference-guide
スター
294
フォーク
42
同梱ファイル
指示のみ
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    wentoraiがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Stata Reference Guide」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/wentorai/research-plugins/tree/main/skills/analysis/econometrics/stata-reference-guide
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wentorai/research-plugins.git /tmp/research-plugins
mkdir -p .claude/skills
cp -r /tmp/research-plugins/skills/analysis/econometrics/stata-reference-guide .claude/skills/stata-reference-guide
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでStata Reference Guideを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にStata Reference Guideを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Stata Reference Guideは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Stata Comprehensive Reference Guide

Overview

Stata is the dominant statistical software in economics, political science, public health, and sociology research. This guide provides a comprehensive reference covering core syntax, data management, estimation commands, causal inference methods, graphics, Mata programming, and 20+ community-contributed packages. It is designed as a progressive-disclosure reference: use the section relevant to your current task rather than reading end-to-end.

Core Syntax and Data Management

Data Import and Export

stata
* Import CSV with variable names in first row
import delimited "data.csv", clear varnames(1)

* Import Excel (specific sheet and cell range)
import excel "workbook.xlsx", sheet("Sheet1") cellrange(A1:Z1000) firstrow clear

* Import Stata format
use "dataset.dta", clear

* Export to CSV
export delimited "output.csv", replace

* Save as Stata format
save "cleaned_data.dta", replace

Variable Management

stata
* Generate new variables
gen log_income = ln(income)
gen age_sq = age^2
gen treatment_post = treatment * post

* Recode and label
recode education (1/12 = 1 "HS or less") (13/16 = 2 "College") (17/20 = 3 "Graduate"), gen(edu_cat)
label variable edu_cat "Education Category"

* String operations
gen first_name = word(full_name, 1)
gen year_str = string(year)
destring price_str, gen(price) force

* Date handling
gen date = date(date_str, "YMD")
format date %td
gen year = year(date)
gen quarter = quarter(date)

Data Cleaning Patterns

stata
* Identify and handle duplicates
duplicates report id year
duplicates tag id year, gen(dup_flag)
duplicates drop id year, force

* Missing values
misstable summarize
misstable patterns
replace income = . if income < 0  // recode impossible values

* Merge datasets
merge 1:1 id year using "panel_data.dta", keep(match master) nogen
merge m:1 state year using "state_controls.dta", keep(match master) nogen

* Reshape between wide and long
reshape long income_, i(id) j(year)
reshape wide income, i(id) j(year)

* Collapse to group level
collapse (mean) avg_income=income (sd) sd_income=income (count) n=income, by(state year)

Estimation Commands

Linear Regression

stata
* OLS with robust standard errors
reg y x1 x2 x3, robust

* Clustered standard errors
reg y x1 x2 x3, cluster(firm_id)

* Fixed effects (within estimator)
xtreg y x1 x2 x3, fe cluster(firm_id)
xtset firm_id year  // must declare panel structure first

* Absorbing high-dimensional FE (reghdfe)
reghdfe y x1 x2 x3, absorb(firm_id year) cluster(firm_id)

* Instrumental variables (2SLS)
ivregress 2sls y x1 x2 (endog_var = instrument1 instrument2), robust
estat firststage
estat overid

Panel Data Methods

stata
* Panel setup
xtset firm_id year

* Hausman test (FE vs RE)
quietly xtreg y x1 x2, fe
estimates store fe
quietly xtreg y x1 x2, re
estimates store re
hausman fe re

* Dynamic panel GMM (xtabond2)
xtabond2 y L.y x1 x2, gmm(L.y, lag(2 4)) iv(x1 x2) robust twostep

* Test for serial correlation and overidentification
estat abond    // Arellano-Bond test
estat sargan   // Sargan/Hansen test

Causal Inference

stata
* Difference-in-Differences
gen did = treatment * post
reg y did treatment post controls, cluster(state)

* Modern DiD with staggered treatment (csdid)
csdid y x1 x2, ivar(id) time(year) gvar(first_treat) method(dripw)
csdid_plot  // event study plot

* Regression Discontinuity (rdrobust)
rdrobust y running_var, c(0) p(1) kernel(triangular)
rdplot y running_var, c(0) p(1)

* Propensity Score Matching (psmatch2)
psmatch2 treatment x1 x2 x3, outcome(y) logit caliper(0.05) common
pstest x1 x2 x3  // balance check

* Synthetic Control (synth)
synth y x1 x2 x3 y(1990) y(1991) y(1992), trunit(1) trperiod(1993) fig

Limited Dependent Variables

stata
* Logit/Probit
logit binary_y x1 x2, robust
margins, dydx(*)  // average marginal effects

probit binary_y x1 x2, robust
margins, dydx(*)

* Ordered logit
ologit ordered_y x1 x2, robust
margins, predict(outcome(3)) dydx(x1)

* Tobit (censored regression)
tobit y x1 x2, ll(0)

* Poisson and Negative Binomial
poisson count_y x1 x2, robust
nbreg count_y x1 x2, robust

Community Packages (20+)

Installation

stata
* Install from SSC (Statistical Software Components)
ssc install reghdfe
ssc install estout
ssc install coefplot
ssc install csdid
ssc install rdrobust
ssc install psmatch2
ssc install synth
ssc install ivreg2
ssc install xtabond2
ssc install winsor2
ssc install gtools
ssc install ftools
ssc install binscatter
ssc install binsreg
ssc install grstyle

* Install from GitHub
net install did_multiplegt, from("https://raw.githubusercontent.com/chaisemartinDehejia/did_multiplegt/main")

Publication-Quality Output

stata
* estout / esttab — formatted regression tables
eststo clear
eststo: reg y x1 x2, robust
eststo: reg y x1 x2 x3, robust
eststo: reg y x1 x2 x3, cluster(firm_id)
esttab, se star(* 0.10 ** 0.05 *** 0.01) ///
    title("Main Results") label replace ///
    scalars("r2 R-squared" "N Observations")

* Export to LaTeX
esttab using "table1.tex", replace booktabs ///
    se star(* 0.10 ** 0.05 *** 0.01) label

* Export to CSV/Excel
esttab using "table1.csv", replace se

* coefplot — coefficient visualization
coefplot est1 est2 est3, drop(_cons) xline(0) ///
    title("Coefficient Estimates") legend(order(1 "Model 1" 2 "Model 2" 3 "Model 3"))

Graphics

stata
* Scatter with fit line
twoway (scatter y x) (lfit y x), title("Y vs X") ///
    xtitle("X Variable") ytitle("Y Variable")

* Event study plot
coefplot, vertical drop(_cons) yline(0) ///
    title("Event Study") xtitle("Periods Relative to Treatment")

* Binned scatter (binscatter)
binscatter y x, controls(z1 z2) nquantiles(20) ///
    title("Binned Scatter") xtitle("X") ytitle("Y")

* Kernel density
kdensity income if year==2020, normal ///
    title("Income Distribution") xtitle("Income")

* Graph styling (grstyle)
grstyle init
grstyle set plain, horizontal grid
grstyle color background white
grstyle set color economist

Mata Programming

stata
* Basic Mata usage
mata:
    // Matrix operations
    X = st_data(., ("x1", "x2", "x3"))
    y = st_data(., "y")
    n = rows(X)

    // OLS by hand
    X = X, J(n, 1, 1)  // add constant
    beta = invsym(X'X) * X'y
    e = y - X * beta
    sigma2 = (e'e) / (n - cols(X))
    V = sigma2 * invsym(X'X)
    se = sqrt(diagonal(V))

    beta, se
end

Workflow Best Practices

  1. Always set a random seed before any procedure involving randomness: set seed 12345
  2. Use preserve/restore for temporary data manipulations within a do-file
  3. Log your sessions: log using "analysis_log.smcl", replace
  4. Version control: Start do-files with version 17 (or your version) for reproducibility
  5. Use tempfiles for intermediate datasets: tempfile merged then save merged'`
  6. Profile your code with timer on 1 / timer off 1 / timer list for long-running operations
  7. Use gtools (greshape, gcollapse, gegen) for 5-10x speedups on large datasets

References

よくある質問

AIスキル「Stata Reference Guide」では何ができますか?

Comprehensive Stata reference covering syntax, econometrics, and 20+ packages

TypingMindでStata Reference Guideを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Stata Reference Guideはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにStata Reference Guideをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/wentorai/research-plugins/tree/main/skills/analysis/econometrics/stata-reference-guideを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Stata Reference Guideを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Stata Reference Guideで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもStata Reference Guideを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Stata Reference Guide」は無料ですか?

はい。wentoraiがMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇