我想把我之前的结果都变成word形式生成,以及我做了太多结果,那些回归相关,我已经搞晕了。我把最后结果发给你,请你帮我在每个相关或回归前写一个表头,表明这是什么。
___ ____ ____ ____ ____ ©
/__ / ____/ / ____/ 17.0
___/ / /___/ / /___/ MP—Parallel Edition
Statistics and Data Science Copyright 1985-2021 StataCorp LLC
StataCorp
4905 Lakeway Drive
College Station, Texas 77845 USA
800-STATA-PC https://www.stata.com
979-696-4600 stata@stata.com
Stata license: Single-user 2-core perpetual
Serial number: 501806366048
Licensed to: aaa
bbb
Notes:
1. Unicode is supported; see help unicode_advice.
2. More than 2 billion observations are allowed; see help obs_advice.
3. Maximum number of variables is set to 5,000; see help set_maxvar.
. do "C:\Users\lenovo\AppData\Local\Temp\STD924_000000.tmp"
. * ===========================================================================
. * 验证 AI 投入是否具有滞后正向效应(终极修复版,确保一遍过)
. * 作者:AI 助手 | 日期:2025年4月5日
. * ===========================================================================
.
. * --- 1. 清空内存,设置路径 ---
. clear all
. cd "D:\Users\lenovo\Desktop" // 修改为你自己的路径
D:\Users\lenovo\Desktop
.
. * --- 2. 加载主财务数据 ---
. use "financial_cleaned.dta", clear
.
. * 检查是否有 year 变量
. capture confirm variable year
. if _rc != 0 {
. display as error "❌ 错误:数据中没有 'year' 变量!请检查数据结构"
. exit 111
. }
.
. * --- 3. 检查 ai_annual.dta 是否存在并合并 ---
. capture use "ai_annual.dta", clear
. if _rc != 0 {
. display as error "❌ 错误:无法打开文件 ai_annual.dta,请确认文件存在于桌面且名称正确"
. exit 601
. }
. keep year ai_mentions
. save "ai_temp.dta", replace
(file ai_temp.dta not found)
file ai_temp.dta saved
.
. * 回到主数据
. use "financial_cleaned.dta", clear
. merge m:1 year using "ai_temp.dta", nogen
Result Number of obs
-----------------------------------------
Not matched 0
Matched 39
-----------------------------------------
.
. * --- 4. 检查 rd_annual.dta 是否存在并合并 ---
. capture use "rd_annual.dta", clear
. if _rc != 0 {
. display as error "❌ 错误:无法打开文件 rd_annual.dta,请确认文件存在于桌面且名称正确"
. exit 601
. }
. keep year rd_expense
. save "rd_temp.dta", replace
(file rd_temp.dta not found)
file rd_temp.dta saved
.
. * 回到主数据
. use "financial_cleaned.dta", clear
. merge m:1 year using "ai_temp.dta", nogen
Result Number of obs
-----------------------------------------
Not matched 0
Matched 39
-----------------------------------------
. merge m:1 year using "rd_temp.dta", nogen
Result Number of obs
-----------------------------------------
Not matched 0
Matched 39
-----------------------------------------
.
. * 删除临时文件
. erase "ai_temp.dta"
. erase "rd_temp.dta"
.
. * --- 5. 按年聚合:将季度数据转为年度平均值 ---
. collapse (mean) roa roe debt_ratio ln_revenue /// // 财务指标取均值
> (first) ai_mentions rd_expense, by(year) // AI 和 R&D 取当年值
.
. * --- 6. 排序 ---
. sort year
.
. * --- 7. 生成下一年 ROA ---
. gen next_roa = roa[_n+1] if year[_n+1] == year + 1
(1 missing value generated)
. label var next_roa "Next Year's ROA"
.
. * --- 8. 描述性统计 ---
. summarize roa next_roa ai_mentions rd_expense ln_revenue debt_ratio
Variable | Obs Mean Std. dev. Min Max
-------------+---------------------------------------------------------
roa | 10 .0949047 .026076 .0620595 .1218738
next_roa | 9 .0919443 .0258139 .0620595 .1218738
ai_mentions | 10 52.9 56.58906 4 172
rd_expense | 10 2.74e+09 5.35e+08 1.73e+09 3.44e+09
ln_revenue | 10 23.12686 .3110618 22.51417 23.41911
-------------+---------------------------------------------------------
debt_ratio | 10 .0949394 .0146112 .0629635 .1099355
.
. * --- 9. 相关性分析 ---
. correlate next_roa ai_mentions rd_expense ln_revenue debt_ratio
(obs=9)
| next_roa ai_men~s rd_exp~e ln_rev~e debt_r~o
-------------+---------------------------------------------
next_roa | 1.0000
ai_mentions | -0.7280 1.0000
rd_expense | 0.8877 -0.5749 1.0000
ln_revenue | -0.8232 0.6087 -0.5741 1.0000
debt_ratio | 0.4942 -0.7731 0.4171 -0.2729 1.0000
.
. * --- 10. 回归分析 ---
. regress next_roa c.ai_mentions c.rd_expense c.ln_revenue c.debt_ratio i.year, robust
note: 2021.year omitted because of collinearity.
note: 2022.year omitted because of collinearity.
note: 2023.year omitted because of collinearity.
note: 2024.year omitted because of collinearity.
Linear regression Number of obs = 9
F(0, 0) = .
Prob > F = .
R-squared = 1.0000
Root MSE = 0
------------------------------------------------------------------------------
| Robust
next_roa | Coefficient std. err. t P>|t| [95% conf. interval]
-------------+----------------------------------------------------------------
ai_mentions | 3.34e-06 . . . . .
rd_expense | 1.73e-11 . . . . .
ln_revenue | -.0532505 . . . . .
debt_ratio | -.0980677 . . . . .
|
year |
2017 | .0035353 . . . . .
2018 | .0201439 . . . . .
2019 | .0230021 . . . . .
2020 | .0161762 . . . . .
2021 | 0 (omitted)
2022 | 0 (omitted)
2023 | 0 (omitted)
2024 | 0 (omitted)
|
_cons | 1.278377 . . . . .
------------------------------------------------------------------------------
.
. * --- 11. 输出结果到 Word ---
. * 如果未安装 outreg2,请先运行:ssc install outreg2, replace
. capture which outreg2
. if _rc == 111 {
. display as text "⚠️ 未安装 outreg2,正在尝试安装..."
. ssc install outreg2, replace
. }
. outreg2 using ai_lag_effect.doc, replace ctitle("Future ROA") auto(2) ///
> title("Table 1: Effect of AI Mentions on Next-Year ROA")
ai_lag_effect.doc
dir : seeout
.
. * --- 12. 绘制散点图:AI 提及 vs 下一年 ROA ---
. twoway (scatter next_roa ai_mentions, mlabel(year) mcolor(red) msymbol(circle)) ///
> (lfit next_roa ai_mentions, lcolor(blue)), ///
> title("AI Mentions Predict Future ROA?") ///
> subtitle("Current AI Mentions vs Next Year's ROA") ///
> xtitle("AI Mentions in Current Year") ///
> ytitle("ROA in Next Year") ///
> legend(off) ///
> name(ai_vs_future_roa, replace)
. graph export "ai_vs_future_roa.png", width(900) height(600) replace
(file ai_vs_future_roa.png not found)
file ai_vs_future_roa.png saved as PNG format
.
. * --- 13. 绘制趋势图:ROA 与 AI 提及随时间变化 ---
. preserve
. twoway (line roa year, lcolor(blue) lwidth(medium)) ///
> (line ai_mentions year, lcolor(red) yaxis(2) lwidth(medium)), ///
> title("Trend Over Time") ///
> xtitle("Year") ///
> ytitle("ROA", axis(1)) ///
> ytitle("AI Mentions", axis(2)) ///
> xlabel(2016(1)2025) ///
> legend(order(1 "ROA" 2 "AI Mentions")) ///
> name(roa_ai_trend, replace)
. graph export "roa_ai_trend.png", width(900) height(600) replace
(file roa_ai_trend.png not found)
file roa_ai_trend.png saved as PNG format
. restore
.
. * --- 14. 显示数据预览 ---
. list year roa next_roa ai_mentions in 1/12, sepby(year) noobs
observation numbers out of range
r(198);
end of do-file
r(198);
. do "C:\Users\lenovo\AppData\Local\Temp\STD924_000000.tmp"
. * ===========================================================================
. * 验证 AI 投入是否具有滞后正向效应(终极修复版,确保一遍过)
. * 作者:AI 助手 | 日期:2025年4月5日
. * ===========================================================================
.
. * --- 1. 清空内存,设置路径 ---
. clear all
. cd "D:\Users\lenovo\Desktop" // 修改为你自己的路径
D:\Users\lenovo\Desktop
.
. * --- 2. 加载主财务数据 ---
. use "financial_cleaned.dta", clear
.
. * 检查是否有 year 变量
. capture confirm variable year
. if _rc != 0 {
. display as error "❌ 错误:数据中没有 'year' 变量!请检查数据结构"
. exit 111
. }
.
. * --- 3. 检查 ai_annual.dta 是否存在并合并 ---
. capture use "ai_annual.dta", clear
. if _rc != 0 {
. display as error "❌ 错误:无法打开文件 ai_annual.dta,请确认文件存在于桌面且名称正确"
. exit 601
. }
. keep year ai_mentions
. save "ai_temp.dta", replace
(file ai_temp.dta not found)
file ai_temp.dta saved
.
. * 回到主数据
. use "financial_cleaned.dta", clear
. merge m:1 year using "ai_temp.dta", nogen
Result Number of obs
-----------------------------------------
Not matched 0
Matched 39
-----------------------------------------
.
. * --- 4. 检查 rd_annual.dta 是否存在并合并 ---
. capture use "rd_annual.dta", clear
. if _rc != 0 {
. display as error "❌ 错误:无法打开文件 rd_annual.dta,请确认文件存在于桌面且名称正确"
. exit 601
. }
. keep year rd_expense
. save "rd_temp.dta", replace
(file rd_temp.dta not found)
file rd_temp.dta saved
.
. * 回到主数据
. use "financial_cleaned.dta", clear
. merge m:1 year using "ai_temp.dta", nogen
Result Number of obs
-----------------------------------------
Not matched 0
Matched 39
-----------------------------------------
. merge m:1 year using "rd_temp.dta", nogen
Result Number of obs
-----------------------------------------
Not matched 0
Matched 39
-----------------------------------------
.
. * 删除临时文件
. erase "ai_temp.dta"
. erase "rd_temp.dta"
.
. * --- 5. 按年聚合:将季度数据转为年度平均值 ---
. collapse (mean) roa roe debt_ratio ln_revenue /// // 财务指标取均值
> (first) ai_mentions rd_expense, by(year) // AI 和 R&D 取当年值
.
. * --- 6. 排序 ---
. sort year
.
. * --- 7. 生成下一年 ROA ---
. gen next_roa = roa[_n+1] if year[_n+1] == year + 1
(1 missing value generated)
. label var next_roa "Next Year's ROA"
.
. * --- 8. 描述性统计 ---
. summarize roa next_roa ai_mentions rd_expense ln_revenue debt_ratio
Variable | Obs Mean Std. dev. Min Max
-------------+---------------------------------------------------------
roa | 10 .0949047 .026076 .0620595 .1218738
next_roa | 9 .0919443 .0258139 .0620595 .1218738
ai_mentions | 10 52.9 56.58906 4 172
rd_expense | 10 2.74e+09 5.35e+08 1.73e+09 3.44e+09
ln_revenue | 10 23.12686 .3110618 22.51417 23.41911
-------------+---------------------------------------------------------
debt_ratio | 10 .0949394 .0146112 .0629635 .1099355
.
. * --- 9. 相关性分析 ---
. correlate next_roa ai_mentions rd_expense ln_revenue debt_ratio
(obs=9)
| next_roa ai_men~s rd_exp~e ln_rev~e debt_r~o
-------------+---------------------------------------------
next_roa | 1.0000
ai_mentions | -0.7280 1.0000
rd_expense | 0.8877 -0.5749 1.0000
ln_revenue | -0.8232 0.6087 -0.5741 1.0000
debt_ratio | 0.4942 -0.7731 0.4171 -0.2729 1.0000
.
. * --- 10. 回归分析(修正版:避免过拟合)---
. * 不再使用 i.year,改用时间趋势或仅控制协变量
.
. * 方法一:简单稳健回归(推荐小样本)
. regress next_roa c.ai_mentions c.rd_expense c.ln_revenue c.debt_ratio, robust
Linear regression Number of obs = 9
F(3, 4) = .
Prob > F = .
R-squared = 0.9505
Root MSE = .00812
------------------------------------------------------------------------------
| Robust
next_roa | Coefficient std. err. t P>|t| [95% conf. interval]
-------------+----------------------------------------------------------------
ai_mentions | -.0000538 .000124 -0.43 0.687 -.000398 .0002905
rd_expense | 2.87e-11 7.17e-12 4.00 0.016 8.79e-12 4.86e-11
ln_revenue | -.0346581 .0132604 -2.61 0.059 -.0714749 .0021587
debt_ratio | .1340701 .1677207 0.80 0.469 -.3315972 .5997375
_cons | .8053355 .2946586 2.73 0.052 -.0127679 1.623439
------------------------------------------------------------------------------
.
. * 方法二:加入时间趋势(可选)
. * gen time_trend = year - 2016
. * regress next_roa c.ai_mentions c.rd_expense c.ln_revenue c.debt_ratio c.time_trend, robust
.
. * --- 11. 输出结果到 Word ---
. outreg2 using ai_lag_effect.doc, replace ctitle("Future ROA") auto(2) ///
> title("Table 1: Effect of AI Mentions on Next-Year ROA")
ai_lag_effect.doc
dir : seeout
.
. * --- 12. 绘制散点图 ---
. twoway (scatter next_roa ai_mentions, mlabel(year) mcolor(red) msymbol(circle)) ///
> (lfit next_roa ai_mentions, lcolor(blue)), ///
> title("AI Mentions Predict Future ROA?") ///
> subtitle("Current AI Mentions vs Next Year's ROA") ///
> xtitle("AI Mentions in Current Year") ///
> ytitle("ROA in Next Year") ///
> legend(off) ///
> name(ai_vs_future_roa, replace)
. graph export "ai_vs_future_roa.png", width(900) height(600) replace
file ai_vs_future_roa.png saved as PNG format
.
. * --- 13. 绘制趋势图 ---
. preserve
. twoway (line roa year, lcolor(blue) lwidth(medium)) ///
> (line ai_mentions year, lcolor(red) yaxis(2) lwidth(medium)), ///
> title("Trend Over Time") ///
> xtitle("Year") ///
> ytitle("ROA", axis(1)) ///
> ytitle("AI Mentions", axis(2)) ///
> xlabel(2016(1)2025) ///
> legend(order(1 "ROA" 2 "AI Mentions")) ///
> name(roa_ai_trend, replace)
. graph export "roa_ai_trend.png", width(900) height(600) replace
file roa_ai_trend.png saved as PNG format
. restore
.
. * --- 14. 显示数据预览(修正范围)---
. list year roa next_roa ai_mentions in 1/10, sepby(year) noobs
+--------------------------------------+
| year roa next_roa ai_men~s |
|--------------------------------------|
| 2016 .121548 .1202005 4 |
|--------------------------------------|
| 2017 .1202 .1179928 5 |
|--------------------------------------|
| 2018 .117993 .1218738 13 |
|--------------------------------------|
| 2019 .121874 .1115533 16 |
|--------------------------------------|
| 2020 .111553 .0837875 20 |
|--------------------------------------|
| 2021 .083788 .0620595 32 |
|--------------------------------------|
| 2022 .062059 .0654863 61 |
|--------------------------------------|
| 2023 .065486 .0806397 89 |
|--------------------------------------|
| 2024 .08064 .063905 117 |
|--------------------------------------|
| 2025 .063905 . 172 |
+--------------------------------------+
.
. * --- 15. 成功提示 ---
. display as text "✅ 分析完成!"
✅ 分析完成!
. display as text "📊 回归结果已保存至:ai_lag_effect.doc"
📊 回归结果已保存至:ai_lag_effect.doc
. display as text "🖼️ 图表已保存至桌面:"
🖼️ 图表已保存至桌面:
. display as text " • ai_vs_future_roa.png"
• ai_vs_future_roa.png
. display as text " • roa_ai_trend.png"
• roa_ai_trend.png
.
end of do-file
.
最新发布