2013-11-15 445 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

相關問題