-
Notifications
You must be signed in to change notification settings - Fork 1
/
pcn_load_estimates.ado
187 lines (158 loc) · 4.97 KB
/
pcn_load_estimates.ado
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
/*==================================================
project: Load working data stored in P drive
Author: David L. Vargas
E-email: [email protected]
url:
Dependencies: The World Bank
----------------------------------------------------
Creation Date: 5 Feb 2020 -
Modification Date:
Do-file version: 01
References:
Output:
==================================================*/
/*==================================================
0: Program set up
==================================================*/
program define pcn_load_estimates, rclass
syntax [anything(name=subcmd id="subcommand")], ///
[ ///
maindir(string) ///
REshaped ///
VERsion(string) ///
clear ///
pause ///
]
version 14
*---------- pause
if ("`pause'" == "pause") pause on
else pause off
* ---- Initial parameters
local date = date("`c(current_date)'", "DMY") // %tdDDmonCCYY
local time = clock("`c(current_time)'", "hms") // %tcHH:MM:SS
local date_time = `date'*24*60*60*1000 + `time' // %tcDDmonCCYY_HH:MM:SS
local datetimeHRF: disp %tcDDmonCCYY_HH:MM:SS `date_time'
local datetimeHRF = trim("`datetimeHRF'")
local user=c(username)
//========================================================
// Check version of pending data
//========================================================
qui {
* working month
local cmonth: disp %tdnn date("`c(current_date)'", "DMY")
*Working year
local wkyr: disp %tdCCyy date("`c(current_date)'", "DMY")
* Either Annual meeting (AM) or Spring meeting (SM)
if inrange(`cmonth', 1, 4) | inrange(`cmonth', 11, 12) local meeting "SM"
if inrange(`cmonth', 5, 10) local meeting "AM"
if inrange(`cmonth', 11, 12) {
local wkyr = `wkyr' + 1 // workign for the next year's meeting
}
return local wkyr = `wkyr'
return local meeting = "`meeting'"
local maindir "`maindir'/`wkyr'_`meeting'/estimates"
//========================================================
// conditions
//========================================================
/* clean version */
if ("`version'" != ""){
if ("`version'" != "list"){
if regexm("`version'","/"){
if (strlen("`version'") == 8 | strlen("`version'") == 10){
local version = date("`version'", "MDY")
}
else{
noi di as err "Version should be list or a date in either stata, mm/dd/yy or mm/dd/yyyy format."
}
}
}
}
/*==================================================
1: Load data in memory
==================================================*/
/* reshpaed or regular
if ("`REshaped'" != "" ){
local fileroot "primus_estimates_reshaped"
}
else{
local fileroot "primus_estimates"
}
*/
/* filename according to version */
local files: dir "`maindir'" files "*.dta", respectcase
if (wordcount(`"`files'"') == 0) {
noi disp in r "No estimates files found"
error
}
else{
if ("`version'" == ""){
local filename "`fileroot'"
}
else if ("`version'"=="list"){
if (wordcount(`"`files'"') == 1) {
local filename = regexr(`files',`".dta"',"")
noi disp in r "Loading Only available"
}
else {
noi disp as text "list of available estimates files:"
local i = 0
foreach file of local files {
local ++i
local file = regexr("`file'",`".dta"',"")
*if ("`avfile'" == "") loc avfile "`fileroot'"
noi disp `" `i' {c |} {stata `file'}"'
}
noi disp _n "select file to load" _request(_file)
local filename = regexr(`"`file'"',".dta",`""')
}
}
else{
cap confirm "`maindir'/`fileroot'_`version'.dta"
if _rc {
local verstart : di %13.0f cofd(`version')
local verstart = substr("`verstart'",1,5)
di "`verstart'"
foreach file of local files {
if regexm(`"`file'"', "(.+)_(`verstart'.+)\.dta"){
local a = regexs(2)
local versions "`versions' `a'"
}
}
if (wordcount(`"`versions'"') == 0) {
noi disp in r "No estimates files found for that date"
exit
}
if (wordcount(`"`versions'"') == 1) {
local version = subinstr("`versions'"," ","",.)
noi di as text "Loading only available for that date"
}
else {
noi disp as text "list of available versions for that date:"
local i = 0
foreach version of local versions{
loc ++i
noi di `" `i' {c |} {stata `version'}"'
}
noi disp _n "select file to load" _request(_version)
}
local filename "`fileroot'_`version'"
}
else{
local filename "`fileroot'_`version'"
}
}
}
noi di as text "loading `filename'.dta ..."
use "`maindir'/`filename'.dta", clear
noi disp as text "`filename'.dta" as res " successfully loaded"
}
end
exit
/* End of do-file */
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
Notes:
1.
2.
3.
Version Control:
03feb2020 20:56:07