-
Notifications
You must be signed in to change notification settings - Fork 2
/
povcalnet_info.ado
223 lines (174 loc) · 6.68 KB
/
povcalnet_info.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
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
221
222
223
*********************************************************************************
* povcalnet_info *
*********************************************************************************
program def povcalnet_info, rclass
version 11.0
syntax [, ///
COUntry(string) ///
REGion ///
AGGregate ///
clear ///
justdata /// programmers option
pause /// debugging
server(string) ///
]
if ("`pause'" == "pause") pause on
else pause off
qui {
if ("`clear'" == "") preserve
*---------- API defaults
if "`server'"=="" {
local site_name = "PovcalNet"
local server = "http://iresearch.worldbank.org/"
local url = "`server'/`site_name'"
return local server = "`server'"
return local site_name = "`site_name'"
return local url = "`url'"
}
else {
local url "`server'"
}
***************************************************
* 1. Load guidance database
***************************************************
tempfile temp1000
local jsfile = "`url'/js/initCItem2014.js"
return local jsfile = "`jsfile'"
cap copy "`jsfile'" `temp1000'
if (_rc != 0 ) {
noi disp in red "There is a problem accessing the information file."
noi disp in red "to check your connection, copy and paste in your browser the following address:" _n /*
*/ _col(4) in w `"`url'/js/initCItem2014.js"'
error
}
import delim using `temp1000', delim(",()") stringc(_all) /*
*/ stripq(yes) varnames(nonames) clear
/*==================================================
Data wrangling
==================================================*/
* Drop unnecessary variables
drop v1
missings dropobs, force
missings dropvars, force
*rename variables
/* rename (v3 v4 v5 v6 v10 v12 v13) (wb_region un_region income_region country_name ppp pppimp year) */
local vars1 v2 v3 v4 v5 v6 v10 v12 v13
local vars2 code wb_region un_region income_region country_name ppp pppimp year
local i = 0
foreach var of local vars1 {
local ++i
rename `var' `: word `i' of `vars2''
}
gen country_code = substr(code,1,3)
gen coverage_code = substr(code,-1,1)
gen coverage_level = ""
replace coverage_level = "national" if inlist(v7, "N", "A")
replace coverage_level = "urban" if v7 == "U"
replace coverage_level = "rural" if v7 == "R"
gen coverage_type = ""
replace coverage_type = "national" if v7 == "N"
replace coverage_type = "urban" if v7 == "U"
replace coverage_type = "rural" if v7 == "R"
replace coverage_type = "national aggregate" if v7 == "A"
drop v* // drop unneeded variables
order country_code country_name wb_region un_region income_region coverage_level coverage_type coverage_code year
if ("`justdata'" != "") exit
***************************************************
* 2. Inital listing with countries and regions
***************************************************
if ("`country'" == "") & ("`region'" == "") {
qui{
noi disp in y _n "{title:Available Surveys}: " in g "Select a country or region"
noi disp in y _n "{title: Countries}"
quietly levelsof country_code , local(countries)
local current_line = 0
foreach cccc of local countries{
local current_line = `current_line' + 1
local display_this = "{stata povcalnet_info, country(`cccc') clear: `cccc'} "
if (`current_line' < 10) noi display in y `"`display_this'"' _continue
else{
noi display in y `"`display_this'"'
local current_line = 0
}
}
noi disp in y _n(2) "{title: Regions}"
quietly levelsof wb_region, local(regions)
foreach i_reg of local regions{
local current_line = 0
local dipsthis "{stata povcalnet, region(`i_reg') year(all) aggregate clear:`i_reg' }"
noi disp " `dipsthis' " _c
}
noi display in y _n "{stata povcalnet_info, region clear: World Bank regions by year}"
noi display _n ""
exit
}
}
***************************************************
* 3. Listing of country surveys
***************************************************
if ("`country'" != "") & ("`region'" == "") {
qui{
noi disp in y _n "{title:Available Surveys for `country'}"
preserve
local country = upper("`country'")
keep if country_code == "`country'"
local link_detail = "`url'/Docs/CountryDocs/`country'.htm"
noi display `"{browse "`link_detail'" : Detailed information (browser)}"'
local nobs = _N
local current_line = 0
local index_s = 1
foreach n of numlist 1/`nobs' {
noi disp in y _n "`=country_name[`index_s']'-`=coverage_level[`index_s']'"
noi disp in y "year (survey year)"
local years_current = "`=year[`index_s']'"
local coverage = "`=coverage_level[`index_s']'"
local years_current: subinstr local years_current "," " ", all
local index_s = `index_s'+ 1
foreach ind_y of local years_current {
local current_line = `current_line' + 1
local ind_y_c=substr("`ind_y'",1,4)
local display_this = "{stata povcalnet, country(`country') year(`ind_y') coverage(`coverage') clear: `ind_y_c'(`ind_y')}"
if (`current_line' < 10) noi display in y `"`display_this'"' _continue
else{
noi display in y `"`display_this'"'
local current_line = 0
}
}
noi display `"{stata povcalnet, country(`country') year(all) coverage(`coverage') clear: All}"'
}
restore
noi display _n ""
exit
break
}
}
***************************************************
* 4. Listing of regions
***************************************************
if ("`country'" == "") & ("`region'" != "") {
qui{
noi disp in y _n "{title:Available Surveys}"
noi disp in y _n "{title:Select a Year}"
quietly levelsof wb_region, local(regions)
foreach i_reg of local regions{
local current_line = 0
noi disp in y _n "`i_reg'"
local years_current = "$refyears"
foreach ind_y of local years_current {
local current_line = `current_line' + 1
local display_this = "{stata povcalnet, region(`i_reg') year(`ind_y') aggregate clear: `ind_y'}"
if (`current_line' < 10) noi display in y `"`display_this'"' _continue
else{
noi display in y `"`display_this'"'
local current_line = 0
}
}
noi display in y "{stata povcalnet, region(`i_reg') year(all) aggregate clear: All}"
}
noi display _n ""
exit
break
}
}
}
end