-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpcn_production.ado
180 lines (124 loc) · 4.48 KB
/
pcn_production.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
/*==================================================
project: Create a load Povcalnet production vintages
Author: R.Andres Castaneda
E-email: [email protected]
url:
Dependencies: The World Bank
----------------------------------------------------
Creation Date: 15 Jul 2020 - 09:03:17
Modification Date:
Do-file version: 01
References:
Output:
==================================================*/
/*==================================================
0: Program set up
==================================================*/
program define pcn_production, rclass
syntax anything(name=subcmd id="action of pcn_production"), ///
[ ///
vintage(string) ///
clear ///
server(string) ///
replace ///
]
version 15
*##s
qui {
local maindir "\\wbntpcifs\povcalnet\01.PovcalNet\02.Production"
local subcmdok 0
* ---- 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)
/*==================================================
1: Load
==================================================*/
*----------1.1: Read current versions
if ("`subcmd'" == "load") {
// If vintage is not selected
if ("`vintage'" == "") {
noi _disp_dirs `subcmd' , maindir("`maindir'")
return add
}
*----------1.2: If vintage is selected
else {
mata: st_local("direx", strofreal(direxists("`maindir'/`vintage'")))
if (`direx' == 0) {
noi disp in red "Vintage `vintage' folder does not exist"
error
}
confirm file "`maindir'/`vintage'/PovcalNet_`vintage'.dta"
use "`maindir'/`vintage'/PovcalNet_`vintage'.dta", `clear'
}
local subcmdok 1
}
*##e
/*==================================================
2: Create version
==================================================*/
*----------2.1: check folder existence
if ("`subcmd'" == "create") {
if ("`vintage'" == "") {
noi disp in red "You must select a pre-existing vintage folder"
noi _disp_dirs `subcmd' , maindir("`maindir'") server(`server') `clear'
return add
}
else {
mata: st_local("direx", strofreal(direxists("`maindir'/`vintage'")))
if (`direx' == 0) {
noi disp in red "Vintage `vintage' folder does not exist"
error
}
*----------2.2: download data
povcalnet, server(`server') `clear'
cap noi datasignature confirm using "`maindir'/`vintage'/PovcalNet_`vintage'"
if (_rc | "`replace'" != "") {
datasignature set, reset saving("`maindir'/`vintage'/PovcalNet_`vintage'", replace)
cap mkdir "`maindir'/`vintage'/_vintage" // create vintage folder
save "`maindir'/`vintage'/_vintage/PovcalNet_`vintage'_`date_time'.dta"
noi save "`maindir'/`vintage'/PovcalNet_`vintage'.dta", replace
}
}
local subcmdok 1
} // end of create
/*==================================================
3: closing conditions
==================================================*/
*----------3.1:
if (`subcmdok' == 0) {
noi disp in red `"pcn_production action "`subcmd'" is not allowed. "' _n ///
"please one of the following: " in green " load | create "
error
}
*----------3.2:
} // end of qui
end
//========================================================
// Aux programs
//========================================================
program define _disp_dirs, rclass
syntax anything(name=subcmd), maindir(string) *
local dirs: dir "`maindir'" dirs "*", respectcase
local i = 0
noi disp in y "Available PovcalNet Production vintages"
noi disp in g "{hline 40}"
foreach dir of local dirs {
local ++i
if regexm("`dir'", "^_|\.git") continue
local pcncmd "pcn_production `subcmd', vintage(`dir') `options'"
noi disp in y _col(2) `i' _col(5) "{c |} {stata `pcncmd':`dir'}"
} // end of dirs loop
return local production_vtgs = `"`dirs'"'
end
exit
/* End of do-file */
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
Notes:
1.
2.
3.
Version Control: