Hi everyone! I'm using the World Bank database to get data on real GDP (NY.GDP.MKTP.KD) and Total Consumption (NE.CON.TOTL.KD). I want to analyse business cycle synchronization among EMU countries and to do so I need to do the following:
The first point is super-easy, but I don't know how to do the second point. The only thing I managed to do is calculating the correlation among countries by using reshape wide. However, the professor told me that I should use a loop, so I'm sure this is not the correct way. ChatGPT has not been of much help so here I am, I would like to thanks in advance anyone who will try to help!
This is my code until now, you need to install the wbopendata package to run it.
The "wrong way" of doing it is:
How can I do it through a loop? Thanks!
- estimate the cyclical component of the GDP through a HP filter
- calculate the average correlation coefficient of each country’s cyclical component of real GDP with that of the other EMU countries (Italy with Germany/France/Spain/etc, France with Germany/Italy/Spain/etc)
The first point is super-easy, but I don't know how to do the second point. The only thing I managed to do is calculating the correlation among countries by using reshape wide. However, the professor told me that I should use a loop, so I'm sure this is not the correct way. ChatGPT has not been of much help so here I am, I would like to thanks in advance anyone who will try to help!
This is my code until now, you need to install the wbopendata package to run it.
Code:
clear all wbopendata, language(en - English) country() topics() indicator(NE.CON.TOTL.KD; NY.GDP.MKTP.KD) clear long format ne_con_totl_kd ny_gdp_mktp_kd %20.10f set more off egen CountryID = group(countrycode) drop if missing(ne_con_totl_kd, ny_gdp_mktp_kd) drop if regionname == "Aggregates" rename ny_gdp_mktp_kd GDP rename ne_con_totl_kd Consumption gen lnConsumption = ln(Consumption) gen lnGDP = ln(GDP) xtset CountryID year gen EMU = 0 replace EMU = 1 if inlist(CountryID, 15, 18, 100, 54, 72, 76, 78, 56, 90, 112, 117, 146, 144, 145, 160, 177, 195, 222, 223, 71) tsfilter hp cyclical_GDP=lnGDP, trend(trend_GDP) smooth(6.25) keep if EMU == 1
Code:
reshape wide cyclical_GDP countrycode countryname region regionname adminregion adminregionname incomelevel incomelevelname lendingtype lendingtypename Consumption GDP lnConsumption lnGDP EMU EU lnGDP_EMU lnGDP_nonEMU lnGDP_EU lnGDP_nonEU lnGDP_COVID19 lnGDP_nonCOVID19 time_trend GDP_int lnGDP_EMU_t lnGDP_nonEMU_t trend_GDP, i(year) j(CountryID) correlate cyclical_GDP*
Comment