-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsshnd.do
More file actions
81 lines (71 loc) · 2.81 KB
/
Copy pathsshnd.do
File metadata and controls
81 lines (71 loc) · 2.81 KB
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
qui {
// X.X.X. 04DEC2017 Updates following Nov/Dec Stata software update
// X.X.X. 01SEP2017 Adam Ross Nelson Original Version
// Author/Creator: Adam Ross Nelson
// Questions: Via GitHub or Twitter @adamrossnelson
// Maintained at: https://github.com/adamrossnelson/StataQuickReference
// This do prompts the user to specify a log file location. From log file
// location this do file also infers the same location for saving dta
// files. Lastly, this do also infers a sub dir which can be used to save
// and store temporary, working, or meta files.
// Intended use is to call this do file from another do file. This do file
// will establish three globals for later use: lobal dtagbl = $dtagbl AND
// Global loggbl = $loggbl AND Global wkdgbl = $wkdgbl
// Set preferences
set more off
clear all
set logtype text
// Gathers input from user. Error checks user correctly specified .log filename.
// Declare a global with a default project name.
global loggbl = "LogFileName.log"
// Ask user to define project name and location.
capture window fsave loggbl "Specify a log file name and location." "Log file|*.log" log
// Close stray SvSpcHndlr log file.
capture log close
capture log close SvSpcHndlr
noi log using "$loggbl", replace name(SvSpcHndlr)
// Define location and file name for resulting data file.
global dtagbl = subinstr("$loggbl",".log",".dta",.)
// Define location path for workspace.
global wkdgbl = subinstr("$loggbl",".log","wksp",.)
// Provide user with information & option to cancel.
noi di ""
noi di "#############################################################################"
noi di ""
noi di " Will create (or overwrite):"
noi di " Datafile: $dtagbl"
noi di " Logfile: $loggbl"
noi di ""
noi di " Will create (use):"
noi di " Workspace: $wkdgbl"
noi di ""
noi di " Dialogue window asks, Are you sure you wish to proceed?"
noi di ""
noi di "#############################################################################"
window stopbox rusure "Will create or overwrite : `=char(13)'" ///
"$loggbl, " ///
"$dtagbl, & " ///
"$wkdgbl. `=char(13)'" ///
"Do you wish to continue?"
// Make directory at workspace location.
// -mkdir- for existing location does not delete existing data.
capture mkdir "$wkdgbl"
// Change working directory to new location.
cd "$wkdgbl"
// Double check working directory location.
noi di ""
noi di ""
noi di "Changed working directory; current working directory:"
noi di c(pwd)
noi di ""
noi di "Global dtagbl = $dtagbl"
noi di "Global loggbl = $loggbl"
noi di "Global wkdgbl = $wkdgbl"
noi di ""
noi di "{ul:To append log file...}"
noi di " Use: {cmd:log using {it:filename} [, append]}"
noi di " OR: {cmd:log using {it:$loggbl} [, append]}"
noi di " OR: {cmd:log using {it:loggbl (see above)} [, append]}"
noi di ""
noi log close SvSpcHndlr
}