Skip to content

Commit

Permalink
changing file paths and current directories
Browse files Browse the repository at this point in the history
  • Loading branch information
dedwar65 committed Feb 21, 2024
1 parent 0efe1f1 commit 76bbca0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 19 deletions.
7 changes: 6 additions & 1 deletion code/main/parse_GB_raw_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pandas as pd
import os

# Load the Excel file
excel_file = pd.ExcelFile('data/raw/GBweb_Row_Format.xlsx')
Expand Down Expand Up @@ -80,6 +81,10 @@
for column in GB_df.columns[1:]:
GB_df[column] = GB_df[column].apply(lambda x: f"{x:.{decimal}f}")

current_directory = os.path.dirname(os.path.abspath(__file__))
file_path = "/../data/output/FRED.csv"
GB_df.to_csv(current_directory + file_path)

# Uncomment these final lines to get the output of your choice
GB_df.to_csv('data/output/GB.csv')
#GB_df.to_csv('data/output/GB.csv')
# GB_df.to_excel('data/output/GB_parsed.xlsx', index=False)
7 changes: 6 additions & 1 deletion code/main/parse_SPF_raw_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pandas as pd
import os

# Load the Excel file with levels first
excel_file = pd.ExcelFile('data/raw/meanLevel.xlsx')
Expand Down Expand Up @@ -68,6 +69,10 @@
for column in results_df.columns[1:]:
results_df[column] = results_df[column].apply(lambda x: f"{x:.{decimal}f}")

current_directory = os.path.dirname(os.path.abspath(__file__))
file_path = "/../data/output/FRED.csv"
results_df.to_csv(current_directory + file_path)

# Uncomment these final lines to get the output of your choice
results_df.to_csv('data/output/SPF.csv')
# results_df.to_csv('data/output/SPF.csv')
# SPF_df.to_excel('data/output/SPF_parsed.xlsx', index=False)
14 changes: 7 additions & 7 deletions code/main/reproduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

# List all files in the current directory
files_to_run = [
"./code/main/parse_GB_raw_data.py",
"./code/main/parse_SPF_raw_data.py",
"./code/main/scrape_FRED_data.py",
"./code/main/annual_forecasts.py",
"./code/main/compute_abs_error.py",
"./code/main/abse_reg.py"
"/parse_GB_raw_data.py",
"/parse_SPF_raw_data.py",
"/scrape_FRED_data.py",
"/annual_forecasts.py",
"/compute_abs_error.py",
"/abse_reg.py"
]

# Measure the start time
Expand All @@ -22,7 +22,7 @@
# Run each Python script in the directory
for python_file in files_to_run:
if python_file != "reproduce.py": # Exclude the launcher script itself
subprocess.run(["python", python_file])
subprocess.run(["python", current_directory + python_file])

end_time = time.time()

Expand Down
7 changes: 6 additions & 1 deletion code/main/scrape_FRED_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import fredpy as fp
import matplotlib.pyplot as plt
import os

fp.api_key = "c735c085b4e162a17326871bc1d5c625"
win = ['01-01-1982','12-01-2017']
Expand Down Expand Up @@ -29,6 +30,10 @@
for column in obs_df.columns[1:]:
obs_df[column] = obs_df[column].apply(lambda x: f"{x:.{decimal}f}")

obs_df.to_csv('data/output/FRED.csv')
current_directory = os.path.dirname(os.path.abspath(__file__))
file_path = "/../data/output/FRED.csv"
obs_df.to_csv(current_directory + file_path)

#obs_df.to_csv('data/output/FRED.csv')

# obs_df.to_excel('data/output/FRED_scraped.xlsx', index=False)
2 changes: 1 addition & 1 deletion reproduce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cd "$SCPT_DIR"

ipython *.ipynb

cd code
cd code/main

python reproduce.py

Expand Down
16 changes: 8 additions & 8 deletions results/abse_reg_1983.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Regression Summary for GB_error_unemp:
Dep. Variable: GB_error_unemp R-squared: 0.013
Model: OLS Adj. R-squared: 0.006
Method: Least Squares F-statistic: 1.760
Date: Tue, 07 Nov 2023 Prob (F-statistic): 0.187
Time: 09:53:44 Log-Likelihood: -118.32
Date: Wed, 21 Feb 2024 Prob (F-statistic): 0.187
Time: 08:35:09 Log-Likelihood: -118.32
No. Observations: 144 AIC: 240.6
Df Residuals: 142 BIC: 246.6
Df Model: 1
Expand All @@ -32,8 +32,8 @@ Regression Summary for SPF_error_unemp:
Dep. Variable: SPF_error_unemp R-squared: 0.005
Model: OLS Adj. R-squared: -0.002
Method: Least Squares F-statistic: 0.6700
Date: Tue, 07 Nov 2023 Prob (F-statistic): 0.414
Time: 09:53:44 Log-Likelihood: -125.71
Date: Wed, 21 Feb 2024 Prob (F-statistic): 0.414
Time: 08:35:09 Log-Likelihood: -125.71
No. Observations: 144 AIC: 255.4
Df Residuals: 142 BIC: 261.4
Df Model: 1
Expand All @@ -60,8 +60,8 @@ Regression Summary for GB_error_cons:
Dep. Variable: GB_error_cons R-squared: 0.219
Model: OLS Adj. R-squared: 0.214
Method: Least Squares F-statistic: 30.02
Date: Tue, 07 Nov 2023 Prob (F-statistic): 1.89e-07
Time: 09:53:44 Log-Likelihood: -166.53
Date: Wed, 21 Feb 2024 Prob (F-statistic): 1.89e-07
Time: 08:35:10 Log-Likelihood: -166.53
No. Observations: 144 AIC: 337.1
Df Residuals: 142 BIC: 343.0
Df Model: 1
Expand All @@ -88,8 +88,8 @@ Regression Summary for SPF_error_cons:
Dep. Variable: SPF_error_cons R-squared: 0.133
Model: OLS Adj. R-squared: 0.127
Method: Least Squares F-statistic: 26.15
Date: Tue, 07 Nov 2023 Prob (F-statistic): 1.01e-06
Time: 09:53:44 Log-Likelihood: -177.99
Date: Wed, 21 Feb 2024 Prob (F-statistic): 1.01e-06
Time: 08:35:10 Log-Likelihood: -177.99
No. Observations: 144 AIC: 360.0
Df Residuals: 142 BIC: 365.9
Df Model: 1
Expand Down

0 comments on commit 76bbca0

Please sign in to comment.