-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path0_MasterCode.R
More file actions
132 lines (96 loc) · 5.65 KB
/
0_MasterCode.R
File metadata and controls
132 lines (96 loc) · 5.65 KB
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
# This code replicates the results in Mexico paper including tables and figures..
# Preliminaries -----------------------------------------------------------
library(readxl) #for importing data from xlsx
library(ggplot2) #for plots
library(reshape2) #for using melt() which converts data to long format convenient for ggplot
library(ggpubr) #for multiple plots in one figure using ggarrange()
library(zoo) #for na.approx
library(tvReg) #for tvvar and tvirf
library(urca) #for ur.df
library(vars) #for running VAR, IRF
library(beepr) #for beep() to make a sound after code is run
#setwd("C:/Users/sbnidhir/OneDrive - University Of Houston/Research/MP transmission/Data_Analysis")
#setwd("C:/Users/sebin/OneDrive - University Of Houston/Research/MP transmission/Data_Analysis")
setwd('../') # goes up one level to Data_Analysis folder
rm(list = ls())
# Cleaning Data -----------------------------------------------------
# Uses data from Bloomberg in MXYC_1mo30y_PLAST.xlsx (This has last price data at
# daily frequency) and creates BBYield and start_date_yield showing dates when
# data starts.
source("Mexicopaper_analysis/1_DataCreate_BByield.R")
# Uses data from Bloomberg in MXYC_1mo30y_PBAM.xlsx and creates BBLiq (daily freq)
# Liq_w (weekly frequency) which have bid-ask spreads.
source("Mexicopaper_analysis/1_DataCreate_BBLiq.R")
# Uses data from Banxico in Mex_GD_ownership.xlsx and creates Own_Data with all
# ownership data, Mex_FO with foreign ownership data. Also, has the option to
# export Mex_FO.csv. Creates start_date_Own showing dates when data starts.
source("Mexicopaper_analysis/1_DataCreate_FO.R")
# Uses data from Banxico in TIIE_daily.xlsx and MXN_USD_daily.xlsx. It creates
# TIIE and MXN from this.
source("Mexicopaper_analysis/1_DataCreate_TIIE_xrate.R")
# Uses data in EFFR.csv to create EFFR (daily data) and EFFR_w (weekly data).
# Also uses INDPRO.csv to create IIP(monthly data)
source("Mexicopaper_analysis/1_DataCreate_EFFR_IIP.R")
# Uses data from Banxico in Mex_GD_Maturity.xlsx to create Mex_mat. This is
# needed only for 1 plot
source("Mexicopaper_analysis/1_DataCreate_Mat.R")
# These various R datatables are merged and one table with necessary variables is
# created for both daily and weekly frequencies as Mex_d and Mex_w. These are also
# exported as Mex_Daily and Mex_Weekly. Weekly data is just the daily data for
# the last day of a week. This is how weekly data was generated in Bloomberg. So,
# daily data is retrieved from Bloomberg and then used to create the weekly
# frequency data.
source("Mexicopaper_analysis/1_TabCreate_SVAR.R")
# Analysis ----------------------------------------------------------------
# Using Mex_d, it creates weekday data stored in Mex_d_TV. ADF test is run on
# the 4 SVAR variables both at levels and first differences. The results are stored
# in matrix ADF_result_l for levels and ADF_result_d for first differences. Mex_d_TV
# and Mex_d_TV_diff are used in 2_TVVAR_v1.R
source("Mexicopaper_analysis/2_ADFtest.R")
# Runs aforementioned (1) ARIMAX of 10yr and 1mo yield on Proportion of FO and
# (2) a linear regression of BA spread on FO using EFFR as IV
#source("Mexicopaper_analysis/2_EFFR_IV.R") # no longer used
# Following uses EFFR and IIP as instruments.
source("Mexicopaper_analysis/2_IV_Stage1.R")
source("Mexicopaper_analysis/2_Stage2_SURE.R")
#source("Mexicopaper_analysis/2_TVVAR.R")
#source("Mexicopaper_analysis/2_TVVAR_Daily.R")
source("Mexicopaper_analysis/2_TVVAR_v1.R")
# Creating figures --------------------------------------------------------
#The figures that show just Fo in a line is not being used in slides anymore.
#source("Mexicopaper_analysis/3_Fig_FO.R") # time plot of Foreign ownership as value and share
#FO_value_plot
#FO_share_plot
source("Mexicopaper_analysis/3_Fig_Mat.R") # time plot of share of long term debt Foreign ownership as value and share
Mat_plot
source("Mexicopaper_analysis/3_Fig_OwnShare.R") # time plot of share of long term debt Foreign ownership as value and share
OwnShare_plot
source("Mexicopaper_analysis/3_CPISFigs.R")
cntry_plot
sec_plot
secShare_plot
source("Mexicopaper_analysis/3_Fig_yields.R") # time plot of yields. creates 3 plots, uses only 1 of them
Yield_plot
source("Mexicopaper_analysis/3_IRFs.R")
source("Mexicopaper_analysis/3_IVFig.R") # creates plot of IV results over time
apply(Mex_d_TV_diff[,-1], 2, sd)
plot(Mex_d_TV_diff$MPTBA)
# No longer used ----------------------------------------------------------
# Elasticity for each owner class for few yields are calculated using Own_Data,
# BBYield, TIIE and Mex_w. It returns Tab_Elast_d for daily data and Tab_Elast_w
# for weekly data
#need to adapt this for new Mex_w which has all variables
source("Mexicopaper_analysis/2_Elasticity.R")
# Runs (1) ARIMAX of 10yr and 1mo yield on Proportion of Foreign Ownership
# (2) a linear regression of BA spread on FO. Uses Mex_W. This suffers from
# endogeneity.
#source("Mexicopaper_analysis/2_ARIMAX_Liq.R")
# source("Mexicopaper_analysis/2_IVRegs_Mat_Flow.R")
# source("Mexicopaper_analysis/2_IVRegs_Joint.R")
# SVAR analysis. Uses Mex_W and Mex_d
#source("Mexicopaper_analysis/2_SVAR.R")
#source("Mexicopaper_analysis/2_SVAR_TIIE.R")
# Running SVAR on Moving horizon. This saves output to a RData file.
#source("Mexicopaper_analysis/2_SVAR_MH.R")
# OLS regressions on results from SVAR Moving Horizon
#source("Mexicopaper_analysis/2_SVAR_MH_regs.R")