楼主: 匿名
1504 0

[Stata] [Stata]schedule——自定义Stata运行时间(24小时内) [推广有奖]

匿名网友
楼主
匿名网友  发表于 2016-4-3 16:10:38 |坛友微信交流群|倒序 |AI写论文
相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

schedule——自定义Stata运行时间(24小时内)

  1. *Written for Stata 9.0 by Kerry L. Papps (klp27@cornell.edu)
  2. *13 October 2005

  3. *This ado-file allows the user to specify the start time for a Stata do-file up to 24 hours in advance
  4. *The syntax is either:
  5. *schedule start_time do_file[, run INTerval(interval_time) reset]
  6. *or
  7. *schedule start_time[, INTerval(interval_time)]
  8. *The first syntax can be used interactively; the second syntax can be used at the start of a do-file
  9. *The run option specifies that Stata should run rather than do the do-file
  10. *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
  11. *The reset option tells Stata to clear the spreadsheet and reset the memory limit to its initial value
  12. *start_time should be entered in the form 18:53 etc.


  13. program define schedule
  14.   version 9.0
  15.   syntax [anything] [, run INTerval(integer 30000) reset]

  16.   tokenize `anything'
  17.   local starttime "`1'"
  18.   local dofile "`2'"

  19.   if substr("`starttime'",3,1)~=":" {
  20.     di as error "start time should be entered in the form 18:53 etc."
  21.   }

  22.   qui memory
  23.   local initmem=r(M_data)

  24.   else {
  25.     local currenttime=real(substr(c(current_time),1,2))+real(substr(c(current_time),4,2))/60
  26.     local starttime2=real(substr("`starttime'",1,2))+real(substr("`starttime'",4,2))/60
  27.     local currentdate=c(current_date)
  28.     local currentdate=d(`currentdate')
  29.     local startdate=`currentdate'
  30.     if `starttime2'<`currenttime' {
  31.       local startdate=`startdate'+1
  32.     }

  33.     while `currentdate'<`startdate' {
  34.       sleep `interval'
  35.       local currentdate=c(current_date)
  36.       local currentdate=d(`currentdate')
  37.     }

  38.     local currenttime=real(substr(c(current_time),1,2))+real(substr(c(current_time),4,2))/60
  39.     while `currenttime'<`starttime2' {
  40.       sleep `interval'
  41.       local currenttime=real(substr(c(current_time),1,2))+real(substr(c(current_time),4,2))/60
  42.     }
  43.   }

  44.   if "`dofile'"~="" {
  45.     if "`run'"~="" {
  46.       run "`dofile'"
  47.     }
  48.     else {
  49.       do "`dofile'"
  50.     }
  51.   }

  52.   if "`reset'"~="" {
  53.     clear
  54.     set mem `initmem'b
  55.   }
  56. end
复制代码

注:本帖内容参考自http://people.bath.ac.uk/klp33/

       schedule.ado.rar (896 Bytes) 本附件包括:

  • schedule.ado




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:SCHEDULE Stata Sched tata 运行时间 schedule

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-20 04:15