搜索
人大经济论坛 附件下载

附件下载

所在主题:
文件名:  schedule.ado.rar
资料下载链接地址: https://bbs.pinggu.org/a-2005848.html
本附件包括:
  • schedule.ado
附件大小:
896 Bytes   举报本内容

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/






    熟悉论坛请点击新手指南
下载说明
1、论坛支持迅雷和网际快车等p2p多线程软件下载,请在上面选择下载通道单击右健下载即可。
2、论坛会定期自动批量更新下载地址,所以请不要浪费时间盗链论坛资源,盗链地址会很快失效。
3、本站为非盈利性质的学术交流网站,鼓励和保护原创作品,拒绝未经版权人许可的上传行为。本站如接到版权人发出的合格侵权通知,将积极的采取必要措施;同时,本站也将在技术手段和能力范围内,履行版权保护的注意义务。
(如有侵权,欢迎举报)
二维码

扫码加我 拉你入群

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

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

GMT+8, 2026-2-7 21:06