You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/book/usage/simulations.md
+70-1Lines changed: 70 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -209,6 +209,75 @@ print(f"Total income tax from all people: £{total_tax:.2f}")
209
209
The column naming follows the pattern `variable_name__year` for time-varying variables. Note the double underscore `__` between the variable name and year.
210
210
```
211
211
212
+
### From entity tables with `UKSingleYearDataset` and `UKMultiYearDataset`
213
+
214
+
If your data is already split into person-, benefit-unit-, and household-level
215
+
tables, use the UK dataset classes directly:
216
+
217
+
```python
218
+
import pandas as pd
219
+
220
+
from policyengine_uk import Simulation
221
+
from policyengine_uk.data import UKMultiYearDataset, UKSingleYearDataset
222
+
223
+
person_2025 = pd.DataFrame({
224
+
"person_id": [1, 2],
225
+
"person_benunit_id": [1, 1],
226
+
"person_household_id": [1, 1],
227
+
"age": [35, 7],
228
+
"employment_income": [32_000, 0],
229
+
})
230
+
231
+
benunit_2025 = pd.DataFrame({
232
+
"benunit_id": [1],
233
+
})
234
+
235
+
household_2025 = pd.DataFrame({
236
+
"household_id": [1],
237
+
"region": ["LONDON"],
238
+
"council_tax": [1_800],
239
+
})
240
+
241
+
dataset_2025 = UKSingleYearDataset(
242
+
person=person_2025,
243
+
benunit=benunit_2025,
244
+
household=household_2025,
245
+
fiscal_year=2025,
246
+
)
247
+
248
+
sim = Simulation(dataset=dataset_2025)
249
+
print(sim.calculate("income_tax", 2025))
250
+
```
251
+
252
+
Each table should contain the ID columns needed to link entities together:
253
+
254
+
-`person`: `person_id`, `person_benunit_id`, `person_household_id`, plus any person-level variables
255
+
-`benunit`: `benunit_id`, plus any benefit-unit variables
256
+
-`household`: `household_id`, plus any household-level variables
257
+
258
+
Use `UKSingleYearDataset` when you have one cross-section and want PolicyEngine
259
+
UK to extend it forward using its standard uprating assumptions.
260
+
261
+
Use `UKMultiYearDataset` when you already have explicit tables for multiple
262
+
years and want those year-by-year values loaded as-is:
@@ -453,4 +522,4 @@ This makes it easy to trace through exactly how a reform affects different compo
453
522
- Cache simulation results when running the same calculation multiple times
454
523
```
455
524
456
-
The simulation system is designed to be flexible and powerful. Start with simple examples and gradually build up to more complex analyses as you become familiar with the structure and capabilities.
525
+
The simulation system is designed to be flexible and powerful. Start with simple examples and gradually build up to more complex analyses as you become familiar with the structure and capabilities.
0 commit comments