在试验了一段时间后,我找到了一个适合我的解决方案。
有多种 ADO 可以处理导出特定函数。我使用outreg2 进行回归,使用tabout 进行汇总统计。
对于更简单的命令,您可以轻松编写自己的程序以将结果自动保存为标准格式的纯文本。这是我写的一些……请注意,这两个都显示结果(保存到日志文件)并将它们导出到文本文件中——如果你只想保存到文本中,你可以去掉di's和quisum、tab等命令:
cap program drop sumout
program define sumout
di ""
di ""
di "Summary of `1'"
di ""
sum `1', d
qui matrix X = (r(mean), r(sd), r(p50), r(min), r(max))
qui matrix colnames X = mean sd median min max
qui mat2txt, matrix(X) saving("`2'") replace
end
cap program drop tab2_chi_out
program define tab2_chi_out
di ""
di ""
di "Tabulation of `1' and `2'"
di ""
tab `1' `2', chi2
qui matrix X = (r(p), r(chi2))
qui matrix colnames X = chi2p chi2
qui mat2txt, matrix(X) saving("`3'") replace
end
cap program drop oneway_out
program define oneway_out
di ""
di ""
di "Oneway anova with dv = `1' and iv = `2'"
di ""
oneway `1' `2'
qui matrix X = (r(F), r(df_r), r(df_m), Ftail(r(df_m), r(df_r), r(F)))
qui matrix colnames X = anova_between_groups_F within_groups_df between_groups_df P
qui mat2txt, matrix(X) saving("`3'") replace
end
cap program drop anova_out
program define anova_out
di ""
di ""
di "Anova command: anova `1'"
di ""
anova `1'
qui matrix X = (e(F), e(df_r), e(df_m), Ftail(e(df_m), e(df_r), e(F)), e(r2_a))
qui matrix colnames X = anova_between_groups_F within_groups_df between_groups_df P RsquaredAdj
qui mat2txt, matrix(X) saving("`2'") replace
end
接下来的问题是如何将输出输入 Excel 并对其进行格式化。我发现将文本输出文件从 Stata 导入 Excel 的最佳方法是将它们连接成一个大文本文件,然后使用 Excel 中的Import Text File... 功能导入该单个文件。
我通过将此 Ruby 代码放在输出文件夹中,然后使用 qui shell cd path/to/output/folder/ && ruby table.rb 从我的 Do 文件运行 int 来连接文件:
output = ""
Dir.new(".").entries.each do |file|
next if file =~/\A\./ || file == "table.rb" || file == "out.txt"
if file =~ /.*xml/
system "rm #{file}"
next
end
contents = File.open(file, "rb").read
output << "\n\n#{file}\n\n" << contents
end
File.open("out.txt", 'w') {|f| f.write(output)}
一旦我将out.txt 导入到 Excel 中自己的工作表中,我就会使用 Excel 的一系列内置函数将数据整合到漂亮、漂亮的表格中。
我使用vlookup、offset、match、iferror 的组合以及带有单元格编号和文件名的隐藏列来执行此操作。源 .txt 文件包含在该文件内容上方的out.txt 中,您可以使用这些函数查找文件的内容,然后使用vlookup 和offset 引用特定单元格。
这个 Excel 业务实际上是这个系统中最复杂的部分,如果不向您显示文件,确实没有好的方法来解释它,但希望您能得到足够的想法来自己弄清楚。如果没有,请随时通过http://maxmasnick.com 与我联系,我可以为您获取更多信息。