From 1472642d70b9688ea511e7416157264c7a2dfe95 Mon Sep 17 00:00:00 2001 From: SeaCelo Date: Tue, 7 May 2024 13:41:47 -0400 Subject: [PATCH] Update macro_params.py Changed the source of labor share of income (gamma) to ILOSTAT. This gets us the latest year available (currently 2021). Removed FRED as a source because it only gives us up to 2019. --- ogzaf/macro_params.py | 80 +++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/ogzaf/macro_params.py b/ogzaf/macro_params.py index dec1a50..b22428f 100644 --- a/ogzaf/macro_params.py +++ b/ogzaf/macro_params.py @@ -83,34 +83,32 @@ def get_macro_params(): wb_data_q = wb_data_q.set_index("year") """ - This retrieves labour share data from the United Nations Data Portal API - (see https://data.un.org) + This retrieves labour share data from the ILOSTAT Data API + (see https://rshiny.ilo.org/dataexplorer9/?lang=en) """ - # target = ( - # "https://data.un.org/ws/rest/data/IAEG-SDGs,DF_SDG_GLH/" - # + "..SL_EMP_GTOTL.710..........." - # + "?startPeriod=" - # + str(start.year) - # + "&" - # + "endPeriod=" - # + str(end.year) - # + "&format=csv" - # ) - - # response = get_legacy_session().get(target) - # print("TaRGET = ", target) + target = ( + "https://rplumber.ilo.org/data/indicator/" + + "?id=LAP_2GDP_NOC_RT_A" + + "&ref_area=" + + str(country_iso) + + "&timefrom=" + + str(start.year) + + "&timeto=" + + str(end.year) + + "&type=both&format=.csv" + ) - # # Check if the request was successful before processing - # if response.status_code == 200: - # csv_content = StringIO(response.text) - # df_temp = pd.read_csv(csv_content) - # else: - # print( - # f"Failed to retrieve data. HTTP status code: {response.status_code}" - # ) + response = requests.get(target) + if response.status_code == 200: + csv_content = StringIO(response.text) + df_temp = pd.read_csv(csv_content) + else: + print( + f"Failed to retrieve data. HTTP status code: {response.status_code}" + ) - # un_data_a = df_temp[["TIME_PERIOD", "OBS_VALUE"]] + ilo_data = df_temp[["time", "obs_value"]] """ This retrieves data from FRED. @@ -127,11 +125,11 @@ def get_macro_params(): } # pull series of interest using pandas_datareader - fred_data = web.DataReader(fred_variable_dict.values(), "fred", start, end) - fred_data.rename( - columns=dict((y, x) for x, y in fred_variable_dict.items()), - inplace=True, - ) + # fred_data = web.DataReader(fred_variable_dict.values(), "fred", start, end) + # fred_data.rename( + # columns=dict((y, x) for x, y in fred_variable_dict.items()), + # inplace=True, + # ) # Separate quartely, monthly, and annual FRED dataseries @@ -195,19 +193,19 @@ def get_macro_params(): # find gamma macro_parameters["gamma"] = [ - # 1 - # - ( - # ( - # un_data_a.loc[ - # un_data_a["TIME_PERIOD"] == baseline_date.year, "OBS_VALUE" - # ].squeeze() - # ) - # / 100 - # ) 1 - - pd.Series( - (fred_data["Labor share of income"]).loc[baseline_yearquarter] - ).mean() + - ( + ( + ilo_data.loc[ + ilo_data["time"] == baseline_date.year, "obs_value" + ].squeeze() + ) + / 100 + ) + # 1 + # - pd.Series( + # (fred_data["Labor share of income"]).loc[baseline_yearquarter] + # ).mean() ] # find g_y