レポート生成の自動化 [終了]
質問
私たちは Stata を使用して、地区内のすべての代理店のデータを毎月組み合わせて分析しています。この月次レポートについて、データ分析のレポートをなんとか自動作成したいと考えています。レポートには、報告された指標の概要表、主要な指標のいくつかのグラフィック、およびデータ グループ内の統計的に有意な差を示す分析表が含まれています。これらを PDF にして代理店に自動的に電子メールで送信したいと考えています。これを自動化するために使用できるソフトウェアについて何かアイデアはありますか?
解決
分析には Stata を使用しているため、レポートの自動化という重労働も Stata に任せることができます。
秘訣は、-rtfutil- のような Stata パッケージを使用して、記述した表とグラフィックを 1 つのドキュメントにエクスポートすることです。その時点で、メールで送信する前に PDF に変換する必要があります。
ここでは、-rtfutil- を使用するためのサンプル コードによって、RTF ドキュメント内に表と 2 つのグラフィックス (およびいくつかのテキスト段落) を含むドキュメントの作成を自動化します (例としてシステム データセット「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 ドキュメントに配置されます (このコードを Web ページからコピー/ペーストする場合は、コードの折り返しに関する問題に注意してください)。
あなたの質問では、このプロセス中に PDF を作成したいとも述べられました。ここでは、Stata 以外のソリューションを使用する必要があります。Mac OSX を使用している場合は、ターミナル -convert- ユーティリティまたはオートメータを使用してこれを行うことができます。または、他の解決策を以下に示します。 http://codesnippets.joyent.com/posts/show/1601
私は Windows を使用していないので、その OS での解決策がわかりません。幸運を。