Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Stata workflows for publication-ready sociology and social science research
.claude/skills/brycewang-stanford-stata-analyst-guide/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 42% | 0% |
| case-19 | ✗→✓ | ▲ Improved | 61% | 0% |
| case-23 | ✗→✓ | ▲ Improved | 130% | 0% |
| case-01 | ✓→✗ | ▼ Worse | 56% | 0% |
| case-07 | ✓→✓ | = Same ✓ | 103% | 0% |
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.
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.
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.
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.
stata* Social science surveys typically require survey weights svyset psu [pweight=finalweight], strata(stratum) * Weighted means and proportions svy: mean income education_years age svy: proportion race gender marital_status * Weighted cross-tabulation svy: tabulate education_cat income_quintile, row se * Descriptive statistics table for paper estpost summarize age education_years income /// children household_size, detail esttab using "tables/descriptives.tex", /// cells("mean(fmt(2)) sd(fmt(2)) min max count") /// label title("Descriptive Statistics") replace
stata* T-tests with survey weights svy: mean income, over(gender) lincom [income]Male - [income]Female * ANOVA svy: regress income i.race i.education_cat testparm i.race testparm i.education_cat * Effect sizes (Cohen's d) esize twosample income, by(gender)
stata* Model building strategy (nested models for sociology papers) * Model 1: Bivariate reg income i.gender [pweight=finalweight], robust estimates store m1 * Model 2: Add demographics reg income i.gender age age_sq i.race i.marital [pweight=finalweight], robust estimates store m2 * Model 3: Add human capital reg income i.gender age age_sq i.race i.marital /// education_years experience experience_sq [pweight=finalweight], robust estimates store m3 * Model 4: Add job characteristics reg income i.gender age age_sq i.race i.marital /// education_years experience experience_sq /// i.occupation i.industry hours_worked [pweight=finalweight], robust estimates store m4 * Publication-ready table esttab m1 m2 m3 m4 using "tables/regression_income.tex", /// b(3) se(3) star(* 0.05 ** 0.01 *** 0.001) /// label title("OLS Regression of Income") /// mtitles("Bivariate" "Demographics" "Human Capital" "Full Model") /// stats(N r2_a, labels("Observations" "Adjusted R-squared") fmt(0 3)) /// addnotes("Standard errors in parentheses." /// "All models use survey weights.") /// replace
stata* Binary outcome: employment status logit employed i.gender age age_sq i.race i.education_cat /// children i.marital [pweight=finalweight], robust estimates store logit1 * Report odds ratios logit employed i.gender age age_sq i.race i.education_cat /// children i.marital [pweight=finalweight], robust or estimates store logit_or * Average marginal effects (preferred in sociology) margins, dydx(*) post estimates store ame * Predicted probabilities by group logit employed i.gender##i.race age education_years [pweight=finalweight], robust margins gender#race, atmeans marginsplot, title("Predicted Probability of Employment")
stata* Gender x education interaction on income reg income c.education_years##i.gender age i.race [pweight=finalweight], robust * Visualize interaction margins gender, at(education_years=(8(2)20)) marginsplot, /// title("Returns to Education by Gender") /// ytitle("Predicted Income ($)") /// xtitle("Years of Education") /// legend(order(1 "Male" 2 "Female")) /// scheme(s2mono) graph export "figures/education_gender_interaction.pdf", replace
stata* Test whether the effect of X on Y varies by moderator Z reg outcome c.x_var##c.moderator controls [pweight=finalweight], robust * Simple slopes at meaningful values of moderator margins, dydx(x_var) at(moderator=(10 25 50 75 90)) // Percentiles marginsplot, recast(line) recastci(rarea) /// title("Effect of X on Y at Different Levels of Moderator")
stata* Students nested within schools mixed test_score gender ses || school_id:, /// variance mle * Random slopes mixed test_score gender c.ses || school_id: ses, /// covariance(unstructured) mle * Calculate ICC estat icc * Store and compare models estimates store mlm1 mixed test_score gender c.ses school_quality || school_id: ses, /// covariance(unstructured) mle estimates store mlm2 lrtest mlm1 mlm2
stata* Set publication-ready scheme set scheme s2mono * Coefficient plot coefplot m2 m3 m4, /// drop(_cons) xline(0) /// title("Regression Coefficients Across Models") /// legend(order(2 "Demographics" 4 "Human Capital" 6 "Full")) /// graphregion(color(white)) graph export "figures/coefplot.pdf", replace * Distribution comparison twoway (kdensity income if gender==1, lcolor(navy)) /// (kdensity income if gender==2, lcolor(cranberry)), /// title("Income Distribution by Gender") /// legend(order(1 "Male" 2 "Female")) /// xtitle("Annual Income ($)") ytitle("Density") /// graphregion(color(white)) graph export "figures/income_density.pdf", replace
stata* Master do-file structure for replication * master.do * ========================================== * Project: [Title] * Author: [Name] * Date: [Date] * Description: Master script for replication * ========================================== version 17 clear all set more off set maxvar 10000 global root "~/research/project_name" global raw "$root/data/raw" global processed "$root/data/processed" global tables "$root/tables" global figures "$root/figures" global logs "$root/logs" log using "$logs/master_log.smcl", replace do "$root/code/01_data_cleaning.do" do "$root/code/02_descriptives.do" do "$root/code/03_main_analysis.do" do "$root/code/04_robustness.do" do "$root/code/05_tables_figures.do" log close
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→fail | 22,862 | 26,273 | +15% | 1 | 1 | 0% | 3,919 | 6,112 | +56% | 0 | 0 | — |
case-02 | fail→pass | 19,721 | 17,004 | -14% | 1 | 1 | 0% | 3,600 | 5,105 | +42% | 0 | 0 | — |
case-03 | fail→fail | 13,159 | 13,709 | +4% | 1 | 1 | 0% | 2,424 | 4,592 | +89% | 0 | 0 | — |
case-04 | fail→fail | 20,331 | 22,683 | +12% | 1 | 1 | 0% | 3,499 | 5,923 | +69% | 0 | 0 | — |
case-05 | fail→fail | 19,562 | 17,189 | -12% | 1 | 1 | 0% | 3,548 | 5,102 | +44% | 0 | 0 | — |
case-06 | fail→fail | 14,882 | 15,323 | +3% | 1 | 1 | 0% | 2,538 | 4,486 | +77% | 0 | 0 | — |
case-07 | pass→pass | 8,499 | 5,984 | -30% | 1 | 1 | 0% | 1,487 | 3,015 | +103% | 0 | 0 | — |
case-08 | pass→pass | 10,883 | 12,225 | +12% | 1 | 1 | 0% | 1,855 | 4,095 | +121% | 0 | 0 | — |
case-09 | pass→pass | 11,363 | 14,637 | +29% | 1 | 1 | 0% | 2,007 | 4,641 | +131% | 0 | 0 | — |
case-10 | pass→pass | 11,745 | 8,694 | -26% | 1 | 1 | 0% | 1,989 | 3,490 | +75% | 0 | 0 | — |
case-11 | fail→fail | 10,146 | 10,618 | +5% | 1 | 1 | 0% | 1,802 | 3,857 | +114% | 0 | 0 | — |
case-12 | pass→pass | 12,736 | 15,172 | +19% | 1 | 1 | 0% | 2,284 | 4,876 | +113% | 0 | 0 | — |
case-13 | pass→pass | 8,983 | 7,585 | -16% | 1 | 1 | 0% | 1,560 | 3,272 | +110% | 0 | 0 | — |
case-14 | pass→pass | 10,796 | 18,627 | +73% | 1 | 1 | 0% | 1,951 | 3,939 | +102% | 0 | 0 | — |
case-15 | pass→pass | 12,644 | 9,115 | -28% | 1 | 1 | 0% | 2,225 | 3,566 | +60% | 0 | 0 | — |
case-16 | pass→pass | 11,740 | 7,081 | -40% | 1 | 1 | 0% | 2,142 | 3,206 | +50% | 0 | 0 | — |
case-17 | pass→pass | 10,939 | 12,485 | +14% | 1 | 1 | 0% | 1,854 | 4,040 | +118% | 0 | 0 | — |
case-18 | pass→pass | 8,928 | 7,217 | -19% | 1 | 1 | 0% | 1,262 | 3,133 | +148% | 0 | 0 | — |
case-19 | fail→pass | 11,783 | 6,633 | -44% | 1 | 1 | 0% | 1,924 | 3,093 | +61% | 0 | 0 | — |
case-20 | pass→pass | 7,534 | 9,059 | +20% | 1 | 1 | 0% | 1,315 | 3,584 | +173% | 0 | 0 | — |
case-21 | pass→pass | 9,671 | 10,537 | +9% | 1 | 1 | 0% | 1,705 | 3,883 | +128% | 0 | 0 | — |
case-22 | pass→pass | 7,773 | 5,723 | -26% | 1 | 1 | 0% | 1,381 | 2,930 | +112% | 0 | 0 | — |
case-23 | fail→pass | 9,210 | 9,745 | +6% | 1 | 1 | 0% | 1,570 | 3,604 | +130% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +9 percentage points is the difference between those two pass rates over the 23 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.