-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpcn_primus_download.ado
139 lines (114 loc) · 4.23 KB
/
pcn_primus_download.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
/*==================================================
project: Download pending databases from PRIMUS
Author: R.Andres Castaneda
E-email: [email protected]
url:
Dependencies: The World Bank
----------------------------------------------------
Creation Date: 29 Jul 2019 - 16:01:01
Modification Date:
Do-file version: 01
References:
Output:
==================================================*/
/*==================================================
0: Program set up
==================================================*/
program define pcn_primus_download, rclass
syntax [anything(name=subcmd id="subcommand")], ///
[ ///
COUNtries(string) ///
Years(numlist) ///
REGions(string) ///
DIR(string) ///
Status(string) ///
DOWNload(string) ///
TRANSfile(string) ///
replace ///
clear ///
pause ///
]
version 14
*---------- conditions
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)
/*
if ("`status'" == "approved") local dir "p:\01.PovcalNet\03.QA\05.PRIMUS_approved"
else local dir "p:\01.PovcalNet\03.QA\02.PRIMUS_pending"
*/
if ("`status'" == "approved") local dir "p:\01.PovcalNet\03.QA\02.PRIMUS\approved"
else local dir "p:\01.PovcalNet\03.QA\02.PRIMUS\pending"
if ("`countries'" == "") local countries "all"
// =============================
// Preliminay checks
// =============================
if !inlist("`download'", "transactions", "trans","estimates") {
noi di as err "download must be either transactions or estimates"
}
//========================================================
// 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'"
//===========================================================
// Check transaction ID's
//===========================================================
if ("`transfile'" == "") {
noi pcn_primus_download_trans, countries(`countries') years(`years') status(`status') ///
wkyr(`wkyr') meeting(`meeting') dir(`dir') date_time(`date_time')
return local change = "`r(change)'"
}
else {
return local change = "User given"
}
//===========================================================
// Download estimates (If demanded)
//===========================================================
if ("`r(change)'" != "No Change") {
if ("`download'" == "trans" | "`download'" == "transactions") {
// nothing happens
}
else if ("`download'" == "" | "`download'" == "estimates") {
noi pcn_primus_download_estimates, status(`status') date_time(`date_time') ///
wkyr(`wkyr') meeting(`meeting') dir(`dir') transfile(`transfile')
}
else {
noi di as err "Only estimates or transactions are allowed to be loaded."
error
}
}
else{
noi di as result "Not new estimates to download"
}
}
end
/*====================================================================
Mata functions
====================================================================*/
findfile "pcn_functions.mata"
include "`r(fn)'"
exit
/* End of do-file */
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
Notes:
1.
2.
3.