stata-regression
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStata Regression
Stata回归分析
Purpose
用途
This skill produces reproducible regression analysis workflows in Stata, including model diagnostics and publication-ready tables using or .
esttaboutreg2本Skill可在Stata中生成可复现的回归分析工作流,包括模型诊断,以及使用或生成可直接用于发表的表格。
esttaboutreg2When to Use
使用场景
- Estimating linear or nonlinear regression models in Stata
- Producing tables for academic papers and reports
- Running robustness checks and alternative specifications
- 在Stata中估计线性或非线性回归模型
- 为学术论文和报告生成表格
- 进行稳健性检验和替代模型设定
Instructions
操作步骤
Follow these steps to complete the task:
请按照以下步骤完成任务:
Step 1: Understand the Context
步骤1:理解背景信息
Before generating any code, ask the user:
- What is the dependent variable and key regressors?
- What controls and fixed effects are required?
- How should standard errors be clustered?
- What output format is needed (LaTeX, Word, or CSV)?
在生成代码前,询问用户:
- 因变量和核心自变量是什么?
- 需要哪些控制变量和固定效应?
- 标准误应如何聚类?
- 需要什么格式的输出(LaTeX、Word或CSV)?
Step 2: Generate the Output
步骤2:生成输出内容
Based on the context, generate Stata code that:
- Loads and checks the data - Handle missing values and verify variable types
- Runs the requested specification - Use ,
regress, orreghdfeas appropriatextreg - Adds robust or clustered standard errors - Match the study design
- Exports tables - Use or
esttabwith clear labelsoutreg2
根据背景信息,生成Stata代码,包含以下内容:
- 加载并检查数据 - 处理缺失值并验证变量类型
- 运行指定的模型设定 - 根据情况使用、
regress或reghdfextreg - 添加稳健标准误或聚类标准误 - 与研究设计匹配
- 导出表格 - 使用或
esttab并添加清晰标签outreg2
Step 3: Verify and Explain
步骤3:验证与解释
After generating output:
- Explain what each model estimates
- Highlight assumptions and diagnostics
- Suggest robustness checks or alternative models
生成输出后:
- 解释每个模型的估计内容
- 强调假设和诊断结果
- 建议稳健性检验或替代模型
Example Prompts
示例提示词
- "Run OLS with firm and year fixed effects, clustering by firm"
- "Estimate a logit model and export results to LaTeX"
- "Create a regression table with three specifications"
- "运行包含企业和年份固定效应的OLS回归,按企业聚类标准误"
- "估计logit模型并将结果导出为LaTeX格式"
- "创建包含三种模型设定的回归表格"
Example Output
示例输出
stata
* ============================================
* Regression Analysis with Stata
* ============================================
* Load data
use "data.dta", clear
* Summary stats
summarize y x1 x2 x3
* Main regression with clustered SEs
regress y x1 x2 x3, vce(cluster firm_id)
eststo model1
* Alternative specification with fixed effects
reghdfe y x1 x2 x3, absorb(firm_id year) vce(cluster firm_id)
eststo model2
* Export table
esttab model1 model2 using "results/regression_table.tex", replace se labelstata
* ============================================
* Regression Analysis with Stata
* ============================================
* Load data
use "data.dta", clear
* Summary stats
summarize y x1 x2 x3
* Main regression with clustered SEs
regress y x1 x2 x3, vce(cluster firm_id)
eststo model1
* Alternative specification with fixed effects
reghdfe y x1 x2 x3, absorb(firm_id year) vce(cluster firm_id)
eststo model2
* Export table
esttab model1 model2 using "results/regression_table.tex", replace se labelRequirements
要求
Software
软件
- Stata 17+
- Stata 17+
Packages
扩展包
- (for
estout)esttab - (optional, for high-dimensional fixed effects)
reghdfe
Install with:
stata
ssc install estout
ssc install reghdfe- (用于
estout)esttab - (可选,用于高维固定效应)
reghdfe
安装命令:
stata
ssc install estout
ssc install reghdfeBest Practices
最佳实践
- Match standard errors to the design (cluster where treatment varies)
- Report all model variants used in the analysis
- Document variable definitions and transformations
- 根据研究设计匹配标准误(在处理变量变化的维度进行聚类)
- 报告分析中使用的所有模型变体
- 记录变量定义和转换过程
Common Pitfalls
常见误区
- Not clustering standard errors at the correct level
- Omitting fixed effects when required by the design
- Exporting tables without clear labels and notes
- 未在正确维度聚类标准误
- 研究设计要求固定效应时却未加入
- 导出表格时未添加清晰的标签和注释
References
参考资料
Changelog
更新日志
v1.0.0
v1.0.0
- Initial release
- 初始版本