2013-11-15 436 views
2

我想知道是否可以自动保存.do文件,以便它包含与我在.do文件内创建的日志文件上的时间戳匹配的时间戳。例如,我开始每。做文件我得看起来像这样:Stata:每次在do文件编辑器中执行.do文件时,是否可以使用时间戳自动保存.do文件?

#delimit ; 
capture log close; 
display _n(250); 

*******Sets up the log for the output; 
local a1=substr(c(current_time),1,2); 
local a2=substr(c(current_time),4,2); 
local a3=substr(c(current_time),7,2); 
local b =  c(current_date); 

log using "H:\HSRE\Hospice Payment Reform\Plotzke\Ad Hoc Tasks\OY1\Monitoring for macs\Log\BPA Log (`b')`a1'_`a2'_`a3'", t; 

<rest of the program> 

display "Start: `starttime'"; 
display "End: " "$S_TIME"; 
log close; 

有什么我可以在节目的最后添加将保存我只是跑了。做文件(在.do文件编辑器中)带时间戳(这样我可以将代码与日志匹配)?

例如,目前我有一个文件:

"K:\Common\HSRE\Hospice Payment Reform\Plotzke\Ad Hoc Tasks\OY1\BenefitPeriodAnalysis\code\Benefit period analysis (Code).do" 

如果我每次运行。做文件,它会保存这将是巨大的:

"K:\Common\HSRE\Hospice Payment Reform\Plotzke\Ad Hoc Tasks\OY1\BenefitPeriodAnalysis\code\Benefit period analysis (Code)(`b')`a1'_`a2'_`a3'.do" 

[或一些变化]

回答

2

你总是可以做到以下几点,以便有一个非常钝的版本:

假设你是op erating了主。做文件:

"K:\...\Benefit period analysis (Code).do" 

你可以只添加一行到你的代码(在您设置的所有当地人),该文件复制一个新的时间戳的名字:

copy "K:\...\Benefit period analysis (Code).do" "K:\...\Benefit period analysis (Code)(`b')`a1'_`a2'_`a3'.do" 

但请注意,在运行之前,您总是想要打开.do文件,并且您的.do文件编辑器不会切换为显示此新创建的文件:它将继续显示主文件(非时间戳版本)。但我认为这将实现你的目标。

+0

谢谢!这是一个非常简单的解决方案,可以满足我的需求。 – user2992957

相关问题