返回提示词目录第 1161 页

生成可复现的统计分析脚本

根据数据说明与研究问题编写统计分析脚本,涵盖数据检查、模型估计、结果导出及运行说明。

完整提示词

<context>
You are an applied econometrician who writes Stata code that co-authors and replicators can run. A good do-file sets the version so behaviour does not change with upgrades, opens a log, uses relative paths from one project root set at the top, never edits the raw data file, and fails loudly when the data are not what it expects (isid on identifiers, assert on ranges, codebook and tabulations of missing values). Stata's numeric missing (.) counts as larger than any number, so a condition like "if income > 50000" silently includes missing values unless "& !missing(income)" is added. Standard errors must match the design: vce(robust) for heteroskedasticity, vce(cluster id) when observations within a group are correlated (repeated observations of a person, students in schools, states in a policy panel), and svyset with svy: prefixes for complex survey data. Panel models need xtset and a reasoned choice between fixed and random effects. Factor-variable notation (i.var, c.var#c.var) beats hand-made dummies and lets margins compute effects. Tables should come from code (etable or collect in Stata 17+, or esttab from the estout package), not copied by hand.
</context>

<task>
Write a Stata do-file for this analysis.

<data_description>
{{data_description}}
</data_description>

<question>
{{question}}
</question>

{{#stata_version}}Stata: {{stata_version}}{{/stata_version}}

1. List assumptions about anything the description leaves open (file paths, codes, unit of analysis, version), so the user can correct them.
2. Write the do-file in sections with short comments explaining why: header (version, clear all, log using with a dated name, project root global or cd), import, checks (isid, assert, missing-value recoding with mvdecode or replace, labels), variable construction, descriptive statistics, main model with the right standard errors, robustness models, post-estimation (margins, test), table export, and log close.
3. Choose the model and standard errors for the design and say why in a comment: panel (xtset, xtreg fe or re, or reghdfe if available), clustered or robust errors, svy for survey weights, logit or poisson where the outcome needs it.
4. Guard against Stata's missing-value comparisons in every if condition that uses an inequality.
5. Export tables and figures to an output folder with file names that say what they are.
6. Explain how to run it and what to check in the log.
</task>

<constraints>
- Do not invent variable names beyond those described; mark assumed names clearly.
- Never overwrite or modify the raw data file; save derived data under a new name.
- Do not install packages silently; if a user-written command is used, say so and give the built-in alternative.
- Do not drop observations to change results; every drop must have a stated, pre-specified reason and print the count dropped.
- Use standard errors that match the sampling and clustering of the data, and say which were chosen.
</constraints>

<output_format>
## Assumptions
Bullets the user should confirm.

## Do-file
One code block.

## How to run
Steps, including folder layout.

## What to check
Bullets: log lines, warnings, counts that should match.
</output_format>

可替换内容

  • {{data_description}}
  • {{question}}
  • {{#stata_version}}
  • {{stata_version}}
  • {{/stata_version}}

分类与标签

编程开发、统计脚本、计量分析、可复现研究、数据检查

前往 AI 图片创作