Stata 读取单独的文件以用于ado文件(相对路径)

Stata 读取单独的文件以用于ado文件(相对路径),stata,Stata,暗示这可能不可能,但我想我无论如何都会问。我正在编写一个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

暗示这可能不可能,但我想我无论如何都会问。我正在编写一个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
程序定义文件
/*
读取文件(`1')并逐行写入
到另一个文件(`2')。两个文件都应该是
作为文件对象句柄传递。
*/
文件读取'1'行
而r(eof)==0{
如果(“'3'”==“1”){
文件写入'2'`macval(行)''''\n
}
否则{
文件写入'2'`macval(行)''\u n/'
}
文件读取'1'行
}
结束
程序生成部分
tempname thtml_文件
tempname tcsv_文件
临时名称tjs_fil
//!!!!!!!!!与问题相关!!!!!!!
//需要访问此文件,该文件应位于同一位置
//目录作为这个.ado文件
本地脚本script.js
//打开图表的所有组件文件
文件使用“out.html”打开“thtml_文件”,写入“replace”
使用“脚本”打开“tjs_文件”,读取
//新html文件的开始
本地html_top///
///
///
///
///
///
///
///
///
//写html文件的开头
文件写入'thtml'文件''html'顶部''
//插入javascript
injectFile`tjs_file'`thtml_file'
//关闭HTML文件
文件写入“thtml_文件”;" 
结束
使用findfile查找ADO

例如:

. findfile ivreg2.ado
c:\ado\plus/i/ivreg2.ado

. di r(fn)
c:\ado\plus/i/ivreg2.ado
它还允许在不同于工作目录和ADO路径的文件夹中搜索

期待看到您的包裹,尽管我同意Nick Cox的礼仪规则

使用findfile查找您的包裹

例如:

. findfile ivreg2.ado
c:\ado\plus/i/ivreg2.ado

. di r(fn)
c:\ado\plus/i/ivreg2.ado
它还允许在不同于工作目录和ADO路径的文件夹中搜索


期待看到您的软件包,尽管我同意Nick Cox关于礼仪规则的看法

但我更喜欢看到这里引用的代码,不必离开某个地方,阅读您的代码并尝试理解它。我们只需要看到与您的问题相关的最小代码。感谢您的回复,我添加了一个最小的代码片段。感谢adding详细信息。Sergio建议的
findfile
对我来说很好。我更喜欢看到这里引用的代码,不必离开某个地方,阅读您的代码并尝试理解它。我们只需要看到与您的问题相关的最小代码。感谢您的回复,我添加了一个最小的代码片段。感谢您添加详细信息。Sergio建议
findfile
看起来不错。这听起来是个不错的选择,我不知道
findfile
,谢谢指针!这听起来是个不错的选择,我不知道
findfile
,谢谢指针!