@wentorai/research-plugins 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -22
- package/curated/analysis/README.md +71 -56
- package/curated/domains/README.md +176 -67
- package/curated/literature/README.md +71 -47
- package/curated/research/README.md +91 -58
- package/curated/tools/README.md +88 -87
- package/curated/writing/README.md +80 -45
- package/mcp-configs/cloud-docs/confluence-mcp.json +37 -0
- package/mcp-configs/cloud-docs/google-drive-mcp.json +35 -0
- package/mcp-configs/cloud-docs/notion-mcp.json +29 -0
- package/mcp-configs/communication/discord-mcp.json +29 -0
- package/mcp-configs/communication/slack-mcp.json +29 -0
- package/mcp-configs/communication/telegram-mcp.json +28 -0
- package/mcp-configs/database/neo4j-mcp.json +37 -0
- package/mcp-configs/database/postgres-mcp.json +28 -0
- package/mcp-configs/database/sqlite-mcp.json +29 -0
- package/mcp-configs/dev-platform/github-mcp.json +31 -0
- package/mcp-configs/dev-platform/gitlab-mcp.json +34 -0
- package/mcp-configs/email/email-mcp.json +40 -0
- package/mcp-configs/email/gmail-mcp.json +37 -0
- package/mcp-configs/registry.json +178 -149
- package/mcp-configs/repository/dataverse-mcp.json +33 -0
- package/mcp-configs/repository/huggingface-mcp.json +29 -0
- package/openclaw.plugin.json +2 -2
- package/package.json +2 -2
- package/skills/analysis/dataviz/algorithm-visualizer-guide/SKILL.md +259 -0
- package/skills/analysis/dataviz/bokeh-visualization-guide/SKILL.md +270 -0
- package/skills/analysis/dataviz/chart-image-generator/SKILL.md +229 -0
- package/skills/analysis/dataviz/d3-visualization-guide/SKILL.md +281 -0
- package/skills/analysis/dataviz/echarts-visualization-guide/SKILL.md +250 -0
- package/skills/analysis/dataviz/metabase-analytics-guide/SKILL.md +242 -0
- package/skills/analysis/dataviz/plotly-interactive-guide/SKILL.md +266 -0
- package/skills/analysis/dataviz/redash-analytics-guide/SKILL.md +284 -0
- package/skills/analysis/econometrics/econml-causal-guide/SKILL.md +163 -0
- package/skills/analysis/econometrics/mostly-harmless-guide/SKILL.md +139 -0
- package/skills/analysis/econometrics/panel-data-analyst/SKILL.md +259 -0
- package/skills/analysis/econometrics/python-causality-guide/SKILL.md +134 -0
- package/skills/analysis/econometrics/stata-accounting-guide/SKILL.md +269 -0
- package/skills/analysis/econometrics/stata-analyst-guide/SKILL.md +245 -0
- package/skills/analysis/statistics/data-anomaly-detection/SKILL.md +157 -0
- package/skills/analysis/statistics/ml-experiment-tracker/SKILL.md +212 -0
- package/skills/analysis/statistics/pywayne-statistics-guide/SKILL.md +192 -0
- package/skills/analysis/statistics/quantitative-methods-guide/SKILL.md +193 -0
- package/skills/analysis/statistics/senior-data-scientist-guide/SKILL.md +223 -0
- package/skills/analysis/wrangling/csv-data-analyzer/SKILL.md +170 -0
- package/skills/analysis/wrangling/data-cleaning-pipeline/SKILL.md +266 -0
- package/skills/analysis/wrangling/data-cog-guide/SKILL.md +178 -0
- package/skills/analysis/wrangling/stata-data-cleaning/SKILL.md +276 -0
- package/skills/analysis/wrangling/survey-data-processing/SKILL.md +298 -0
- package/skills/domains/ai-ml/ai-model-benchmarking/SKILL.md +209 -0
- package/skills/domains/ai-ml/annotated-dl-papers-guide/SKILL.md +159 -0
- package/skills/domains/ai-ml/dl-transformer-finetune/SKILL.md +239 -0
- package/skills/domains/ai-ml/generative-ai-guide/SKILL.md +146 -0
- package/skills/domains/ai-ml/huggingface-inference-guide/SKILL.md +196 -0
- package/skills/domains/ai-ml/keras-deep-learning/SKILL.md +210 -0
- package/skills/domains/ai-ml/llm-from-scratch-guide/SKILL.md +124 -0
- package/skills/domains/ai-ml/ml-pipeline-guide/SKILL.md +295 -0
- package/skills/domains/ai-ml/nlp-toolkit-guide/SKILL.md +247 -0
- package/skills/domains/ai-ml/pytorch-guide/SKILL.md +281 -0
- package/skills/domains/ai-ml/pytorch-lightning-guide/SKILL.md +244 -0
- package/skills/domains/ai-ml/tensorflow-guide/SKILL.md +241 -0
- package/skills/domains/biomedical/bioagents-guide/SKILL.md +308 -0
- package/skills/domains/biomedical/medgeclaw-guide/SKILL.md +345 -0
- package/skills/domains/biomedical/medical-imaging-guide/SKILL.md +305 -0
- package/skills/domains/business/architecture-design-guide/SKILL.md +279 -0
- package/skills/domains/business/innovation-management-guide/SKILL.md +257 -0
- package/skills/domains/business/operations-research-guide/SKILL.md +258 -0
- package/skills/domains/chemistry/molecular-dynamics-guide/SKILL.md +237 -0
- package/skills/domains/chemistry/pubchem-api-guide/SKILL.md +180 -0
- package/skills/domains/chemistry/spectroscopy-analysis-guide/SKILL.md +290 -0
- package/skills/domains/cs/distributed-systems-guide/SKILL.md +268 -0
- package/skills/domains/cs/formal-verification-guide/SKILL.md +298 -0
- package/skills/domains/ecology/species-distribution-guide/SKILL.md +343 -0
- package/skills/domains/economics/imf-data-api-guide/SKILL.md +174 -0
- package/skills/domains/economics/post-labor-economics/SKILL.md +254 -0
- package/skills/domains/economics/pricing-psychology-guide/SKILL.md +273 -0
- package/skills/domains/economics/world-bank-data-guide/SKILL.md +179 -0
- package/skills/domains/education/assessment-design-guide/SKILL.md +213 -0
- package/skills/domains/education/educational-research-methods/SKILL.md +179 -0
- package/skills/domains/education/mooc-analytics-guide/SKILL.md +206 -0
- package/skills/domains/finance/portfolio-optimization-guide/SKILL.md +279 -0
- package/skills/domains/finance/risk-modeling-guide/SKILL.md +260 -0
- package/skills/domains/finance/stata-accounting-research/SKILL.md +372 -0
- package/skills/domains/geoscience/climate-modeling-guide/SKILL.md +215 -0
- package/skills/domains/geoscience/satellite-remote-sensing/SKILL.md +193 -0
- package/skills/domains/geoscience/seismology-data-guide/SKILL.md +208 -0
- package/skills/domains/humanities/ethical-philosophy-guide/SKILL.md +244 -0
- package/skills/domains/humanities/history-research-guide/SKILL.md +260 -0
- package/skills/domains/humanities/political-history-guide/SKILL.md +241 -0
- package/skills/domains/law/legal-nlp-guide/SKILL.md +236 -0
- package/skills/domains/law/patent-analysis-guide/SKILL.md +257 -0
- package/skills/domains/law/regulatory-compliance-guide/SKILL.md +267 -0
- package/skills/domains/math/symbolic-computation-guide/SKILL.md +263 -0
- package/skills/domains/math/topology-data-analysis/SKILL.md +305 -0
- package/skills/domains/pharma/clinical-trial-design-guide/SKILL.md +271 -0
- package/skills/domains/pharma/drug-target-interaction/SKILL.md +242 -0
- package/skills/domains/pharma/pharmacovigilance-guide/SKILL.md +216 -0
- package/skills/domains/physics/astrophysics-data-guide/SKILL.md +305 -0
- package/skills/domains/physics/particle-physics-guide/SKILL.md +287 -0
- package/skills/domains/social-science/network-analysis-guide/SKILL.md +310 -0
- package/skills/domains/social-science/psychology-research-guide/SKILL.md +270 -0
- package/skills/domains/social-science/sociology-research-guide/SKILL.md +238 -0
- package/skills/literature/discovery/paper-recommendation-guide/SKILL.md +120 -0
- package/skills/literature/discovery/semantic-paper-radar/SKILL.md +144 -0
- package/skills/literature/discovery/zotero-arxiv-daily-guide/SKILL.md +94 -0
- package/skills/literature/fulltext/core-api-guide/SKILL.md +144 -0
- package/skills/literature/fulltext/institutional-repository-guide/SKILL.md +212 -0
- package/skills/literature/fulltext/open-access-mining-guide/SKILL.md +341 -0
- package/skills/literature/metadata/academic-paper-summarizer/SKILL.md +101 -0
- package/skills/literature/metadata/wikidata-api-guide/SKILL.md +156 -0
- package/skills/literature/search/arxiv-batch-reporting/SKILL.md +133 -0
- package/skills/literature/search/arxiv-paper-processor/SKILL.md +141 -0
- package/skills/literature/search/baidu-scholar-guide/SKILL.md +110 -0
- package/skills/literature/search/chatpaper-guide/SKILL.md +122 -0
- package/skills/literature/search/deep-literature-search/SKILL.md +149 -0
- package/skills/literature/search/deepgit-search-guide/SKILL.md +147 -0
- package/skills/literature/search/pasa-paper-search-guide/SKILL.md +138 -0
- package/skills/research/automation/ai-scientist-v2-guide/SKILL.md +284 -0
- package/skills/research/automation/aim-experiment-guide/SKILL.md +234 -0
- package/skills/research/automation/datagen-research-guide/SKILL.md +131 -0
- package/skills/research/automation/kedro-pipeline-guide/SKILL.md +216 -0
- package/skills/research/automation/mle-agent-guide/SKILL.md +139 -0
- package/skills/research/automation/paper-to-agent-guide/SKILL.md +116 -0
- package/skills/research/automation/rd-agent-guide/SKILL.md +246 -0
- package/skills/research/automation/research-paper-orchestrator/SKILL.md +254 -0
- package/skills/research/deep-research/academic-deep-research/SKILL.md +190 -0
- package/skills/research/deep-research/auto-deep-research-guide/SKILL.md +141 -0
- package/skills/research/deep-research/deep-research-pro/SKILL.md +213 -0
- package/skills/research/deep-research/deep-research-work/SKILL.md +204 -0
- package/skills/research/deep-research/deep-searcher-guide/SKILL.md +253 -0
- package/skills/research/deep-research/gpt-researcher-guide/SKILL.md +191 -0
- package/skills/research/deep-research/khoj-research-guide/SKILL.md +200 -0
- package/skills/research/deep-research/local-deep-research-guide/SKILL.md +253 -0
- package/skills/research/deep-research/tongyi-deep-research-guide/SKILL.md +217 -0
- package/skills/research/funding/eu-horizon-guide/SKILL.md +244 -0
- package/skills/research/funding/grant-budget-guide/SKILL.md +284 -0
- package/skills/research/funding/nih-reporter-api-guide/SKILL.md +166 -0
- package/skills/research/funding/nsf-award-api-guide/SKILL.md +133 -0
- package/skills/research/methodology/academic-mentor-guide/SKILL.md +169 -0
- package/skills/research/methodology/claude-scientific-guide/SKILL.md +122 -0
- package/skills/research/methodology/deep-innovator-guide/SKILL.md +242 -0
- package/skills/research/methodology/osf-api-guide/SKILL.md +165 -0
- package/skills/research/methodology/research-paper-kb/SKILL.md +263 -0
- package/skills/research/methodology/research-town-guide/SKILL.md +263 -0
- package/skills/research/paper-review/automated-review-guide/SKILL.md +281 -0
- package/skills/research/paper-review/paper-compare-guide/SKILL.md +238 -0
- package/skills/research/paper-review/paper-digest-guide/SKILL.md +240 -0
- package/skills/research/paper-review/paper-research-assistant/SKILL.md +231 -0
- package/skills/research/paper-review/research-quality-filter/SKILL.md +261 -0
- package/skills/research/paper-review/review-response-guide/SKILL.md +275 -0
- package/skills/tools/code-exec/google-colab-guide/SKILL.md +276 -0
- package/skills/tools/code-exec/kaggle-api-guide/SKILL.md +216 -0
- package/skills/tools/code-exec/overleaf-cli-guide/SKILL.md +279 -0
- package/skills/tools/diagram/code-flow-visualizer/SKILL.md +197 -0
- package/skills/tools/diagram/excalidraw-diagram-guide/SKILL.md +170 -0
- package/skills/tools/diagram/json-data-visualizer/SKILL.md +270 -0
- package/skills/tools/diagram/mermaid-architect-guide/SKILL.md +219 -0
- package/skills/tools/diagram/tldraw-whiteboard-guide/SKILL.md +397 -0
- package/skills/tools/document/docsgpt-guide/SKILL.md +130 -0
- package/skills/tools/document/large-document-reader/SKILL.md +202 -0
- package/skills/tools/document/paper-parse-guide/SKILL.md +243 -0
- package/skills/tools/knowledge-graph/citation-network-builder/SKILL.md +244 -0
- package/skills/tools/knowledge-graph/concept-map-generator/SKILL.md +284 -0
- package/skills/tools/knowledge-graph/graphiti-guide/SKILL.md +219 -0
- package/skills/tools/ocr-translate/pdf-math-translate-guide/SKILL.md +141 -0
- package/skills/tools/ocr-translate/zotero-pdf-translate-guide/SKILL.md +95 -0
- package/skills/tools/ocr-translate/zotero-pdf2zh-guide/SKILL.md +143 -0
- package/skills/tools/scraping/dataset-finder-guide/SKILL.md +253 -0
- package/skills/tools/scraping/easy-spider-guide/SKILL.md +250 -0
- package/skills/tools/scraping/google-scholar-scraper/SKILL.md +255 -0
- package/skills/tools/scraping/repository-harvesting-guide/SKILL.md +310 -0
- package/skills/writing/citation/academic-citation-manager/SKILL.md +314 -0
- package/skills/writing/citation/jabref-reference-guide/SKILL.md +127 -0
- package/skills/writing/citation/jasminum-zotero-guide/SKILL.md +103 -0
- package/skills/writing/citation/obsidian-citation-guide/SKILL.md +164 -0
- package/skills/writing/citation/obsidian-zotero-guide/SKILL.md +137 -0
- package/skills/writing/citation/papersgpt-zotero-guide/SKILL.md +132 -0
- package/skills/writing/citation/papis-cli-guide/SKILL.md +213 -0
- package/skills/writing/citation/zotero-better-bibtex-guide/SKILL.md +107 -0
- package/skills/writing/citation/zotero-better-notes-guide/SKILL.md +121 -0
- package/skills/writing/citation/zotero-gpt-guide/SKILL.md +111 -0
- package/skills/writing/citation/zotero-mcp-guide/SKILL.md +164 -0
- package/skills/writing/citation/zotero-mdnotes-guide/SKILL.md +162 -0
- package/skills/writing/citation/zotero-reference-guide/SKILL.md +139 -0
- package/skills/writing/citation/zotero-scholar-guide/SKILL.md +294 -0
- package/skills/writing/citation/zotfile-attachment-guide/SKILL.md +140 -0
- package/skills/writing/composition/ml-paper-writing/SKILL.md +163 -0
- package/skills/writing/composition/paper-debugger-guide/SKILL.md +143 -0
- package/skills/writing/composition/scientific-writing-resources/SKILL.md +151 -0
- package/skills/writing/composition/scientific-writing-wrapper/SKILL.md +153 -0
- package/skills/writing/latex/latex-drawing-collection/SKILL.md +154 -0
- package/skills/writing/latex/latex-templates-collection/SKILL.md +159 -0
- package/skills/writing/latex/md-to-pdf-academic/SKILL.md +230 -0
- package/skills/writing/latex/tex-render-guide/SKILL.md +243 -0
- package/skills/writing/polish/academic-tone-guide/SKILL.md +209 -0
- package/skills/writing/polish/conciseness-editing-guide/SKILL.md +225 -0
- package/skills/writing/polish/paper-polish-guide/SKILL.md +160 -0
- package/skills/writing/templates/graphical-abstract-guide/SKILL.md +183 -0
- package/skills/writing/templates/novathesis-guide/SKILL.md +152 -0
- package/skills/writing/templates/scientific-article-pdf/SKILL.md +261 -0
- package/skills/writing/templates/sjtuthesis-guide/SKILL.md +197 -0
- package/skills/writing/templates/thuthesis-guide/SKILL.md +181 -0
- package/skills/literature/fulltext/repository-harvesting-guide/SKILL.md +0 -207
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: python-causality-guide
|
|
3
|
+
description: "Learn causal inference with Python using the Brave and True handbook"
|
|
4
|
+
metadata:
|
|
5
|
+
openclaw:
|
|
6
|
+
emoji: "📊"
|
|
7
|
+
category: analysis
|
|
8
|
+
subcategory: econometrics
|
|
9
|
+
keywords: ["causal-inference", "python", "econometrics", "statistics", "treatment-effects", "observational-studies"]
|
|
10
|
+
source: "https://github.com/matheusfacure/python-causality-handbook"
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Causal Inference for the Brave and True
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
Causal Inference for the Brave and True is an open-source, Python-based textbook by Matheus Facure that teaches causal inference methods through practical implementations. The book bridges the gap between theoretical econometrics textbooks and hands-on data science practice, presenting each method with runnable Python code, real-world datasets, and intuitive explanations that demystify the mathematics behind causal reasoning.
|
|
18
|
+
|
|
19
|
+
The handbook covers the full spectrum of causal inference techniques used in modern empirical research, from foundational concepts like potential outcomes and directed acyclic graphs (DAGs) through advanced methods including instrumental variables, regression discontinuity, difference-in-differences, and synthetic control. Each chapter builds on the previous one, constructing a coherent framework for thinking about causation from observational data.
|
|
20
|
+
|
|
21
|
+
With over 3,000 GitHub stars, this resource has become a standard reference for graduate students, applied researchers, and data scientists seeking to add causal reasoning to their analytical toolkit. The emphasis on Python implementation makes it directly applicable to modern research workflows.
|
|
22
|
+
|
|
23
|
+
## Installation and Setup
|
|
24
|
+
|
|
25
|
+
The handbook runs as Jupyter notebooks. Set up the environment:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/matheusfacure/python-causality-handbook.git
|
|
29
|
+
cd python-causality-handbook
|
|
30
|
+
|
|
31
|
+
# Create a virtual environment
|
|
32
|
+
python -m venv causal-env
|
|
33
|
+
source causal-env/bin/activate
|
|
34
|
+
|
|
35
|
+
# Install dependencies
|
|
36
|
+
pip install numpy pandas matplotlib seaborn scikit-learn statsmodels
|
|
37
|
+
pip install linearmodels causalinference
|
|
38
|
+
pip install jupyter
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Launch the notebook server:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
jupyter notebook
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The chapters are organized as numbered Jupyter notebooks, starting from foundational concepts and progressing to advanced methods. Each notebook is self-contained with all data loading and analysis code included.
|
|
48
|
+
|
|
49
|
+
## Core Methods Covered
|
|
50
|
+
|
|
51
|
+
**Potential Outcomes Framework**: The book begins by establishing the Neyman-Rubin potential outcomes model, defining treatment effects and the fundamental problem of causal inference:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import pandas as pd
|
|
55
|
+
import numpy as np
|
|
56
|
+
from scipy.stats import ttest_ind
|
|
57
|
+
|
|
58
|
+
# Estimate ATE from randomized experiment
|
|
59
|
+
treated = data[data["treatment"] == 1]["outcome"]
|
|
60
|
+
control = data[data["treatment"] == 0]["outcome"]
|
|
61
|
+
ate = treated.mean() - control.mean()
|
|
62
|
+
t_stat, p_value = ttest_ind(treated, control)
|
|
63
|
+
print(f"ATE: {ate:.3f}, p-value: {p_value:.4f}")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Regression and Matching**: OLS regression for causal estimation, understanding omitted variable bias, propensity score methods, and matching estimators:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import statsmodels.formula.api as smf
|
|
70
|
+
|
|
71
|
+
# OLS with controls
|
|
72
|
+
model = smf.ols("outcome ~ treatment + age + income + education", data=data)
|
|
73
|
+
results = model.fit(cov_type="HC1")
|
|
74
|
+
print(results.summary().tables[1])
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Instrumental Variables**: Two-stage least squares and the local average treatment effect, with practical guidance on instrument validity and weak instrument diagnostics:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from linearmodels.iv import IV2SLS
|
|
81
|
+
|
|
82
|
+
# Two-stage least squares
|
|
83
|
+
iv_formula = "outcome ~ 1 + [treatment ~ instrument]"
|
|
84
|
+
iv_model = IV2SLS.from_formula(iv_formula, data=data)
|
|
85
|
+
iv_results = iv_model.fit(cov_type="robust")
|
|
86
|
+
print(iv_results.summary)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Difference-in-Differences**: Parallel trends assumption, two-way fixed effects, event study designs, and staggered treatment adoption:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
# Difference-in-Differences with two-way fixed effects
|
|
93
|
+
did_model = smf.ols(
|
|
94
|
+
"outcome ~ treated_post + C(unit_id) + C(time_period)",
|
|
95
|
+
data=panel_data
|
|
96
|
+
)
|
|
97
|
+
did_results = did_model.fit(cov_type="cluster", cov_kwds={"groups": panel_data["unit_id"]})
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Regression Discontinuity**: Sharp and fuzzy RD designs, bandwidth selection, and local polynomial estimation for identifying causal effects at policy thresholds.
|
|
101
|
+
|
|
102
|
+
**Synthetic Control**: Constructing counterfactual units from donor pools for comparative case studies, with inference via placebo tests.
|
|
103
|
+
|
|
104
|
+
## Research Workflow Integration
|
|
105
|
+
|
|
106
|
+
**Graduate Coursework**: The handbook maps directly to applied econometrics and causal inference course syllabi. Students can follow along with lectures by running the corresponding notebooks, experimenting with parameter changes, and observing how different assumptions affect estimates.
|
|
107
|
+
|
|
108
|
+
**Method Selection Guide**: Use the decision framework presented across chapters to choose the appropriate method for your research question:
|
|
109
|
+
|
|
110
|
+
- Randomized experiment available: simple comparison of means or regression adjustment
|
|
111
|
+
- Selection on observables: matching, propensity scores, or regression
|
|
112
|
+
- Unobserved confounders with instrument: instrumental variables
|
|
113
|
+
- Policy threshold: regression discontinuity
|
|
114
|
+
- Before/after with control group: difference-in-differences
|
|
115
|
+
- Single treated unit over time: synthetic control
|
|
116
|
+
|
|
117
|
+
**Replication and Extension**: Each chapter uses real or realistic datasets. Researchers can adapt the code to their own data by replacing data loading steps while preserving the analytical pipeline.
|
|
118
|
+
|
|
119
|
+
**Teaching Tool**: Instructors can assign chapters as interactive homework, asking students to modify assumptions, change specifications, or apply methods to new datasets. The notebook format makes it straightforward to create assignments with embedded solutions.
|
|
120
|
+
|
|
121
|
+
## Best Practices Highlighted in the Handbook
|
|
122
|
+
|
|
123
|
+
1. **Always graph your data first**: Visual inspection reveals patterns that inform modeling choices and expose violations of identifying assumptions.
|
|
124
|
+
2. **Understand your identification strategy**: Before running any estimator, articulate clearly what variation identifies the causal effect and what assumptions are required.
|
|
125
|
+
3. **Cluster standard errors appropriately**: When treatment is assigned at group level, cluster standard errors at that level to avoid overstating statistical significance.
|
|
126
|
+
4. **Run robustness checks**: Vary specifications, bandwidths, control variables, and functional forms to assess sensitivity of conclusions.
|
|
127
|
+
5. **Report effect sizes alongside p-values**: Statistical significance without practical significance is not informative for policy or scientific understanding.
|
|
128
|
+
|
|
129
|
+
## References
|
|
130
|
+
|
|
131
|
+
- Python Causality Handbook: https://github.com/matheusfacure/python-causality-handbook
|
|
132
|
+
- Online version: https://matheusfacure.github.io/python-causality-handbook/
|
|
133
|
+
- Angrist and Pischke, Mostly Harmless Econometrics (companion reference)
|
|
134
|
+
- Cunningham, Causal Inference: The Mixtape (complementary resource)
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: stata-accounting-guide
|
|
3
|
+
description: "STATA code for empirical accounting and financial economics research"
|
|
4
|
+
metadata:
|
|
5
|
+
openclaw:
|
|
6
|
+
emoji: "ledger"
|
|
7
|
+
category: "analysis"
|
|
8
|
+
subcategory: "econometrics"
|
|
9
|
+
keywords: ["Stata", "accounting research", "Compustat", "CRSP", "earnings management", "financial economics"]
|
|
10
|
+
source: "https://www.stata.com"
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Stata Accounting Research Guide
|
|
14
|
+
|
|
15
|
+
Generate publication-ready Stata code for empirical accounting research. This skill covers the standard econometric models, variable constructions, and estimation procedures used in top accounting journals (TAR, JAR, JAE, RAS, CAR).
|
|
16
|
+
|
|
17
|
+
## Overview
|
|
18
|
+
|
|
19
|
+
Empirical accounting research has developed a distinctive set of analytical conventions that differ from general econometrics. Researchers work with financial statement data from databases like Compustat and CRSP, construct standardized proxies for earnings quality, accruals, and discretionary behavior, and employ estimation techniques that address the particular endogeneity concerns in archival accounting studies.
|
|
20
|
+
|
|
21
|
+
This skill provides the Stata implementation for the most commonly used models in accounting research: accrual models (Jones, Modified Jones, performance-matched), earnings management detection, value relevance studies, audit quality analyses, and corporate governance research. Each model includes the variable construction from raw Compustat items, the estimation procedure, and the table formatting expected by accounting journal reviewers.
|
|
22
|
+
|
|
23
|
+
The code follows the conventions established in influential methodological papers by Dechow, Sloan, and Sweeney (1995), Kothari, Leone, and Wasley (2005), and Ecker, Francis, Kim, Olsson, and Schipper (2006), ensuring alignment with reviewer expectations at major accounting journals.
|
|
24
|
+
|
|
25
|
+
## Data Preparation from Compustat
|
|
26
|
+
|
|
27
|
+
### Variable Construction
|
|
28
|
+
|
|
29
|
+
```stata
|
|
30
|
+
* ============================================
|
|
31
|
+
* Standard Compustat Variable Construction
|
|
32
|
+
* ============================================
|
|
33
|
+
|
|
34
|
+
* Load Compustat annual data
|
|
35
|
+
use "raw/compustat_annual.dta", clear
|
|
36
|
+
|
|
37
|
+
* Fiscal year identifier
|
|
38
|
+
gen fyear = year(datadate)
|
|
39
|
+
|
|
40
|
+
* Key financial variables (Compustat mnemonics)
|
|
41
|
+
* Total accruals (balance sheet approach)
|
|
42
|
+
gen total_accruals_bs = (dch_act - dch_che) - (dch_lct - dch_dlc - dch_txp) - dp
|
|
43
|
+
replace total_accruals_bs = total_accruals_bs / l.at // Scale by lagged assets
|
|
44
|
+
|
|
45
|
+
* Total accruals (cash flow approach, preferred)
|
|
46
|
+
gen total_accruals_cf = (ib - oancf) / l.at
|
|
47
|
+
|
|
48
|
+
* Key ratios
|
|
49
|
+
gen roa = ib / l.at // Return on assets
|
|
50
|
+
gen leverage = (dltt + dlc) / at // Financial leverage
|
|
51
|
+
gen size = ln(at) // Firm size (log assets)
|
|
52
|
+
gen mb = (prcc_f * csho) / ceq // Market-to-book
|
|
53
|
+
gen sales_growth = (sale - l.sale) / l.sale // Revenue growth
|
|
54
|
+
gen cfo = oancf / l.at // Cash flow from operations
|
|
55
|
+
gen loss = (ib < 0) // Loss indicator
|
|
56
|
+
|
|
57
|
+
* Industry classification (Fama-French 48)
|
|
58
|
+
merge m:1 sic using "reference/ff48_sic.dta", nogen keep(master match)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Sample Selection and Filters
|
|
62
|
+
|
|
63
|
+
```stata
|
|
64
|
+
* Standard sample restrictions
|
|
65
|
+
drop if at <= 0 // Positive assets
|
|
66
|
+
drop if sale < 0 // Non-negative sales
|
|
67
|
+
drop if missing(ib, at, sale) // Key variables non-missing
|
|
68
|
+
drop if inlist(sic, 6000, 6999) // Exclude financials (SIC 6000-6999)
|
|
69
|
+
drop if inlist(sic, 4900, 4999) // Exclude utilities (SIC 4900-4999)
|
|
70
|
+
|
|
71
|
+
* Require minimum observations per industry-year
|
|
72
|
+
bysort ff48 fyear: gen n_iy = _N
|
|
73
|
+
drop if n_iy < 20
|
|
74
|
+
|
|
75
|
+
* Winsorize continuous variables at 1st/99th percentile
|
|
76
|
+
foreach var of varlist roa leverage mb sales_growth cfo total_accruals_cf {
|
|
77
|
+
winsor2 `var', cuts(1 99) replace
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Accrual Models
|
|
82
|
+
|
|
83
|
+
### Modified Jones Model (Dechow, Sloan, Sweeney 1995)
|
|
84
|
+
|
|
85
|
+
```stata
|
|
86
|
+
* ============================================
|
|
87
|
+
* Modified Jones Model - Industry-Year Estimation
|
|
88
|
+
* ============================================
|
|
89
|
+
|
|
90
|
+
* Construct regressors
|
|
91
|
+
gen inv_at = 1 / l.at
|
|
92
|
+
gen d_rev_rec = ((sale - l.sale) - (rect - l.rect)) / l.at
|
|
93
|
+
gen ppe_scaled = ppegt / l.at
|
|
94
|
+
|
|
95
|
+
* Estimate by industry-year cross-sections
|
|
96
|
+
gen da_mj = .
|
|
97
|
+
levelsof ff48, local(industries)
|
|
98
|
+
levelsof fyear, local(years)
|
|
99
|
+
|
|
100
|
+
foreach ind of local industries {
|
|
101
|
+
foreach yr of local years {
|
|
102
|
+
capture {
|
|
103
|
+
reg total_accruals_cf inv_at d_rev_rec ppe_scaled ///
|
|
104
|
+
if ff48 == `ind' & fyear == `yr', robust
|
|
105
|
+
predict resid if e(sample), resid
|
|
106
|
+
replace da_mj = resid if ff48 == `ind' & fyear == `yr' & !missing(resid)
|
|
107
|
+
drop resid
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
label variable da_mj "Discretionary accruals (Modified Jones)"
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Performance-Matched Model (Kothari et al. 2005)
|
|
116
|
+
|
|
117
|
+
```stata
|
|
118
|
+
* Add ROA as control for performance matching
|
|
119
|
+
gen da_kothari = .
|
|
120
|
+
|
|
121
|
+
foreach ind of local industries {
|
|
122
|
+
foreach yr of local years {
|
|
123
|
+
capture {
|
|
124
|
+
reg total_accruals_cf inv_at d_rev_rec ppe_scaled roa ///
|
|
125
|
+
if ff48 == `ind' & fyear == `yr', robust
|
|
126
|
+
predict resid if e(sample), resid
|
|
127
|
+
replace da_kothari = resid if ff48 == `ind' & fyear == `yr' & !missing(resid)
|
|
128
|
+
drop resid
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
label variable da_kothari "Discretionary accruals (Kothari)"
|
|
134
|
+
|
|
135
|
+
* Alternative: performance matching by ROA decile
|
|
136
|
+
xtile roa_decile = roa, nq(10)
|
|
137
|
+
bysort ff48 fyear roa_decile: egen da_pm = mean(da_mj)
|
|
138
|
+
gen da_performance_matched = da_mj - da_pm
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Earnings Management Detection
|
|
142
|
+
|
|
143
|
+
### Earnings Management Around Thresholds
|
|
144
|
+
|
|
145
|
+
```stata
|
|
146
|
+
* ============================================
|
|
147
|
+
* Earnings Distribution Discontinuity Test
|
|
148
|
+
* ============================================
|
|
149
|
+
|
|
150
|
+
* Scaled earnings (earnings per share / price)
|
|
151
|
+
gen earn_scaled = ib / (prcc_f * csho)
|
|
152
|
+
|
|
153
|
+
* Histogram around zero
|
|
154
|
+
twoway (histogram earn_scaled if inrange(earn_scaled, -0.10, 0.10), ///
|
|
155
|
+
width(0.005) color(navy%50)), ///
|
|
156
|
+
xline(0, lcolor(red)) ///
|
|
157
|
+
title("Distribution of Scaled Earnings Around Zero") ///
|
|
158
|
+
xtitle("Earnings / Market Cap") ytitle("Frequency") ///
|
|
159
|
+
graphregion(color(white))
|
|
160
|
+
graph export "figures/earnings_discontinuity.pdf", replace
|
|
161
|
+
|
|
162
|
+
* Burgstahler & Dichev (1997) test
|
|
163
|
+
gen earn_bin = round(earn_scaled, 0.005)
|
|
164
|
+
tab earn_bin if inrange(earn_scaled, -0.025, 0.025)
|
|
165
|
+
|
|
166
|
+
* Test for discontinuity at zero
|
|
167
|
+
gen just_above = (earn_scaled >= 0 & earn_scaled < 0.005)
|
|
168
|
+
gen just_below = (earn_scaled >= -0.005 & earn_scaled < 0)
|
|
169
|
+
prtest just_above == just_below
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Real Earnings Management (Roychowdhury 2006)
|
|
173
|
+
|
|
174
|
+
```stata
|
|
175
|
+
* Abnormal cash flow from operations
|
|
176
|
+
gen da_cfo = .
|
|
177
|
+
foreach ind of local industries {
|
|
178
|
+
foreach yr of local years {
|
|
179
|
+
capture {
|
|
180
|
+
reg cfo inv_at sale_scaled d_sale_scaled ///
|
|
181
|
+
if ff48 == `ind' & fyear == `yr', robust
|
|
182
|
+
predict resid if e(sample), resid
|
|
183
|
+
replace da_cfo = resid if ff48 == `ind' & fyear == `yr' & !missing(resid)
|
|
184
|
+
drop resid
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
* Abnormal production costs
|
|
190
|
+
gen prod_costs = cogs + (xinv - l.xinv)
|
|
191
|
+
gen prod_scaled = prod_costs / l.at
|
|
192
|
+
|
|
193
|
+
gen da_prod = .
|
|
194
|
+
foreach ind of local industries {
|
|
195
|
+
foreach yr of local years {
|
|
196
|
+
capture {
|
|
197
|
+
reg prod_scaled inv_at sale_scaled d_sale_scaled l.d_sale_scaled ///
|
|
198
|
+
if ff48 == `ind' & fyear == `yr', robust
|
|
199
|
+
predict resid if e(sample), resid
|
|
200
|
+
replace da_prod = resid if ff48 == `ind' & fyear == `yr' & !missing(resid)
|
|
201
|
+
drop resid
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Publication Tables
|
|
208
|
+
|
|
209
|
+
### Regression Table with Standard Formatting
|
|
210
|
+
|
|
211
|
+
```stata
|
|
212
|
+
* Main regression: Discretionary accruals on governance
|
|
213
|
+
reg abs_da_mj board_independence ceo_duality audit_committee_size ///
|
|
214
|
+
big4 size leverage mb loss i.fyear, cluster(gvkey)
|
|
215
|
+
estimates store gov1
|
|
216
|
+
|
|
217
|
+
reg abs_da_mj board_independence ceo_duality audit_committee_size ///
|
|
218
|
+
big4 inst_ownership analyst_following ///
|
|
219
|
+
size leverage mb loss i.fyear, cluster(gvkey)
|
|
220
|
+
estimates store gov2
|
|
221
|
+
|
|
222
|
+
* Publication table
|
|
223
|
+
esttab gov1 gov2 using "tables/governance_regression.tex", ///
|
|
224
|
+
b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) ///
|
|
225
|
+
label title("Corporate Governance and Earnings Quality") ///
|
|
226
|
+
mtitles("Baseline" "Extended") ///
|
|
227
|
+
drop(*.fyear) indicate("Year FE = *.fyear") ///
|
|
228
|
+
stats(N r2_a, labels("Observations" "Adj. R-squared") fmt(0 3)) ///
|
|
229
|
+
addnotes("Standard errors clustered by firm in parentheses.") ///
|
|
230
|
+
replace
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Endogeneity and Identification
|
|
234
|
+
|
|
235
|
+
### Two-Stage Least Squares
|
|
236
|
+
|
|
237
|
+
```stata
|
|
238
|
+
* Instrumental variable regression
|
|
239
|
+
ivregress 2sls earnings_quality (board_independence = ///
|
|
240
|
+
state_governance_index peer_board_independence) ///
|
|
241
|
+
size leverage mb loss i.fyear, cluster(gvkey) first
|
|
242
|
+
|
|
243
|
+
* First-stage diagnostics
|
|
244
|
+
estat firststage
|
|
245
|
+
estat endogenous
|
|
246
|
+
|
|
247
|
+
* Weak instrument test
|
|
248
|
+
estat firststage, forcenonrobust
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Propensity Score Matching
|
|
252
|
+
|
|
253
|
+
```stata
|
|
254
|
+
* PSM for treatment effect of Big 4 auditor
|
|
255
|
+
logit big4 size leverage mb roa loss i.ff48, robust
|
|
256
|
+
predict pscore, pr
|
|
257
|
+
|
|
258
|
+
* Nearest-neighbor matching
|
|
259
|
+
psmatch2 big4, pscore(pscore) outcome(abs_da_mj) ///
|
|
260
|
+
neighbor(3) caliper(0.01) common
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## References
|
|
264
|
+
|
|
265
|
+
- Dechow, Sloan & Sweeney (1995), "Detecting Earnings Management," TAR 70(2)
|
|
266
|
+
- Kothari, Leone & Wasley (2005), "Performance Matched Discretionary Accrual Measures," JAE 39(1)
|
|
267
|
+
- Roychowdhury (2006), "Earnings Management through Real Activities Manipulation," JAE 42(3)
|
|
268
|
+
- Burgstahler & Dichev (1997), "Earnings Management to Avoid Earnings Decreases and Losses," JAE 24(1)
|
|
269
|
+
- Compustat Manual: https://www.spglobal.com/marketintelligence
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: stata-analyst-guide
|
|
3
|
+
description: "Stata workflows for publication-ready sociology and social science research"
|
|
4
|
+
metadata:
|
|
5
|
+
openclaw:
|
|
6
|
+
emoji: "survey"
|
|
7
|
+
category: "analysis"
|
|
8
|
+
subcategory: "econometrics"
|
|
9
|
+
keywords: ["Stata", "sociology", "social science", "survey data", "regression", "publication tables"]
|
|
10
|
+
source: "https://www.stata.com"
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Stata Analyst Guide for Social Science Research
|
|
14
|
+
|
|
15
|
+
Complete Stata workflow for sociology and social science research, from survey data preparation through publication-ready regression tables and visualizations. This skill covers the analytical techniques most commonly used in top sociology journals.
|
|
16
|
+
|
|
17
|
+
## Overview
|
|
18
|
+
|
|
19
|
+
Stata is the dominant statistical software in sociology, political science, demography, and many social science disciplines. Its command-line interface, reproducible do-file workflow, and comprehensive support for survey data, multilevel models, and categorical data analysis make it the tool of choice for researchers working with complex social datasets.
|
|
20
|
+
|
|
21
|
+
This skill provides ready-to-use Stata code for the most common analytical tasks in social science research: descriptive statistics for diverse variable types, regression modeling with proper controls and robustness checks, interaction effects with meaningful visualizations, and automated production of APA/ASA-formatted tables suitable for direct inclusion in journal manuscripts.
|
|
22
|
+
|
|
23
|
+
The examples draw on typical social science data structures: individual-level survey data with sampling weights, nested data (individuals within organizations or regions), longitudinal panels, and event-history data. All code follows the conventions expected by reviewers at journals such as the American Sociological Review, American Journal of Sociology, and Social Forces.
|
|
24
|
+
|
|
25
|
+
## Descriptive Statistics
|
|
26
|
+
|
|
27
|
+
### Weighted Summary Statistics
|
|
28
|
+
|
|
29
|
+
```stata
|
|
30
|
+
* Social science surveys typically require survey weights
|
|
31
|
+
svyset psu [pweight=finalweight], strata(stratum)
|
|
32
|
+
|
|
33
|
+
* Weighted means and proportions
|
|
34
|
+
svy: mean income education_years age
|
|
35
|
+
svy: proportion race gender marital_status
|
|
36
|
+
|
|
37
|
+
* Weighted cross-tabulation
|
|
38
|
+
svy: tabulate education_cat income_quintile, row se
|
|
39
|
+
|
|
40
|
+
* Descriptive statistics table for paper
|
|
41
|
+
estpost summarize age education_years income ///
|
|
42
|
+
children household_size, detail
|
|
43
|
+
esttab using "tables/descriptives.tex", ///
|
|
44
|
+
cells("mean(fmt(2)) sd(fmt(2)) min max count") ///
|
|
45
|
+
label title("Descriptive Statistics") replace
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Group Comparisons
|
|
49
|
+
|
|
50
|
+
```stata
|
|
51
|
+
* T-tests with survey weights
|
|
52
|
+
svy: mean income, over(gender)
|
|
53
|
+
lincom [income]Male - [income]Female
|
|
54
|
+
|
|
55
|
+
* ANOVA
|
|
56
|
+
svy: regress income i.race i.education_cat
|
|
57
|
+
testparm i.race
|
|
58
|
+
testparm i.education_cat
|
|
59
|
+
|
|
60
|
+
* Effect sizes (Cohen's d)
|
|
61
|
+
esize twosample income, by(gender)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Regression Analysis
|
|
65
|
+
|
|
66
|
+
### OLS with Standard Controls
|
|
67
|
+
|
|
68
|
+
```stata
|
|
69
|
+
* Model building strategy (nested models for sociology papers)
|
|
70
|
+
|
|
71
|
+
* Model 1: Bivariate
|
|
72
|
+
reg income i.gender [pweight=finalweight], robust
|
|
73
|
+
estimates store m1
|
|
74
|
+
|
|
75
|
+
* Model 2: Add demographics
|
|
76
|
+
reg income i.gender age age_sq i.race i.marital [pweight=finalweight], robust
|
|
77
|
+
estimates store m2
|
|
78
|
+
|
|
79
|
+
* Model 3: Add human capital
|
|
80
|
+
reg income i.gender age age_sq i.race i.marital ///
|
|
81
|
+
education_years experience experience_sq [pweight=finalweight], robust
|
|
82
|
+
estimates store m3
|
|
83
|
+
|
|
84
|
+
* Model 4: Add job characteristics
|
|
85
|
+
reg income i.gender age age_sq i.race i.marital ///
|
|
86
|
+
education_years experience experience_sq ///
|
|
87
|
+
i.occupation i.industry hours_worked [pweight=finalweight], robust
|
|
88
|
+
estimates store m4
|
|
89
|
+
|
|
90
|
+
* Publication-ready table
|
|
91
|
+
esttab m1 m2 m3 m4 using "tables/regression_income.tex", ///
|
|
92
|
+
b(3) se(3) star(* 0.05 ** 0.01 *** 0.001) ///
|
|
93
|
+
label title("OLS Regression of Income") ///
|
|
94
|
+
mtitles("Bivariate" "Demographics" "Human Capital" "Full Model") ///
|
|
95
|
+
stats(N r2_a, labels("Observations" "Adjusted R-squared") fmt(0 3)) ///
|
|
96
|
+
addnotes("Standard errors in parentheses." ///
|
|
97
|
+
"All models use survey weights.") ///
|
|
98
|
+
replace
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Logistic Regression
|
|
102
|
+
|
|
103
|
+
```stata
|
|
104
|
+
* Binary outcome: employment status
|
|
105
|
+
logit employed i.gender age age_sq i.race i.education_cat ///
|
|
106
|
+
children i.marital [pweight=finalweight], robust
|
|
107
|
+
estimates store logit1
|
|
108
|
+
|
|
109
|
+
* Report odds ratios
|
|
110
|
+
logit employed i.gender age age_sq i.race i.education_cat ///
|
|
111
|
+
children i.marital [pweight=finalweight], robust or
|
|
112
|
+
estimates store logit_or
|
|
113
|
+
|
|
114
|
+
* Average marginal effects (preferred in sociology)
|
|
115
|
+
margins, dydx(*) post
|
|
116
|
+
estimates store ame
|
|
117
|
+
|
|
118
|
+
* Predicted probabilities by group
|
|
119
|
+
logit employed i.gender##i.race age education_years [pweight=finalweight], robust
|
|
120
|
+
margins gender#race, atmeans
|
|
121
|
+
marginsplot, title("Predicted Probability of Employment")
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Interaction Effects
|
|
125
|
+
|
|
126
|
+
### Continuous x Categorical Interaction
|
|
127
|
+
|
|
128
|
+
```stata
|
|
129
|
+
* Gender x education interaction on income
|
|
130
|
+
reg income c.education_years##i.gender age i.race [pweight=finalweight], robust
|
|
131
|
+
|
|
132
|
+
* Visualize interaction
|
|
133
|
+
margins gender, at(education_years=(8(2)20))
|
|
134
|
+
marginsplot, ///
|
|
135
|
+
title("Returns to Education by Gender") ///
|
|
136
|
+
ytitle("Predicted Income ($)") ///
|
|
137
|
+
xtitle("Years of Education") ///
|
|
138
|
+
legend(order(1 "Male" 2 "Female")) ///
|
|
139
|
+
scheme(s2mono)
|
|
140
|
+
graph export "figures/education_gender_interaction.pdf", replace
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Moderation Analysis
|
|
144
|
+
|
|
145
|
+
```stata
|
|
146
|
+
* Test whether the effect of X on Y varies by moderator Z
|
|
147
|
+
reg outcome c.x_var##c.moderator controls [pweight=finalweight], robust
|
|
148
|
+
|
|
149
|
+
* Simple slopes at meaningful values of moderator
|
|
150
|
+
margins, dydx(x_var) at(moderator=(10 25 50 75 90)) // Percentiles
|
|
151
|
+
marginsplot, recast(line) recastci(rarea) ///
|
|
152
|
+
title("Effect of X on Y at Different Levels of Moderator")
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Multilevel Models
|
|
156
|
+
|
|
157
|
+
```stata
|
|
158
|
+
* Students nested within schools
|
|
159
|
+
mixed test_score gender ses || school_id:, ///
|
|
160
|
+
variance mle
|
|
161
|
+
|
|
162
|
+
* Random slopes
|
|
163
|
+
mixed test_score gender c.ses || school_id: ses, ///
|
|
164
|
+
covariance(unstructured) mle
|
|
165
|
+
|
|
166
|
+
* Calculate ICC
|
|
167
|
+
estat icc
|
|
168
|
+
|
|
169
|
+
* Store and compare models
|
|
170
|
+
estimates store mlm1
|
|
171
|
+
mixed test_score gender c.ses school_quality || school_id: ses, ///
|
|
172
|
+
covariance(unstructured) mle
|
|
173
|
+
estimates store mlm2
|
|
174
|
+
|
|
175
|
+
lrtest mlm1 mlm2
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Visualization for Publication
|
|
179
|
+
|
|
180
|
+
### Journal-Quality Figures
|
|
181
|
+
|
|
182
|
+
```stata
|
|
183
|
+
* Set publication-ready scheme
|
|
184
|
+
set scheme s2mono
|
|
185
|
+
|
|
186
|
+
* Coefficient plot
|
|
187
|
+
coefplot m2 m3 m4, ///
|
|
188
|
+
drop(_cons) xline(0) ///
|
|
189
|
+
title("Regression Coefficients Across Models") ///
|
|
190
|
+
legend(order(2 "Demographics" 4 "Human Capital" 6 "Full")) ///
|
|
191
|
+
graphregion(color(white))
|
|
192
|
+
graph export "figures/coefplot.pdf", replace
|
|
193
|
+
|
|
194
|
+
* Distribution comparison
|
|
195
|
+
twoway (kdensity income if gender==1, lcolor(navy)) ///
|
|
196
|
+
(kdensity income if gender==2, lcolor(cranberry)), ///
|
|
197
|
+
title("Income Distribution by Gender") ///
|
|
198
|
+
legend(order(1 "Male" 2 "Female")) ///
|
|
199
|
+
xtitle("Annual Income ($)") ytitle("Density") ///
|
|
200
|
+
graphregion(color(white))
|
|
201
|
+
graph export "figures/income_density.pdf", replace
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Replication Package
|
|
205
|
+
|
|
206
|
+
```stata
|
|
207
|
+
* Master do-file structure for replication
|
|
208
|
+
* master.do
|
|
209
|
+
* ==========================================
|
|
210
|
+
* Project: [Title]
|
|
211
|
+
* Author: [Name]
|
|
212
|
+
* Date: [Date]
|
|
213
|
+
* Description: Master script for replication
|
|
214
|
+
* ==========================================
|
|
215
|
+
|
|
216
|
+
version 17
|
|
217
|
+
clear all
|
|
218
|
+
set more off
|
|
219
|
+
set maxvar 10000
|
|
220
|
+
|
|
221
|
+
global root "~/research/project_name"
|
|
222
|
+
global raw "$root/data/raw"
|
|
223
|
+
global processed "$root/data/processed"
|
|
224
|
+
global tables "$root/tables"
|
|
225
|
+
global figures "$root/figures"
|
|
226
|
+
global logs "$root/logs"
|
|
227
|
+
|
|
228
|
+
log using "$logs/master_log.smcl", replace
|
|
229
|
+
|
|
230
|
+
do "$root/code/01_data_cleaning.do"
|
|
231
|
+
do "$root/code/02_descriptives.do"
|
|
232
|
+
do "$root/code/03_main_analysis.do"
|
|
233
|
+
do "$root/code/04_robustness.do"
|
|
234
|
+
do "$root/code/05_tables_figures.do"
|
|
235
|
+
|
|
236
|
+
log close
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## References
|
|
240
|
+
|
|
241
|
+
- Stata Survey Data Reference Manual: https://www.stata.com/manuals/svy.pdf
|
|
242
|
+
- Mitchell, M. (2021), A Visual Guide to Stata Graphics, 4th ed., Stata Press
|
|
243
|
+
- Long & Freese (2014), Regression Models for Categorical Dependent Variables Using Stata, 3rd ed.
|
|
244
|
+
- esttab/estout documentation: http://repec.sowi.unibe.ch/stata/estout/
|
|
245
|
+
- ASA Style Guide: https://www.asanet.org/publications/style-guide/
|