Skip to content

Instantly share code, notes, and snippets.

@kongscn
Last active August 29, 2015 14:04
Show Gist options
  • Save kongscn/4085dbe0b58d2742c70f to your computer and use it in GitHub Desktop.
Save kongscn/4085dbe0b58d2742c70f to your computer and use it in GitHub Desktop.
Snippets

Snippet for R

  • Generate datetime string to use as filenames
fname = paste(format(Sys.time(), "%Y%m%d-%H%M%S"), ".EXT", sep="")

Snippet for Stata

  • reset random seed using date time

You might be quite suprised if you are new to stata and just realized that stata use the same random seed for every startup. To see this, type display c(seed). This is to see, if you dont set the seed, you are useing the SAME random data for all your research life.

I find my self very willing to add the following line to my profile.do. This is not a perfect solution but what I can get from within stata is limited. Well, better than noting anyway.

set seed `= clock("`c(current_date)' `c(current_time)'","DMYhms")/1000'

  • date time filename
`: display %tCCCYY-NN-DD-HH-MM-SS Clock("`c(current_date)' `c(current_time)'","DMYhms")'

This code will generate a string like 2014-01-28-15-24-30, you can use this to save a file, eg save ...(replace the ... with the code above).

  • auto logging

Add the following to your profile.do

log using PATH/TO/LOG/`: display %tCCCYY-NN-DD-HH-MM-SS ///
    Clock("`c(current_date)' `c(current_time)'","DMYhms")', ///
    name(default_log_file) text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment