-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauxiliary_files.html
557 lines (531 loc) · 38.3 KB
/
auxiliary_files.html
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.3.433">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Auxiliary Files</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="auxiliary_files_files/libs/clipboard/clipboard.min.js"></script>
<script src="auxiliary_files_files/libs/quarto-html/quarto.js"></script>
<script src="auxiliary_files_files/libs/quarto-html/popper.min.js"></script>
<script src="auxiliary_files_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="auxiliary_files_files/libs/quarto-html/anchor.min.js"></script>
<link href="auxiliary_files_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="auxiliary_files_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="auxiliary_files_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="auxiliary_files_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="auxiliary_files_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
</head>
<body class="fullcontent">
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title">Auxiliary Files</h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<section id="list-of-auxiliary-files" class="level2">
<h2 class="anchored" data-anchor-id="list-of-auxiliary-files">List of Auxiliary Files</h2>
<p>Here is the list of auxiliary flies along with variable lists within each of the auxiliary data. In the variable list, the key variable(s) for the underline auxiliary file are represented as bold text. Variables that can be used as interchangeable/ replacement for any of the key variables are represented in square brackets.</p>
<ol type="1">
<li>pfw: wb_region_code, <strong>country_code</strong>, pcn_region_code, ctryname, <strong>year</strong>, [surveyid_year], timewp, fieldwork, <strong>survey_acronym</strong>, link, altname, survey_time, wbint_link, wbext_link, alt_link, pip_meta, surv_title, surv_producer, survey_coverage, [welfare_type], use_imputed, use_microdata, use_bin, use_groupdata, reporting_year, survey_comparability, comp_note, preferable, display_cp, fieldwork_range, [survey_year], ref_year_des, wf_baseprice, wf_baseprice_note, wf_baseprice_des, wf_spatial_des, wf_spatial_var, cpi_replication, cpi_domain, cpi_domain_var, wf_currency_des, ppp_replication, ppp_domain, ppp_domain_var, wf_add_temp_des, wf_add_temp_var, wf_add_spatial_des, wf_add_spatial_var, tosplit, tosplit_var, inpovcal, oth_welfare1_type, oth_welfare1_var, gdp_domain, pce_domain, pop_domain, Note, pfw_id</li>
</ol>
<p>Note: <em>welfare_type</em> and <em>survey_acronym</em>, and <em>year</em> and <em>surveyid_year</em> can be interchangeably used as key to merge pfw data with other auxiliary files.</p>
<ol start="2" type="1">
<li>cpi: <strong>country_code</strong>, <strong>cpi_year</strong>, [survey_year], cpi, ccf, <strong>survey_acronym</strong>, change_cpi2011, cpi_domain, cpi_domain_value, cpi2017_unadj, cpi2011_unadj, cpi2011, cpi2017, cpi2011_SM22, cpi2017_SM22, cpi2005, <strong>cpi_data_level</strong>, cpi2011_SM23, cpi2017_SM23, cpi_id</li>
</ol>
<p>Note: <em>cpi_year</em> and <em>survey_year</em> can be interchangeably used as the pary of key variables.</p>
<ol start="3" type="1">
<li><p>gdp: <strong>country_code</strong>, <strong>year</strong>, gdp, <strong>gdp_data_level</strong>, gdp_domain</p></li>
<li><p>gdm: survey_id, <strong>country_code</strong>, <strong>surveyid_year</strong>, [survey_year], welfare_type, survey_mean_lcu, distribution_type, gd_type, <strong>pop_data_level</strong>, pcn_source_file, pcn_survey_id</p></li>
<li><p>pce: <strong>country_code</strong>, <strong>year</strong>, pce, <strong>pce_data_level</strong>, pce_domain</p></li>
<li><p>pop: <strong>country_code</strong>, <strong>year</strong>, <strong>pop_data_level</strong>, pop, pop_domain</p></li>
<li><p>ppp: <strong>country_code</strong>, <strong>ppp_year</strong>, <strong>release_version</strong>, <strong>adaptation_version</strong>, ppp, ppp_default, ppp_default_by_year, ppp_domain, <em>ppp_data_level</em></p></li>
</ol>
<p>Note: ppp auxiliary data may need to be reshaped to merge it with other auxiliary files.</p>
<ol start="8" type="1">
<li><p>maddison: <strong>country_code</strong>, <strong>year</strong>, mpd_gdp</p></li>
<li><p>weo: <strong>country_code</strong>, <strong>year</strong>, weo_gdp</p></li>
<li><p>npl: <strong>country_code</strong>, <strong>reporting_year</strong>, nat_headcount, comparability, footnote</p></li>
<li><p>countries: <strong>country_code</strong>, country_name, africa_split, africa_split_code, region, region_code, world, world_code</p></li>
<li><p>regions: region, <strong>region_code</strong>, grouping_type</p></li>
<li><p>income_groups: <strong>country_code</strong>, <strong>year_data</strong>, incgroup_historical, fcv_historical, ssa_subregion_code</p></li>
<li><p>metadata: <strong>country_code</strong>, country_name, reporting_year, [survey_year], <strong>surveyid_year</strong>, survey_title, survey_conductor, survey_coverage, <strong>welfare_type</strong>, distribution_type, metadata</p></li>
</ol>
</section>
<section id="relationship-between-auxiliary-files" class="level2">
<h2 class="anchored" data-anchor-id="relationship-between-auxiliary-files">Relationship between auxiliary files</h2>
<p>Understanding the relationship among auxiliary files help to merge the files easily. The auxiliary datsets are grouped into three based on unique level of observations. Datasets within each group have one-to-one relationship.</p>
<ul>
<li>Group one: maddison, weo</li>
</ul>
<p>Note: Group one files can be merged with any of the auxiliary files using <strong>country_code</strong> and <strong>year</strong> varaibles.</p>
<ul>
<li>Group two: gdp, pop, gdm, pce, <em>ppp</em></li>
</ul>
<p>Note: ppp requires reshaping to map one-to-one within its group members.</p>
<ul>
<li>Group three: metadata, cpi, pfw</li>
</ul>
</section>
<section id="one-to-one-relationship" class="level1">
<h1>one-to-one relationship</h1>
<p>Datasets within each group have one-to-one relationship</p>
</section>
<section id="many-to-one" class="level1">
<h1>many-to-one</h1>
<p>Datasets in Group two and three have many-to-one relationship with datasets in Group one.</p>
<section id="merge-auxiliary-files" class="level2">
<h2 class="anchored" data-anchor-id="merge-auxiliary-files">Merge auxiliary files</h2>
<p>In order to merge any two auxiliary data, we may need to change part of key variable names. For example, reporting level variable such as pop_data_level, cpi_data_level, gdp_data_level, pce_data_level and ppp_data_level are same in content and can be renamed as <em>reporting_level</em> and <strong>year</strong> can be renamed as <strong>surveyid_year</strong>.</p>
<p>We may need to generate a data that contains set of key variables. For example, to merge pfw data with any of the datasets at reporting level (pop, pce, gdp, gdm, ppp) we need to add reporting level variable in pfw data.</p>
<p>Let’s generate a data that can be used to merge pfw data with datasets at reporting level. This dataset is going to be generated using variables from pfw and cpi datasets.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co"># pfw ---------------------------------------------------</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>pfw <span class="ot"><-</span> pipload<span class="sc">::</span><span class="fu">pip_load_aux</span>(<span class="st">"pfw"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Most recent version of data loaded:
'pfw.qs'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>ℹ no labels available for measure pfw</code></pre>
</div>
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>pfw_key_options <span class="ot"><-</span> pfw[, .(country_code,</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> year,</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> surveyid_year,</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> survey_acronym,</span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> survey_coverage,</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> welfare_type,</span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> survey_year,</span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> cpi_domain,</span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a> cpi_domain_var)]</span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a>pfw_key_options <span class="sc">|></span> <span class="fu">count</span>(cpi_domain_var)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> cpi_domain_var n
1: 2211
2: urban 35</code></pre>
</div>
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>pfw_key_options <span class="ot"><-</span> pfw_key_options[, cpi_domain_value<span class="sc">:</span><span class="er">=</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">fifelse</span>(cpi_domain_var <span class="sc">==</span> <span class="st">"urban"</span>,</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> <span class="dv">0</span>, <span class="dv">1</span>)]</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a><span class="co"># cpi ---------------------------------------------------</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>cpi <span class="ot"><-</span> pipload<span class="sc">::</span><span class="fu">pip_load_aux</span>(<span class="st">"cpi"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Most recent version of data loaded:
'cpi.qs'</code></pre>
</div>
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>cpi_key <span class="ot"><-</span> cpi[, .(country_code,</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> cpi_year,</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> survey_year,</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> survey_acronym,</span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> cpi_domain,</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a> cpi_domain_value,</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a> cpi_data_level)] <span class="sc">|></span></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">setnames</span>(<span class="st">"cpi_data_level"</span>, <span class="st">"reporting_level"</span>)</span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a>cpi_key <span class="sc">|></span> <span class="fu">count</span>(cpi_domain_value)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> cpi_domain_value n
1: 0 36
2: 1 2247</code></pre>
</div>
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>cpi_key <span class="ot"><-</span> cpi_key[, cpi_domain <span class="sc">:</span><span class="er">=</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">fifelse</span>(cpi_domain <span class="sc">==</span> <span class="st">"National"</span>,</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> <span class="dv">1</span>, <span class="dv">2</span>)]</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a>cpi_key<span class="sc">$</span>cpi_domain <span class="ot"><-</span> <span class="fu">as.numeric</span>(cpi_key<span class="sc">$</span>cpi_domain)</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a>pfw_cpi_key <span class="ot"><-</span> cpi_key[pfw_key_options, on <span class="ot">=</span> .(country_code, survey_year,</span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a> survey_acronym, cpi_domain, cpi_domain_value)]</span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a>pfw_cpi_key <span class="ot"><-</span> pfw_cpi_key <span class="sc">|></span></span>
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(country_code, survey_year,</span>
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a> survey_acronym) <span class="sc">|></span></span>
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">year_ =</span> <span class="fu">mean</span>(year, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb10-14"><a href="#cb10-14" aria-hidden="true" tabindex="-1"></a> <span class="at">surveyid_year_ =</span> <span class="fu">mean</span>(surveyid_year, <span class="at">na.rm =</span> <span class="cn">TRUE</span>)) <span class="sc">|></span></span>
<span id="cb10-15"><a href="#cb10-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">ungroup</span>() <span class="sc">|></span> </span>
<span id="cb10-16"><a href="#cb10-16" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">year_ =</span> <span class="fu">ifelse</span>(<span class="fu">is.na</span>(year_), cpi_year, year_),</span>
<span id="cb10-17"><a href="#cb10-17" aria-hidden="true" tabindex="-1"></a> <span class="at">surveyid_year_ =</span> <span class="fu">ifelse</span>(<span class="fu">is.na</span>(surveyid_year_), cpi_year, surveyid_year_),</span>
<span id="cb10-18"><a href="#cb10-18" aria-hidden="true" tabindex="-1"></a> <span class="at">year =</span> <span class="fu">ifelse</span>(<span class="fu">is.na</span>(year), year_, year),</span>
<span id="cb10-19"><a href="#cb10-19" aria-hidden="true" tabindex="-1"></a> <span class="at">surveyid_year =</span> <span class="fu">ifelse</span>(<span class="fu">is.na</span>(surveyid_year), surveyid_year_, surveyid_year)) <span class="sc">|></span></span>
<span id="cb10-20"><a href="#cb10-20" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(country_code, survey_year, survey_acronym, reporting_level, cpi_domain) <span class="sc">|></span> <span class="fu">setDT</span>()</span>
<span id="cb10-21"><a href="#cb10-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-22"><a href="#cb10-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-23"><a href="#cb10-23" aria-hidden="true" tabindex="-1"></a><span class="fu">any</span>(<span class="fu">duplicated</span>(pfw_cpi_key, <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"country_code"</span>, <span class="st">"survey_year"</span>, <span class="st">"survey_acronym"</span>, <span class="st">"cpi_domain"</span>)))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] FALSE</code></pre>
</div>
</div>
<p>In order to merge pfw data with any of the Group two (gdp, pop, gdm, pce, <em>ppp</em>) or Group three (cpi) dataset:</p>
<ol type="1">
<li>Merge <em>pfw_cpi_key</em> data with pfw dataset</li>
<li>Rename ???_data_level variable in the other dataset to reporting_level. Where ??? could be pop, cpi, gdp, or pce depending on the type of the auxiliary file. For example:</li>
</ol>
<div class="cell">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="co"># merging pfw, cpi, pop, pce, gdp, gdm and ppp</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a><span class="co"># first, merge pfw data with pfw_cpi_key datasets</span></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a>pfw <span class="ot"><-</span> pipload<span class="sc">::</span><span class="fu">pip_load_aux</span>(<span class="st">"pfw"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Most recent version of data loaded:
'pfw.qs'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>ℹ no labels available for measure pfw</code></pre>
</div>
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>pfw <span class="ot"><-</span> pfw_cpi_key[pfw, on<span class="ot">=</span> .(country_code, survey_year,</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a> survey_acronym, cpi_domain)]</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a><span class="co"># merge pfw with cpi</span></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a>cpi <span class="ot"><-</span> pipload<span class="sc">::</span><span class="fu">pip_load_aux</span>(<span class="st">"cpi"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Most recent version of data loaded:
'cpi.qs'</code></pre>
</div>
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>cpi <span class="ot"><-</span> cpi[, <span class="sc">-</span><span class="fu">c</span>(<span class="st">"cpi_domain"</span>)] <span class="sc">|></span> <span class="co"># since it is available in pfw</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">setnames</span>(<span class="st">"cpi_data_level"</span>, <span class="st">"reporting_level"</span>)</span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a>pfw_cpi <span class="ot"><-</span> cpi[pfw, on <span class="ot">=</span> .(country_code, survey_year, survey_acronym, reporting_level)]</span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a><span class="co"># merge pfw_cpi with pop </span></span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true" tabindex="-1"></a>pop <span class="ot"><-</span> pipload<span class="sc">::</span><span class="fu">pip_load_aux</span>(<span class="st">"pop"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Most recent version of data loaded:
'pop.qs'</code></pre>
</div>
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>pop <span class="ot"><-</span> pop[, <span class="sc">-</span><span class="fu">c</span>(<span class="st">"pop_domain"</span>)] <span class="sc">|></span> <span class="co"># since it is available in pfw</span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">setnames</span>(<span class="st">"pop_data_level"</span>, <span class="st">"reporting_level"</span>)</span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a>pfw_cpi_pop <span class="ot"><-</span> pop[pfw_cpi, on <span class="ot">=</span> .(country_code, year, reporting_level)]</span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a><span class="co"># merge pfw_cpi_pop with pce</span></span>
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true" tabindex="-1"></a>pce <span class="ot"><-</span> pipload<span class="sc">::</span><span class="fu">pip_load_aux</span>(<span class="st">"pce"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Most recent version of data loaded:
'pce.qs'</code></pre>
</div>
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>pce <span class="ot"><-</span> pce[, <span class="sc">-</span><span class="fu">c</span>(<span class="st">"pce_domain"</span>)] <span class="sc">|></span> <span class="co"># since it is available in pfw</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">setnames</span>(<span class="st">"pce_data_level"</span>, <span class="st">"reporting_level"</span>)</span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a>pfw_cpi_pop_pce <span class="ot"><-</span> pce[pfw_cpi_pop, on <span class="ot">=</span> .(country_code, year, reporting_level)]</span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a><span class="co"># merge pfw_cpi_pop_pce with gdp</span></span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a>gdp <span class="ot"><-</span> pipload<span class="sc">::</span><span class="fu">pip_load_aux</span>(<span class="st">"gdp"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Most recent version of data loaded:
'gdp.qs'</code></pre>
</div>
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>gdp <span class="ot"><-</span> gdp[, <span class="sc">-</span><span class="fu">c</span>(<span class="st">"gdp_domain"</span>)] <span class="sc">|></span> <span class="co"># since it is available in pfw</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">setnames</span>(<span class="st">"gdp_data_level"</span>, <span class="st">"reporting_level"</span>)</span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a>pfw_cpi_pop_pce_gdp <span class="ot"><-</span> gdp[pfw_cpi_pop_pce, </span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a> on <span class="ot">=</span> .(country_code, year, reporting_level)]</span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true" tabindex="-1"></a><span class="co"># merge pfw_cpi_pop_pce_gdp with ppp</span></span>
<span id="cb23-9"><a href="#cb23-9" aria-hidden="true" tabindex="-1"></a><span class="co"># taking the default ppp year</span></span>
<span id="cb23-10"><a href="#cb23-10" aria-hidden="true" tabindex="-1"></a>ppp <span class="ot"><-</span> pipload<span class="sc">::</span><span class="fu">pip_load_aux</span>(<span class="st">"ppp"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Most recent version of data loaded:
'ppp.qs'</code></pre>
</div>
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a>ppp <span class="ot"><-</span> ppp[ppp_default <span class="sc">==</span> <span class="cn">TRUE</span>, .(country_code, ppp_year, ppp, ppp_data_level)] <span class="sc">|></span> </span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">setnames</span>(<span class="st">"ppp_data_level"</span>, <span class="st">"reporting_level"</span>)</span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a><span class="fu">any</span>(<span class="fu">duplicated</span>(ppp))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] FALSE</code></pre>
</div>
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a>pfw_cpi_pop_pce_gdp_ppp <span class="ot"><-</span> ppp[pfw_cpi_pop_pce_gdp, </span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a> on <span class="ot">=</span> .(country_code, reporting_level)]</span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a><span class="co">#dcast(ppp, formula = country_code + reporting_level ~ ppp_year, value.var = "ppp")</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>As demonstrated in the above example, pfw_cpi_key data is a key to merge pfw data with any of the auxiliary data files.</p>
</section>
</section>
</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const isCodeAnnotation = (el) => {
for (const clz of el.classList) {
if (clz.startsWith('code-annotation-')) {
return true;
}
}
return false;
}
const clipboard = new window.ClipboardJS('.code-copy-button', {
text: function(trigger) {
const codeEl = trigger.previousElementSibling.cloneNode(true);
for (const childEl of codeEl.children) {
if (isCodeAnnotation(childEl)) {
childEl.remove();
}
}
return codeEl.innerText;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
let selectedAnnoteEl;
const selectorForAnnotation = ( cell, annotation) => {
let cellAttr = 'data-code-cell="' + cell + '"';
let lineAttr = 'data-code-annotation="' + annotation + '"';
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
return selector;
}
const selectCodeLines = (annoteEl) => {
const doc = window.document;
const targetCell = annoteEl.getAttribute("data-target-cell");
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
const lineIds = lines.map((line) => {
return targetCell + "-" + line;
})
let top = null;
let height = null;
let parent = null;
if (lineIds.length > 0) {
//compute the position of the single el (top and bottom and make a div)
const el = window.document.getElementById(lineIds[0]);
top = el.offsetTop;
height = el.offsetHeight;
parent = el.parentElement.parentElement;
if (lineIds.length > 1) {
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
height = bottom - top;
}
if (top !== null && height !== null && parent !== null) {
// cook up a div (if necessary) and position it
let div = window.document.getElementById("code-annotation-line-highlight");
if (div === null) {
div = window.document.createElement("div");
div.setAttribute("id", "code-annotation-line-highlight");
div.style.position = 'absolute';
parent.appendChild(div);
}
div.style.top = top - 2 + "px";
div.style.height = height + 4 + "px";
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
if (gutterDiv === null) {
gutterDiv = window.document.createElement("div");
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
gutterDiv.style.position = 'absolute';
const codeCell = window.document.getElementById(targetCell);
const gutter = codeCell.querySelector('.code-annotation-gutter');
gutter.appendChild(gutterDiv);
}
gutterDiv.style.top = top - 2 + "px";
gutterDiv.style.height = height + 4 + "px";
}
selectedAnnoteEl = annoteEl;
}
};
const unselectCodeLines = () => {
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
elementsIds.forEach((elId) => {
const div = window.document.getElementById(elId);
if (div) {
div.remove();
}
});
selectedAnnoteEl = undefined;
};
// Attach click handler to the DT
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
for (const annoteDlNode of annoteDls) {
annoteDlNode.addEventListener('click', (event) => {
const clickedEl = event.target;
if (clickedEl !== selectedAnnoteEl) {
unselectCodeLines();
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
if (activeEl) {
activeEl.classList.remove('code-annotation-active');
}
selectCodeLines(clickedEl);
clickedEl.classList.add('code-annotation-active');
} else {
// Unselect the line
unselectCodeLines();
clickedEl.classList.remove('code-annotation-active');
}
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
}
});
</script>
</div> <!-- /content -->
</body></html>