Download the notebook here
!
Interactive online version:
[1]:
import yaml
import sys
import os
import pandas as pd
import respy as rp
sys.path.insert(0, "python")
from auxiliary import plot_average_wages_over_time # noqa: E402
from auxiliary import plot_choice_probabilities # noqa: E402
from auxiliary import plot_distibution_wages # noqa: E402
Robinson Crusoe economy
The respy
package provides several example models that can be used to explore selected issues in the structural microeconometrics. We focus on the robinson
example, which allows for quick iterations. All example models share the same interface so they can be easily swapped in and out of any analysis.
[2]:
options_base = yaml.safe_load(open(os.environ["ROBINSON_SPEC"] + "/robinson.yaml", "r"))
params_base = pd.read_csv(open(os.environ["ROBINSON_SPEC"] + "/robinson.csv", "r"))
params_base.set_index(["category", "name"], inplace=True)
Let’s look at the parameterization of the model, the specified options and a simulated dataset.
[3]:
params_base
[3]:
value | ||
---|---|---|
category | name | |
delta | delta | 0.950 |
wage_fishing | exp_fishing | 0.070 |
nonpec_fishing | constant | -0.100 |
nonpec_hammock | constant | 1.046 |
shocks_sdcorr | sd_fishing | 0.010 |
sd_hammock | 0.010 | |
corr_hammock_fishing | 0.000 |
[4]:
options_base
[4]:
{'estimation_draws': 100,
'estimation_seed': 100,
'estimation_tau': 0.001,
'interpolation_points': -1,
'n_periods': 5,
'simulation_agents': 1000,
'simulation_seed': 132,
'solution_draws': 100,
'solution_seed': 456,
'covariates': {'constant': '1'}}
Now we are ready to simulate a sample.
[5]:
simulate = rp.get_simulate_func(params_base, options_base)
df = simulate(params_base)
We first look at the general structure of the data.
[6]:
df.head()
[6]:
Experience_Fishing | Shock_Reward_Fishing | Meas_Error_Wage_Fishing | Shock_Reward_Hammock | Meas_Error_Wage_Hammock | Choice | Wage | Discount_Rate | Present_Bias | Nonpecuniary_Reward_Fishing | Wage_Fishing | Flow_Utility_Fishing | Value_Function_Fishing | Continuation_Value_Fishing | Nonpecuniary_Reward_Hammock | Wage_Hammock | Flow_Utility_Hammock | Value_Function_Hammock | Continuation_Value_Hammock | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Identifier | Period | |||||||||||||||||||
0 | 0 | 0 | 1.007197 | 1 | 0.010305 | 1 | fishing | 1.007197 | 0.95 | 1 | -0.1 | 1.007197 | 0.907197 | 4.747606 | 4.042536 | 1.046 | NaN | 1.056305 | 4.742931 | 3.880659 |
1 | 1 | 0.981015 | 1 | 0.010596 | 1 | fishing | 1.052147 | 0.95 | 1 | -0.1 | 1.052147 | 0.952147 | 4.022193 | 3.231627 | 1.046 | NaN | 1.056596 | 3.903085 | 2.996304 | |
2 | 2 | 0.998980 | 1 | -0.003797 | 1 | fishing | 1.149101 | 0.95 | 1 | -0.1 | 1.149101 | 1.049101 | 3.230306 | 2.296006 | 1.046 | NaN | 1.042203 | 3.063422 | 2.127598 | |
3 | 3 | 0.989253 | 1 | -0.011702 | 1 | fishing | 1.220419 | 0.95 | 1 | -0.1 | 1.220419 | 1.120419 | 2.282845 | 1.223607 | 1.046 | NaN | 1.034298 | 2.111715 | 1.134123 | |
4 | 4 | 1.010431 | 1 | -0.002176 | 1 | fishing | 1.336932 | 0.95 | 1 | -0.1 | 1.336932 | 1.236932 | 1.236932 | 0.000000 | 1.046 | NaN | 1.043824 | 1.043824 | 0.000000 |
We can study the resulting choice patterns.
[7]:
plot_choice_probabilities(df)
We can look at the distirbution of wages.
[8]:
plot_distibution_wages(df)
We can look at average wages over time.
[9]:
plot_average_wages_over_time(df)