-
Notifications
You must be signed in to change notification settings - Fork 35
/
logging.do
91 lines (60 loc) · 3.57 KB
/
logging.do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
********************************************************************************
** LOGGING STATA OUTPUT **
********************************************************************************
* For reproducibility, it is essential to keep a complete log of what your
* analyses. Stata offers logging functions that automate this task for you --
* the only thing you need to do is switch on the log at the start of each
* analysis and switch it off at the end. In between these two commands, Stata
* will write the following things to the log file:
* _1_ Every command you type or run from a do-file
* _2_ Every comment you make or including in a do-file (handy for annotations!)
* _3_ All output that your commands generate except for graphs.
** OPENING YOUR LOG FILE -- Pretty straightforward:
* This command starts logging immediately in the specified file name
log using "my log filename.log"
* Be sure to include the file name in quotation marks except if the filename is
* one word only.
* Stata knows two file formats for logs, we strongly recommend plain text log
* files, since you can open them in any text editor or word processor like
* Microsoft Word or LibreOffice. As you as the file name ends on .log, Stata
* will save the log in the correct format. However, you can force Stata to play
* nice by explicitly telling it to save the log as text:
log using "my log filename.log", text
* If you using the same log file for analysis in multiple sessions, Stata will
* complain if you are at risk of overwriting an existing file. This forces you
* to choose what you want to do:
* You can CONTINUE the old log file:
log using "my log filename.log", append
* All information in the log file is kept and all new information is added to
* the end of the log file. This is the better option in most circumstances,
* since it avoids any data loss.
* You can OVERWRITE the old log file:
log using "my log filename.log", replace
* You lose everything contained in the log file at this point, so you should
* only use this option if you are sure you can afford to lose this information!
* An easy way to avoid potential data loss is to give each log file a file name
* that includes the date and time when the analysis was started. You can do this
* automatically with the command:
log using "Log `c(current_date)' `c(current_time)'.log"
* Feel free to change the name of the log, but make sure to keep the commands
* for date and time -- `c(current_date)' and `c(current_time)' -- in the file
* name.
* We recommend giving each log file a name:
log using "Log `c(current_date)' `c(current_time)'.log", name("HELPFUL NOTE")
* The name is printed at the very top of the log file and allows you to leave a
* note to your future self about what you are doing in this log file.
* Are you doing unspeakable things to your data that you don't want to record?
* You can pause the log to exclude a part of your analysis from the log:
log off
* All done and want to switch the log back on?
log on
* This is particularly useful if you are exploring or tinkering with your data
* and don't need an actual log of what you are doing. However, there is no harm
* in keeping the log running at all times. Who knows? You might find something
* useful when playing with the data, and if the log isn't on, you don't have a
* record of it...
* At the end of your analysis, you should close your log properly:
log close _all
* This ensures that your log file is properly written to disk. Using _all here
* tells Stata to close any log, independent of the helpful name we have given
* it above.