【问题标题】:Automation for Generating Reports [closed]生成报告的自动化[关闭]
【发布时间】:2009-11-01 23:59:42
【问题描述】:

我们每个月都使用 Stata 来合并和分析我们在一个地区的所有机构的数据。我想以某种方式为这些月度报告自动创建数据分析报告。该报告包括一个报告指标的汇总表、几个关键指标的图形以及一个显示数据组在统计上显着差异的分析表。我希望这些是 pdf 格式并自动通过电子邮件发送给代理机构。关于我可以用来自动执行此操作的软件的任何想法?

【问题讨论】:

    标签: automation documentation-generation office-automation code-statistics stata


    【解决方案1】:

    由于您使用 Stata 进行分析,因此您也可以让它完成报告自动化的繁重工作。

    诀窍是使用像 -rtfutil- 这样的 Stata 包将您描述的表格和图形导出到单个文档中。此时,您需要先将其转换为 pdf,然后再通过电子邮件发送。

    这里有一些示例代码,用于使用 -rtfutil- 在 RTF 文档中自动创建包含表格和两个图形(加上一些文本段落)的文档(以系统数据集“auto.dta”为例):

        ******
    
        clear
    
        //RTF UTILITY FOR INSERTING GRAPHICS & TABLES//
    
        local sf "/users/ppri/desktop/"
    
                //SETUP
                 sysuse auto, clear
                 twoway scatter mpg price,  mlabel(make) || lfitci mpg price
                 graph export "`sf'myplot1.eps", replace
                 twoway scatter price mpg,  mlabel(make) by(for)
                 graph export "`sf'myplot2.eps", replace
    
                 **
                 tempname handle1
    
                //RTFUTIL
                 rtfopen `handle1' using "`sf'mydoc1.rtf", replace
                 file write `handle1' _n  _tab  "{\pard\b SAMPLE DOCUMENT \par}" _tab  _n 
                 file write `handle1' _n "{\line}" 
                 // Figure1
                 file write `handle1' "{\pard\b FIGURE 1:  Plot of Price\par}" _n
                 rtflink `handle1' using "`sf'myplot1.eps"
                 // Figure2
                 file write `handle1' _n "{\page}" _n /*
    */ "{\pard Here is the plot and a paragraph about it.  Here is the plot and a paragraph about it.  Here is the plot and a paragraph about it.  Here is the plot and a paragraph about it.....blah blah blah  blah blah   \line}" _n
                 file write `handle1' _n "{\line}" 
                 file write `handle1' "{\pard\b FIGURE2:  Plots of Price vs. MPG\par}" _n
                 rtflink `handle1' using "`sf'myplot2.eps"
                 //  Table Title
                 file write `handle1' _n "{\page}" _n
                 file write `handle1' _n "{\par\pard}" _n /*
    */   "{\par\pard  HERE IS A TABLE WITH THE CARS:  \par\pard}" _n
                 file write `handle1' _n "{\par\pard}" _n
    
    
                 // Summary Table
                          rtfrstyle make mpg weight, cwidths(2000 1440 1440) local(b d e)
                          listtex make foreign mpg if mpg<15, /*
                    */   handle(`handle1') begin("`b'") delim("`d'") end("`e'") /*
                    */  head("`b'\ql{\i Make}`d'\qr{\i Foreign}`d'\qr{\i MPG }`e'")
                          file write `handle1' _n "{\line}"  
                          file write `handle1' _n _tab(2)  /*
                   */ "{\pard\b Sources:  Census Data, etc...  \par}" _n _n
                        **
                 rtfclose `handle1'
    
        ******
    

    这会将您询问的所有元素放入 RTF 文档中(从网页复制/粘贴此代码时,请小心包装此代码的任何问题)。
    在您的问题中,您还提到希望在此过程中创建 PDF。在这里,您需要使用一些非 Stata 解决方案。如果您使用的是 Mac OSX,您可以使用 Terminal -convert- 实用程序或自动机来执行此操作,或者这里有一些其他解决方案:http://codesnippets.joyent.com/posts/show/1601
    我不使用 Windows,所以我不确定该操作系统的解决方案。祝你好运。

    【讨论】:

    • 好的,您的代码运行良好,但我。使用非 Stata 解决方案创建 PDF 将如何回答我关于“自动化”报告创建的问题? ii. STATA 无法识别 RTFUTIL 包——您的回复未描述如何获取它!??
    • 对于您的第一个问题:正如我所说,这取决于您使用的操作系统。如果您查看我引用的页面并决定使用基于 Mac OSX 终端的脚本,您仍然可以从 Stata 自动执行此操作,方法是在您的 do-file 中插入如下行:!convert mydoc1.rtf -o mydoc2.pdf。这 ”!” (exclam. pt.) 告诉 Stata 向你的操作系统“掏空”。对于第二个问题,您可以像安装任何其他 Stata 软件包一样安装 -rtfutil-,方法是键入 -findit rtfutil- 或 -ssc install rtfutil- 并按照屏幕上的说明进行操作。 ______ 埃里克 A. 布斯 | ebooth@tamu.edu | eric.a.booth@gmail.com _
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多