This question表明它可能不可能,但我想我还是会问。我正在编写一个Stata包,其中主.ado
文件需要在另一个(javascript)文件中读取以写出最终结果。
基本上,我试图在Stata中执行以下操作
修改:添加了代码示例
program define injectFile
/*
Read a file (`1') and write it line by line
to another file (`2'). Both files should be
passed as file object handles.
*/
file read `1' line
while r(eof) == 0 {
if ("`3'" == "1") {
file write `2' `"`macval(line)'"' "\n"
}
else {
file write `2' `"`macval(line)'"' _n //"
}
file read `1' line
}
end
program generateChart
tempname thtml_file
tempname tcsv_file
tempname tjs_fil
// !!!!!!!! Relevant to the question !!!!!!!
// need to access this file which should be located in the same
// directory as this .ado file
local script script.js
// Open all the component files for the chart
file open `thtml_file' using "out.html", write `replace'
file open `tjs_file' using "`script'", read
// The start of the new html file
local html_top ///
<html> ///
<head> ///
<meta http-equiv='Content-Type' content='text/htmlcharset=utf-8' / > ///
<script src='https://code.jquery.com/jquery-1.11.1.min.js'></script> ///
<script src='http://code.highcharts.com/highcharts.js'></script> ///
</head> ///
<body> ///
<div id='chart'></div> ///
<script>
// Write the beginning of the html file
file write `thtml_file' "`html_top'" _n
// Insert the javascript
injectFile `tjs_file' `thtml_file'
// Close the htmlfile
file write `thtml_file' "';</script></body></html>"
end
答案 0 :(得分:4)
使用 findfile 查找您的ADO。
例如:
. findfile ivreg2.ado
c:\ado\plus/i/ivreg2.ado
. di r(fn)
c:\ado\plus/i/ivreg2.ado
它还允许搜索与工作目录和ADO路径不同的文件夹
期待看到你的礼包,虽然我同意尼克考克斯关于礼仪规则