Skip to content

Commit

Permalink
update tables
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlujan91 committed May 13, 2024
1 parent 7d888d5 commit 4aedb8f
Show file tree
Hide file tree
Showing 16 changed files with 15,491 additions and 108,622 deletions.
9 changes: 5 additions & 4 deletions code/estimark/scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
csv_file_path = Path(__file__).resolve().parent / ".." / "data" / "SCFdata.csv"

# Define the variables to keep
keep_vars = ["age", "age_group", "wealth_income_ratio", "weight"]
keep_vars = ["age", "age_group", "wealth_income_ratio", "weight", "wave"]

# Read the CSV file and filter data in one step
scf_data = pd.read_csv(csv_file_path)
scf_data = scf_data.loc[
scf_data_full = scf_data.loc[
(scf_data.norminc > 0.0)
& (scf_data.education == education)
& (scf_data.age > initial_age)
& (scf_data.age <= final_age_data)
& (~scf_data.age.isin(remove_ages_from_scf)),
& (scf_data.age <= final_age_data),
keep_vars,
]

scf_data = scf_data_full.loc[~scf_data.age.isin(remove_ages_from_scf)]
88 changes: 38 additions & 50 deletions code/notebooks/Portfolio.ipynb

Large diffs are not rendered by default.

332 changes: 217 additions & 115 deletions code/notebooks/SCF_notebook.ipynb

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions code/notebooks/WarmGlowPortfolio.ipynb

Large diffs are not rendered by default.

63 changes: 37 additions & 26 deletions code/notebooks/WealthPortfolio.ipynb

Large diffs are not rendered by default.

170 changes: 53 additions & 117 deletions code/notebooks/parse_tables.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -39,18 +39,7 @@
" labor = 0\n",
" stock = 0\n",
"\n",
" if \"Sub\" in file_name:\n",
" if \"(Labor)\" in file_name:\n",
" labor = 1\n",
" file_name = file_name.replace(\"(Labor)\", \"\")\n",
"\n",
" if \"(Stock)\" in file_name:\n",
" stock = 1\n",
" file_name = file_name.replace(\"(Stock)\", \"\")\n",
"\n",
" file_name = file_name.replace(\"Sub\", \"\").replace(\"Market\", \"\")\n",
" file_parameters[\"Name\"] = file_name\n",
" file_parameters[\"Stock\"] = stock\n",
"\n",
" # Iterate over each parameter we want to keep\n",
" for param in params_to_keep:\n",
Expand All @@ -64,7 +53,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 19,
"metadata": {},
"outputs": [
{
Expand All @@ -88,156 +77,103 @@
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Stock</th>\n",
" <th>Name</th>\n",
" <th>criterion</th>\n",
" <th>CRRA</th>\n",
" <th>BeqShift</th>\n",
" <th>BeqFac</th>\n",
" <th>WealthShare</th>\n",
" <th>WealthShift</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Name</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th>BeqFac</th>\n",
" <th>BeqShift</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Portfolio</th>\n",
" <td>✔️</td>\n",
" <td>18.328</td>\n",
" <td>3.476</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>Portfolio</th>\n",
" <td></td>\n",
" <th>0</th>\n",
" <td>Portfolio</td>\n",
" <td>0.895</td>\n",
" <td>6.374</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>WarmGlowPortfolio</th>\n",
" <td>✔️</td>\n",
" <td>49.567</td>\n",
" <td>2.947</td>\n",
" <td>52.462</td>\n",
" <td>45.677</td>\n",
" <td></td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>WarmGlowPortfolio</th>\n",
" <td></td>\n",
" <th>1</th>\n",
" <td>WarmGlowPortfolio</td>\n",
" <td>7.719</td>\n",
" <td>4.706</td>\n",
" <td>16.964</td>\n",
" <td>46.463</td>\n",
" <td></td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>WealthPortfolio</th>\n",
" <td>✔️</td>\n",
" <td>0.154</td>\n",
" <td>6.848</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td>0.389</td>\n",
" <td>41.345</td>\n",
" </tr>\n",
" <tr>\n",
" <th>WealthPortfolio</th>\n",
" <td></td>\n",
" <td>0.058</td>\n",
" <td>5.928</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td>0.434</td>\n",
" <td>9.396</td>\n",
" <td>46.465</td>\n",
" <td>16.966</td>\n",
" </tr>\n",
" <tr>\n",
" <th>WealthPortfolioShareOnly</th>\n",
" <td>✔️</td>\n",
" <td>0.446</td>\n",
" <td>2.000</td>\n",
" <th>2</th>\n",
" <td>WealthPortfolio</td>\n",
" <td>0.347</td>\n",
" <td>3.386</td>\n",
" <td>0.536</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td>0.574</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>WealthPortfolioShareOnly</th>\n",
" <td></td>\n",
" <td>0.346</td>\n",
" <td>3.421</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td>0.538</td>\n",
" <td></td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Stock criterion CRRA BeqShift BeqFac WealthShare \\\n",
"Name \n",
"Portfolio ✔️ 18.328 3.476 \n",
"Portfolio 0.895 6.374 \n",
"WarmGlowPortfolio ✔️ 49.567 2.947 52.462 45.677 \n",
"WarmGlowPortfolio 7.719 4.706 16.964 46.463 \n",
"WealthPortfolio ✔️ 0.154 6.848 0.389 \n",
"WealthPortfolio 0.058 5.928 0.434 \n",
"WealthPortfolioShareOnly ✔️ 0.446 2.000 0.574 \n",
"WealthPortfolioShareOnly 0.346 3.421 0.538 \n",
"\n",
" WealthShift \n",
"Name \n",
"Portfolio \n",
"Portfolio \n",
"WarmGlowPortfolio \n",
"WarmGlowPortfolio \n",
"WealthPortfolio 41.345 \n",
"WealthPortfolio 9.396 \n",
"WealthPortfolioShareOnly \n",
"WealthPortfolioShareOnly "
" Name criterion CRRA WealthShare BeqFac BeqShift\n",
"0 Portfolio 0.895 6.374 \n",
"1 WarmGlowPortfolio 7.719 4.706 46.465 16.966\n",
"2 WealthPortfolio 0.347 3.386 0.536 "
]
},
"execution_count": 3,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def format_df(df):\n",
" for col in df.columns:\n",
" if col == \"Name\":\n",
" continue\n",
" # Check if column is of float type\n",
" if col in params_to_keep:\n",
" df[col] = df[col].astype(float).round(3).fillna(\"\")\n",
" pass\n",
" # Check if column contains only 0 and 1\n",
" else:\n",
" df[col] = df[col].map({0: \"\", 1: \"✔️\"})\n",
" return df\n",
"\n",
"\n",
"df = pd.DataFrame(parameters).set_index(\"Name\")\n",
"format_df(df).sort_index()"
"# Define the order of columns\n",
"column_order = [\"Name\", \"criterion\", \"CRRA\",\n",
" \"WealthShare\", \"BeqFac\", \"BeqShift\"]\n",
"\n",
"df = pd.DataFrame(parameters)\n",
"formatted_df = format_df(df)[column_order].sort_index()\n",
"formatted_df\n",
"\n",
"\n",
"# Life cycle portfolio choice\n",
"# Bequest portfolio Choice\n",
"# TRP Life cycle portfolio choice\n",
"# leave out wealth shift"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"formatted_df.to_latex(\"../../content/tables/parameters.tex\", index=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
18 changes: 7 additions & 11 deletions code/run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@
from estimark.options import low_resource

agent_names = [
# "Portfolio",
# "WarmGlowPortfolio",
"Portfolio",
"WarmGlowPortfolio",
"WealthPortfolio",
]


# Ask the user which replication to run, and run it:
def run_replication():
for agent_name in agent_names:
for sub_stock in [0, 1]:
temp_agent_name = agent_name
if sub_stock:
temp_agent_name += "Sub(Stock)Market"

replication_specs = low_resource.copy()
replication_specs["agent_name"] = temp_agent_name
replication_specs["save_dir"] = "content/tables/TRP2"
replication_specs = low_resource.copy()
replication_specs["agent_name"] = agent_name
replication_specs["save_dir"] = "content/tables/TRP"

print("Model: ", replication_specs["agent_name"])
print("Model: ", replication_specs["agent_name"])

estimate(**replication_specs)
estimate(**replication_specs)

print("All replications complete.")

Expand Down
Loading

0 comments on commit 4aedb8f

Please sign in to comment.