Skip to content

Commit

Permalink
Fixed read me
Browse files Browse the repository at this point in the history
  • Loading branch information
mivanicERS committed Feb 1, 2025
1 parent 5651db2 commit 0dec0f1
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,49 +91,53 @@ endMap["capital"] = "capital"
```

# Generating starting values
# Generating initial model

```
# Starting data and parameters
(; sets, parameters, data, fixed) = generate_starting_values(hSets=hSets, hData=hData, hParameters=hParameters)
start_data = deepcopy(data)
# Starting model (a container with model, data, parameters, fixed value indicators, lower bounds, upper bounds)
mc=generate_initial_model(hSets=hSets, hData=hData, hParameters=hParameters)
# Save the initial data because it contains actual values to which we can calibrate later
start_data = deepcopy(mc.data)
```

# Solve the model with the starting (uncalibrated) data values

```
(; data) = model(sets=sets, data=start_data, parameters=parameters, fixed=fixed, max_iter=30, constr_viol_tol = 1e-8)
solved_data = deepcopy(data)
run_model!(mc)
```


# Calibrate the data and parameters

```
calibrated_data = calibrate(start_data = start_data, data=solved_data, sets=sets, parameters=parameters, fixed=fixed)
```
# Obtain the closure for calibration (fixed_calibration) and data with target values (start_data)
(;fixed_calibration, data_calibration)=generate_calibration_inputs(mc, start_data)
# Before calibrating, let's save the standard closure as we will need it for simulations
fixed_default = deepcopy(mc.fixed)
# Running baseline scenario (the world before the shock)
# Load the model with the calibration data and closure
mc.data = data_calibration
mc.fixed = fixed_calibration
```
(; data) = solve_model(sets=sets, data=calibrated_data, parameters=parameters, fixed=fixed, max_iter = 20)
# Calibrate
run_model!(mc)
# Let's save the state of the world before the simulation
data0 = deepcopy(data)
# Save the calibrate data---this is the starting point for all simulations
calibrated_data = deepcopy(mc.data)
```

# Running the scenario (the world after the shock)


# Running a scenario (increase power of tariff on crops between MENA and EU by 20 percent)

```
# Set the tariff on crops from ssafrica to eu to 1.2 (20 percent)
calibrated_data["tms"]["crops", "mena", "eu"] = 1.2
mc.data["tms"]["crops", "mena", "eu"] = 1.2
# Run the model
(; data) = solve_model(sets=sets, data=calibrated_data, parameters=parameters, fixed=fixed, max_iter=20)
run_model!(mc)
# Save the world after the simulation
data1 = deepcopy(data)
```

# Analyzing the results
Expand All @@ -142,7 +146,7 @@ data1 = deepcopy(data)

```
# Show the change in exports (percent)
((data1["qxs"]./data0["qxs"])[:, :, "eu"] .- 1) .* 100
((mc.data["qxs"]./calibrated_data["qxs"])[:, :, "eu"] .- 1) .* 100
```

Expand All @@ -152,15 +156,15 @@ data1 = deepcopy(data)
ev = calculate_ev(
sets=sets,
data0=calibrated_data,
data1=data,
data1=mc.data,
parameters=parameters
)
```

## Calculate change in real GDP

```
qgdp1 = calculate_gdp(sets =sets, data0=calibrated_data, data1=data)
qgdp0 = calculate_gdp(sets =sets, data0=calibrated_data, data1=calibrated_data)
qgdp1 = calculate_gdp(sets =mc.sets, data0=calibrated_data, data1=mc.data)
qgdp0 = calculate_gdp(sets =mc.sets, data0=calibrated_data, data1=calibrated_data)
(qgdp1 ./ qgdp1 .- 1) .* 100
```

0 comments on commit 0dec0f1

Please sign in to comment.