- *Written for Stata 9.0 by Kerry L. Papps (klp27@cornell.edu)
- *13 October 2005
- *This ado-file allows the user to specify the start time for a Stata do-file up to 24 hours in advance
- *The syntax is either:
- *schedule start_time do_file[, run INTerval(interval_time) reset]
- *or
- *schedule start_time[, INTerval(interval_time)]
- *The first syntax can be used interactively; the second syntax can be used at the start of a do-file
- *The run option specifies that Stata should run rather than do the do-file
- *The interval option specifies the length of time in milliseconds that should elapse before Stata re-checks the current time; the default is 5 mins
- *The reset option tells Stata to clear the spreadsheet and reset the memory limit to its initial value
- *start_time should be entered in the form 18:53 etc.
- program define schedule
- version 9.0
- syntax [anything] [, run INTerval(integer 30000) reset]
- tokenize `anything'
- local starttime "`1'"
- local dofile "`2'"
- if substr("`starttime'",3,1)~=":" {
- di as error "start time should be entered in the form 18:53 etc."
- }
- qui memory
- local initmem=r(M_data)
- else {
- local currenttime=real(substr(c(current_time),1,2))+real(substr(c(current_time),4,2))/60
- local starttime2=real(substr("`starttime'",1,2))+real(substr("`starttime'",4,2))/60
- local currentdate=c(current_date)
- local currentdate=d(`currentdate')
- local startdate=`currentdate'
- if `starttime2'<`currenttime' {
- local startdate=`startdate'+1
- }
- while `currentdate'<`startdate' {
- sleep `interval'
- local currentdate=c(current_date)
- local currentdate=d(`currentdate')
- }
- local currenttime=real(substr(c(current_time),1,2))+real(substr(c(current_time),4,2))/60
- while `currenttime'<`starttime2' {
- sleep `interval'
- local currenttime=real(substr(c(current_time),1,2))+real(substr(c(current_time),4,2))/60
- }
- }
- if "`dofile'"~="" {
- if "`run'"~="" {
- run "`dofile'"
- }
- else {
- do "`dofile'"
- }
- }
- if "`reset'"~="" {
- clear
- set mem `initmem'b
- }
- end
复制代码注:本帖内容参考自http://people.bath.ac.uk/klp33/
schedule.ado.rar
(896 Bytes)
本附件包括:
|