File size: 18,756 Bytes
ed7d493 | 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 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | clear
*set matsize 3000
set matsize 800
clear mata
set mem 500m
set more off
set logtype text
capture log close
*set linesize 255
// IMPORTANT!!! change working directory to the folder of this file
* cd "folder name"
// GDP current prices
clear
local folder="GDP"
insheet using "`folder'\GDP_current_prices.csv", n c case
des
tab PowerCode /* all number in millions */
tab Measure /* two types of measures - current price and ppp */
tab Transaction
keep if Measure=="Current prices"
keep Country Year Value
rename Value GDP
rename Country country
rename Year year
label var GDP "GDP current prices, Million of national currency"
save GDP, replace
// Step 1: make dataset.dta
clear
local folder="Financial balance sheets non consolidated SNA 2008"
* Total liabilities - all sectors
insheet using "`folder'\Total liabilities.csv", n c case
des
tab PowerCode /* all number in millions */
tab Measure /* two types of measures - national currency and USD */
tab Transaction
keep if Measure=="National currency, current prices"
keep Country Sector Time Value
rename Time Year
rename Value totliab
gen Sec=""
replace Sec="Total" if Sector=="Total economy"
replace Sec="World" if Sector=="Rest of the world"
replace Sec="Households" if Sector=="Households and NPISH"
replace Sec="Financials" if Sector=="Financial corporations"
replace Sec="nonFinancials" if Sector=="Non-financial corporations"
replace Sec="Gov" if Sector=="General Government"
keep if Sec~=""
keep Country Year Sec totliab
rename Country country
rename Year year
rename Sec sector
rename totliab totliab_
reshape wide totliab_, i(country year) j(sector) string
label var totliab_Total "Tota Liabilities - Total Economy"
label var totliab_World "Tota Liabilities - Rest of the World"
label var totliab_Households "Tota Liabilities - Households and NPISH"
label var totliab_Financials "Tota Liabilities - Financial corporations"
label var totliab_nonFinancials "Tota Liabilities - Non-financial corporations"
save total_liabilities, replace
//* Financial Corporations - safe liabilities
clear
insheet using "`folder'\Financial_Safe_Liabilities.csv", n c case
des
tab PowerCode /* all number in millions */
tab Measure /* two types of measures - national currency and USD */
tab Transaction
tab Sector /* only financial corporations */
keep if Measure=="National currency, current prices" & Sector=="Financial corporations"
keep Country Time Transaction Value
gen tran=""
replace tran="dep" if Transaction=="Currency and deposits"
replace tran="secur" if Transaction=="Debt securities"
replace tran="loan" if Transaction=="Loans"
replace tran="mmf" if Transaction=="Money market fund shares /units"
replace tran="trade" if Transaction=="Trade credits and advances"
drop if tran==""
keep Country Time tran Value
rename Country country
rename Time year
rename Value fin_
reshape wide fin_, i(country year) j(tran) string
label var fin_dep "Currency and deposits - Financial corporations"
label var fin_secur "Debt securities - Financial corporations"
label var fin_loan "Loans - Financial corporations"
label var fin_mmf "Money market fund shares /units - Financial corporations"
label var fin_trade "Trade credits and advances - Financial corporations"
save financials_safe_items, replace
//* General Government - safe liabilities
clear
insheet using "`folder'\Government_Safe_Liabilities.csv", n c case
des
tab PowerCode /* all number in millions */
tab Measure /* two types of measures - national currency and USD */
tab Transaction
tab Sector /* only general government */
keep if Measure=="National currency, current prices" & Sector=="General Government"
keep Country Time Transaction Value
gen tran=""
replace tran="dep" if Transaction=="Currency and deposits"
replace tran="secur" if Transaction=="Debt securities"
replace tran="loan" if Transaction=="Loans"
replace tran="mmf" if Transaction=="Money market fund shares /units"
replace tran="trade" if Transaction=="Trade credits and advances"
drop if tran==""
keep Country Time tran Value
rename Country country
rename Time year
rename Value gov_
reshape wide gov_, i(country year) j(tran) string
label var gov_dep "Currency and deposits - General Government"
label var gov_secur "Debt securities - General Government"
label var gov_loan "Loans - General Government"
label var gov_mmf "Money market fund shares /units - General Government"
label var gov_trade "Trade credits and advances - General Government"
save government_safe_items, replace
//* Central bank holdings of bonds (assume most of these holdings are government bonds)
clear
insheet using "`folder'\CentralBank_gov_bonds.csv", n c case
des
tab PowerCode /* all number in millions */
tab Measure /* two types of measures - national currency and USD */
tab Transaction
tab Sector /* only general government */
keep if Measure=="National currency, current prices" & Sector=="Central Bank"
keep Country Time Transaction Value
gen tran=""
replace tran="lbond" if Transaction=="Long-term debt securities"
replace tran="sbond" if Transaction=="Short-term debt securities"
drop if tran==""
keep Country Time tran Value
rename Country country
rename Time year
rename Value cb_
reshape wide cb_, i(country year) j(tran) string
save central_bank_bonds, replace
//* Central bank - safe and total liabilities
clear
insheet using "`folder'\CentralBank_liabilities.csv", n c case
des
tab PowerCode /* all number in millions */
tab Measure /* two types of measures - national currency and USD */
tab Transaction
tab Sector /* only Central Bank */
keep if Measure=="National currency, current prices" & Sector=="Central Bank"
keep Country Time Transaction Value
gen tran=""
replace tran="dep" if Transaction=="Currency and deposits"
replace tran="secur" if Transaction=="Debt securities"
replace tran="loan" if Transaction=="Loans"
replace tran="mmf" if Transaction=="Money market fund shares /units"
replace tran="trade" if Transaction=="Trade credits and advances"
replace tran="totliab_Total" if Transaction=="Financial liabilities"
drop if tran==""
keep Country Time tran Value
rename Country country
rename Time year
rename Value cb_
reshape wide cb_, i(country year) j(tran) string
label var cb_dep "Currency and deposits - Central Bank"
label var cb_secur "Debt securities - Central Bank"
label var cb_loan "Loans - Central Bank"
label var cb_mmf "Money market fund shares /units - Central Bank"
label var cb_trade "Trade credits and advances - Central Bank"
label var cb_totliab_Total "Financial liabilities - Central Bank"
save cb_safe_items, replace
clear
use total_liabilities, replace
joinby country year using financials_safe_items, unmatched(both)
cap drop _merge
joinby country year using government_safe_items, unmatched(both)
cap drop _merge
joinby country year using central_bank_bonds, unmatched(both)
cap drop _merge
joinby country year using GDP, unmatched(master)
cap drop _merge
joinby country year using cb_safe_items, unmatched(master)
cap drop _merge
* replace missing values with zeros
foreach var of varlist fin_* gov_* cb_* {
replace `var'=0 if `var'==.
}
label var cb_lbond "Long-term debt securities held by the central bank"
label var cb_sbond "Short-term debt securities held by the central bank"
encode country, gen(countrys)
drop country
rename countrys country
tsset country year
save dataset, replace
//* Compute variables in USD
* Total liabilities - all sectors
clear
insheet using "`folder'\Total liabilities.csv", n c case
des
tab PowerCode /* all number in millions */
tab Measure /* two types of measures - national currency and USD */
tab Transaction
*keep if Measure=="National currency, current prices"
keep if Measure=="US $, current prices, current exchange rates, end of period"
keep Country Sector Time Value
rename Time Year
rename Value totliab
gen Sec=""
replace Sec="Total" if Sector=="Total economy"
replace Sec="World" if Sector=="Rest of the world"
replace Sec="Households" if Sector=="Households and NPISH"
replace Sec="Financials" if Sector=="Financial corporations"
replace Sec="nonFinancials" if Sector=="Non-financial corporations"
replace Sec="Gov" if Sector=="General Government"
keep if Sec~=""
keep Country Year Sec totliab
rename Country country
rename Year year
rename Sec sector
rename totliab totliab_
reshape wide totliab_, i(country year) j(sector) string
label var totliab_Total "Tota Liabilities - Total Economy"
label var totliab_World "Tota Liabilities - Rest of the World"
label var totliab_Households "Tota Liabilities - Households and NPISH"
label var totliab_Financials "Tota Liabilities - Financial corporations"
label var totliab_nonFinancials "Tota Liabilities - Non-financial corporations"
save total_liabilitiesUSD, replace
*/
//* Financial Corporations - safe liabilities
clear
insheet using "`folder'\Financial_Safe_Liabilities.csv", n c case
des
tab PowerCode /* all number in millions */
tab Measure /* two types of measures - national currency and USD */
tab Transaction
tab Sector /* only financial corporations */
*keep if Measure=="National currency, current prices" & Sector=="Financial corporations"
keep if Measure=="US $, current prices, current exchange rates, end of period"
keep Country Time Transaction Value
gen tran=""
replace tran="dep" if Transaction=="Currency and deposits"
replace tran="secur" if Transaction=="Debt securities"
replace tran="loan" if Transaction=="Loans"
replace tran="mmf" if Transaction=="Money market fund shares /units"
replace tran="trade" if Transaction=="Trade credits and advances"
drop if tran==""
keep Country Time tran Value
rename Country country
rename Time year
rename Value fin_
reshape wide fin_, i(country year) j(tran) string
label var fin_dep "Currency and deposits - Financial corporations"
label var fin_secur "Debt securities - Financial corporations"
label var fin_loan "Loans - Financial corporations"
label var fin_mmf "Money market fund shares /units - Financial corporations"
label var fin_trade "Trade credits and advances - Financial corporations"
save financials_safe_itemsUSD, replace
//* General Government - safe liabilities
clear
insheet using "`folder'\Government_Safe_Liabilities.csv", n c case
des
tab PowerCode /* all number in millions */
tab Measure /* two types of measures - national currency and USD */
tab Transaction
tab Sector /* only general government */
*keep if Measure=="National currency, current prices" & Sector=="General Government"
keep if Measure=="US $, current prices, current exchange rates, end of period"
keep Country Time Transaction Value
gen tran=""
replace tran="dep" if Transaction=="Currency and deposits"
replace tran="secur" if Transaction=="Debt securities"
replace tran="loan" if Transaction=="Loans"
replace tran="mmf" if Transaction=="Money market fund shares /units"
replace tran="trade" if Transaction=="Trade credits and advances"
drop if tran==""
keep Country Time tran Value
rename Country country
rename Time year
rename Value gov_
reshape wide gov_, i(country year) j(tran) string
label var gov_dep "Currency and deposits - General Government"
label var gov_secur "Debt securities - General Government"
label var gov_loan "Loans - General Government"
label var gov_mmf "Money market fund shares /units - General Government"
label var gov_trade "Trade credits and advances - General Government"
save government_safe_itemsUSD, replace
//* Central bank holdings of bonds (assume most of these holdings are government bonds)
clear
insheet using "`folder'\CentralBank_gov_bonds.csv", n c case
des
tab PowerCode /* all number in millions */
tab Measure /* two types of measures - national currency and USD */
tab Transaction
tab Sector /* only general government */
*keep if Measure=="National currency, current prices" & Sector=="Central Bank"
keep if Measure=="US $, current prices, current exchange rates, end of period"
keep Country Time Transaction Value
gen tran=""
replace tran="lbond" if Transaction=="Long-term debt securities"
replace tran="sbond" if Transaction=="Short-term debt securities"
drop if tran==""
keep Country Time tran Value
rename Country country
rename Time year
rename Value cb_
reshape wide cb_, i(country year) j(tran) string
save central_bank_bondsUSD, replace
//* Central bank - safe and total liabilities
clear
insheet using "`folder'\CentralBank_liabilities.csv", n c case
des
tab PowerCode /* all number in millions */
tab Measure /* two types of measures - national currency and USD */
tab Transaction
tab Sector /* only Central Bank */
*keep if Measure=="National currency, current prices" & Sector=="Central Bank"
keep if Measure=="US $, current prices, current exchange rates, end of period"
keep Country Time Transaction Value
gen tran=""
replace tran="dep" if Transaction=="Currency and deposits"
replace tran="secur" if Transaction=="Debt securities"
replace tran="loan" if Transaction=="Loans"
replace tran="mmf" if Transaction=="Money market fund shares /units"
replace tran="trade" if Transaction=="Trade credits and advances"
replace tran="totliab_Total" if Transaction=="Financial liabilities"
drop if tran==""
keep Country Time tran Value
rename Country country
rename Time year
rename Value cb_
reshape wide cb_, i(country year) j(tran) string
label var cb_dep "Currency and deposits - Central Bank"
label var cb_secur "Debt securities - Central Bank"
label var cb_loan "Loans - Central Bank"
label var cb_mmf "Money market fund shares /units - Central Bank"
label var cb_trade "Trade credits and advances - Central Bank"
label var cb_totliab_Total "Financial liabilities - Central Bank"
save cb_safe_itemsUSD, replace
***
clear
use total_liabilitiesUSD, replace
joinby country year using financials_safe_itemsUSD, unmatched(both)
cap drop _merge
joinby country year using government_safe_itemsUSD, unmatched(both)
cap drop _merge
joinby country year using central_bank_bondsUSD, unmatched(both)
cap drop _merge
joinby country year using cb_safe_itemsUSD, unmatched(both)
cap drop _merge
* replace missing values with zeros
foreach var of varlist fin_* gov_* cb_* {
replace `var'=0 if `var'==.
}
label var cb_lbond "Long-term debt securities held by the central bank"
label var cb_sbond "Short-term debt securities held by the central bank"
encode country, gen(countrys)
drop country
rename countrys country
tsset country year
save datasetUSD, replace
*** do USD aggregates
use datasetUSD, clear
gen fin_safeUSD=fin_dep+fin_loan+fin_mmf+fin_secur // remove trade credit and advances - it's a small part of financial debt and seems unrelated
gen cb_safeUSD=cb_dep+cb_loan+cb_mmf+cb_secur // remove trade credit and advances - it's a small part of financial debt and seems unrelated
gen gov_safeUSD=gov_dep+gov_loan+gov_mmf+gov_secur // remove trade credit and advnaces
rename totliab_Total totliab_TotalUSD
keep country year fin_safeUSD gov_safeUSD cb_safeUSD totliab_TotalUSD
sort country year
tsset country year
save safeUSD, replace
// Make world table
use safeUSD, clear
gen tempvar=fin_safeUSD+gov_safeUSD+totliab_TotalUSD
bysort country: egen minyear=min(year) if tempvar<.
bysort country: egen maxyear=max(year) if tempvar<.
keep if minyear<=1995
keep if year>=1995
keep if maxyear>=2017
keep if year<=2017
sort country year
tsset country year // panel is balanced
if r(balanced)!="strongly balanced" {
di "WARNING!!!! panel is not balanced"
}
preserve
keep if year==2017
keep country
gen OECD=1
save OECD, replace
restore
decode country, g(country_name)
bysort year: egen fin_safeWorld=total(fin_safeUSD)
bysort year: egen gov_safeWorld=total(gov_safeUSD)
bysort year: egen new_totalWorld=total(totliab_TotalUSD)
bysort year: egen cb_safeWorld=total(cb_safeUSD)
gen fin_shareWorld=fin_safeWorld/new_totalWorld
gen gov_shareWorld=gov_safeWorld/new_totalWorld
gen shareWorld=fin_shareWorld+gov_shareWorld
gen cb_shareWorld=cb_safeWorld/new_totalWorld
bysort year: egen fin_safeNonUS=total(fin_safeUSD) if country_name!="United States"
bysort year: egen gov_safeNonUS=total(gov_safeUSD) if country_name!="United States"
bysort year: egen new_totalNonUS=total(totliab_TotalUSD) if country_name!="United States"
bysort year: egen cb_safeNonUS=total(cb_safeUSD) if country_name!="United States"
gen fin_shareNonUS=fin_safeNonUS/new_totalNonUS
gen gov_shareNonUS=gov_safeNonUS/new_totalNonUS
gen shareNonUS=fin_shareNonUS+gov_shareNonUS
gen cb_shareNonUS=cb_safeNonUS/new_totalNonUS
sort country year
keep if country==country[1]
keep fin_shareWorld gov_shareWorld shareWorld cb_shareWorld fin_shareNonUS gov_shareNonUS shareNonUS cb_shareNonUS year
keep year fin_shareWorld gov_shareWorld shareWorld cb_shareWorld fin_shareNonUS gov_shareNonUS shareNonUS cb_shareNonUS
save World, replace
// Make final dataset
use dataset // non-consolidated data
joinby country year using safeUSD, unmatched(both)
cap drop _merge
joinby year using World, unmatched(both)
cap drop _merge
joinby country using OECD, unmatched(both)
cap drop _merge
cap drop fin_safe
cap drop cb_safe
label var gov_safeUSD "government safe liabilities in USD"
label var fin_shareWorld "financial liabilities (as share of total assets) for the whole world"
label var gov_shareWorld "government liabilities (as share of total assets) for the whole world"
label var cb_shareWorld "central bank liabilities (as share of total assets) for the whole world"
label var shareWorld "safe liabilities (as share of total assets) for the whole world"
label var fin_shareNonUS "financial liabilities (as share of total assets) for non-US sample"
label var gov_shareNonUS "government liabilities (as share of total assets) for non-US sample"
label var cb_shareNonUS "central bank liabilities (as share of total assets) for non-US sample"
label var shareNonUS "safe liabilities (as share of total assets) for non-US sample"
label var totliab_Gov "Tota Liabilities - Government"
label var OECD "dummy for OECD countries"
save OECD_data, replace
|