-
Notifications
You must be signed in to change notification settings - Fork 18
/
profile.do
220 lines (154 loc) · 5.31 KB
/
profile.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
*! SRQM version 2023.01.25
*! URL: https://f.briatte.org/teaching/quanti/
/* --- SRQM --------------------------------------------------------------------
This do-file sets up Stata for taking the SRQM course:
https://github.com/briatte/srqm
It creates a profile.do file in the Stata application folder that will try to
set the working directory to this folder. This do-file then tries to set up a
few Stata defaults and checks the integrity of the course material.
----------------------------------------------------------------------------- */
loc pid "[SRQM]"
// --- COURSE MACROS -----------------------------------------------------------
// working directory
gl SRQM_WD "`c(pwd)'"
// folders
gl SRQM_CODE = "code"
gl SRQM_DATA = "data"
gl SRQM_SETUP = "setup"
gl SRQM_FOLDERS = "$SRQM_CODE $SRQM_DATA $SRQM_SETUP"
// datasets
gl SRQM_DATASETS = "ess0816 gss7616 nhis1017 qog2019 wvs9904"
// packages
loc P_VARS = "_gstd01 fre lookfor_all renvars" // revrs
loc P_DATA = "kountry spmap wbopendata"
loc P_PLOTS = "plotbeta spineplot" // catplot ciplot distplot
loc P_SCHEMES = "scheme-burd" // gr0002_3 (lean) blindschemes scheme_tufte
loc P_TABLES = "estout leanout mkcorr tab_chi tabout" // outreg2
loc P_MISC = "" // clarify log2do2
gl SRQM_PACKAGES = "`P_VARS' `P_DATA' `P_PLOTS' `P_SCHEMES' `P_TABLES' `P_MISC'"
// ado-files
loc A_CORE = "srqm srqm_data srqm_grab srqm_link srqm_pkgs srqm_scan"
loc A_ELSE = "srqm_demo srqm_wipe"
loc A_UTILS = "stab stab_demo sbar sbar_demo utils"
gl SRQM_ADOFILES = "`A_CORE' `A_DATA' `A_UTILS'"
// do-files (including this one)
gl SRQM_DOFILES = "profile.do require.do ../profile.do"
// log
gl SRQM_LOGFILE = "srqm.log"
gl SRQM_LOGNAME = regexr("$SRQM_LOGFILE", "\.", "_")
// --- COURSE LOG --------------------------------------------------------------
cap log using "$SRQM_LOGFILE", name("$SRQM_LOGNAME") replace
loc log "`c(pwd)'/$SRQM_LOGFILE"
if _rc == 604 {
noi di as txt "logfile `log' already open"
}
else if _rc {
noi di as txt "logfile `log' failed to open (code", _rc ")"
}
else {
noi di as txt "logfile `log' opened"
}
// --- COURSE SETTINGS ---------------------------------------------------------
noi di as txt _n "`pid' Setting up Stata for the course..."
loc debug 0
if c(version) < 13 | c(version) > 17 | `debug' {
noi di as err "`pid' WARNING:", ///
as txt "code currently tested only with Stata 13 and 17"
}
cap pr drop srqm_error
pr de srqm_error
if _rc di as err "`pid' ERROR:", as txt "command failed (code", _rc ")"
end
if c(os) != "Unix" {
if c(update_query) == "on" | `debug' {
noi di as txt "`pid' permanently disabling -update_query-"
cap set update_query off
noi srqm_error
}
}
if c(more) == "on" | `debug' {
noi di as txt "`pid' permanently disabling -more-"
cap qui set more off, perm
noi srqm_error
}
if c(varabbrev) == "on" | `debug' {
noi di as txt "`pid' permanently disabling -varabbrev-"
cap set varabbrev off, perm
noi srqm_error
}
if c(version) < 12 | `debug' {
noi di as txt "`pid' permanently setting -memory- to 500MB"
cap set mem 500m, perm
noi srqm_error
}
if c(maxvar) < 7500 | `debug' {
noi di as txt "`pid' permanently setting -maxvar- to 7,500"
cap set maxvar 7500, perm
noi srqm_error
}
if c(scrollbufsize) < 500000 | `debug' {
noi di as txt "`pid' setting -scrollbufsize- to 500,000"
cap set scrollbufsize 500000
noi srqm_error
}
if c(scheme) != "burd" | `debug' {
noi di as txt "`pid' permanently setting -scheme- to 'burd'"
cap set scheme burd, perm
noi srqm_error
}
// --- COURSE FOLDERS ----------------------------------------------------------
foreach x of glo SRQM_FOLDERS {
cap cd "`x'"
if _rc {
noi di ///
as err "`pid' ERROR:" , ///
as txt "missing" , ///
as inp "`x'" , ///
as txt "folder"
exit _rc // fatal
}
cd ..
}
// --- COURSE UTLITIES ---------------------------------------------------------
// calls, in that order: srqm, srqm_link, srqm_pkgs, srqm_scan
adopath + "`c(pwd)'/$SRQM_SETUP"
cap run "$SRQM_SETUP/utils.ado" // required by srqm_pkgs (pkgs)
// silently check setup/ folder
cap noi srqm
if _rc {
exit -999 // bogus error code
}
loc e 0
// check global profile.do
cap noi srqm_link
if _rc loc e 1 // non-fatal
// check package installs
adopath + "`c(pwd)'/setup/pkgs" // find packages installed on restricted systems
cap noi srqm_pkgs, quiet
if _rc loc e 1 // non-fatal
// check code and data
cap noi srqm_scan
if _rc {
noi di ///
as err "`pid' ERROR:" , ///
as txt "essential course material is missing and could not be restored"
exit _rc // fatal
}
else if `e' {
noi di as txt _n "`pid' WARNING: setup encountered nonfatal error(s)"
}
// --- HELLO -------------------------------------------------------------------
loc h = real(substr("`c(current_time)'", 1, 2)) // hour
if `h' < 6 loc t "early" // before 6am
if `h' >= 6 loc t "morning" // 6am +
if `h' >= 12 loc t "afternoon" // noon +
if `h' >= 18 loc t "evening" // 6pm +
if `h' >= 22 loc t "late" // 10pm
if inlist("`t'", "early", "late") {
noi di as inp _n _col(8) "It is too `t' to do statistics.", ///
as txt "Go (back) to bed." _n
}
else {
noi di as inp _n _col(8) "Good `t',", as txt "and welcome to the course." _n
}
// ------------------------------------------------------------------ alright --