Answering it
Last updated
This is the analysis itself: the measures from your plan, computed carefully, with the comparisons that give them meaning and the uncertainty that says how far to trust them. In this lesson you'll compute the measures, put prices in real pesos and compare each month with a year earlier, compare places fairly, attach an interval or a test to each claim, and ask what else could explain what you found.
By the end of this lesson you can
- Compute the planned measures with the right comparisons
- Use real pesos, year-on-year changes and decomposition where the question needs them
- Attach uncertainty to each claim, and consider confounders
The measures
Open 05-answer.ipynb. Compute each measure in your plan (C.1) exactly as you defined it, and print it before charting it. If computing it shows the definition was unclear (what counts as "hit hardest"?), fix the definition in the plan first, with the date and the reason, then compute.
For the rice question, the measures need two preparations from Stage 9: real pesos (9.5), using the PSA's regional CPI so each region is deflated by its own prices, and the change on the same month last year (9.6), so the season doesn't pass for a trend:
import pandas as pd rice = pd.read_csv("data/clean/rice.csv", parse_dates=["month"]) cpi = pd.read_csv("data/clean/cpi_regions.csv", parse_dates=["month"]) # region, month, cpi rice = rice.merge(cpi, on=["psgc", "month"], how="left", validate="many_to_one") assert rice["cpi"].notna().all(), "months or regions without a CPI" base = rice["month"].max() base_cpi = cpi[cpi["month"] == base].set_index("psgc")["cpi"] rice["real_price"] = rice["price"] * rice["psgc"].map(base_cpi) / rice["cpi"] rice = rice.sort_values("month") rice["yoy_%"] = 100 * rice.groupby(["psgc", "rice"])["real_price"].pct_change(12)
Get the regional CPI from OpenSTAT, clean it with the same script pattern as C.3, and put its source on its own card. Use a CPI series with the same base year throughout; if the PSA rebased it during your years, use the series that covers them all, or link the two and say so in the cleaning log.
Over time
The time questions, in order:
- What's the trend? Decompose the national average, and a few regions, with STL (9.6). Is the trend in real pesos rising, falling, or flat?
- Is there a season? Rice prices often follow the harvest; rainfall certainly does; enrolment has its own calendar. Name the months.
- When did things change? Mark the months where the year-on-year change turned, and look for what happened then: a policy, a harvest, a typhoon, a price shock abroad. Write down where each explanation comes from: a news report or an official release, with its date.
- For the rain question: compare decades, not years, and look at extremes (the wettest day of each year, the number of days over a threshold) as well as totals. One wet year proves nothing.
Across places
Comparing regions fairly uses Stage 9's tools:
national = rice.groupby(["rice", "month"])["real_price"].transform("mean") rice["gap"] = rice["real_price"] - national # which regions are dearest, on average, in the last 12 months? recent = rice[rice["month"] > base - pd.DateOffset(months=12)] recent.groupby(["rice", "region"])["gap"].mean().round(2).sort_values()
- Gaps, not levels: each region's real price minus the national average for the same rice and month. A region can be dear and getting cheaper.
- Rates, not totals, wherever sizes differ (9.4): pupils per classroom or per teacher, not pupils; enrolment per 1,000 school-age children, using PSA population.
- Small places vary more (9.8): with few markets or few schools behind a number, a region's figure swings by chance. Use a funnel plot when counts are involved.
- One code per place (5.8): join on PSGC codes, and watch for regions that split or were created during your years.
How sure, and what else
Every claim in the report will need its size, its comparison, and how sure you are. Go through each one with this list before calling the analysis done:
On other explanations: price data from markets, rain from one station, and enrolment from school reports are all observational (8.11). A rise after a policy is not proof the policy caused it; something else may have changed the same month. List the alternatives, check any the data can check (did the rise also happen where the policy didn't apply?), and put the rest in the limitations.
Here's how the reference analysis of the rice question does it. rice/answer.py compares each region's real price in 2022, the last full year before prices rose, with the latest twelve months. Then it measures the change from each of those twelve months on its own, to see how much the answer depends on which month you pick:
Real price of well-milled rice, by region (2018 pesos a kilo)
2022 latest 12 months change % lowest month % highest month %
region
Davao Region 36.7 42.1 14.9 12.0 22.5
SOCCSKSARGEN 34.6 39.6 14.2 9.4 23.8
Northern Mindanao 36.5 41.1 12.6 3.8 20.1
Caraga 36.7 40.6 10.6 -0.4 15.9
Eastern Visayas 38.7 42.5 10.0 2.5 13.7
Western Visayas 36.8 40.1 9.2 0.9 13.8
Ilocos Region 35.1 38.1 8.5 -7.3 15.4
Negros Island Region 37.6 40.7 8.2 1.9 14.5
Bicol Region 35.2 38.0 7.9 -5.3 15.0
Zamboanga Peninsula 38.3 41.3 7.7 -0.0 12.4
Philippines 37.8 40.4 6.9 -1.8 12.5
NCR 38.4 40.1 4.4 -1.7 9.7
MIMAROPA 36.6 38.0 4.0 -6.5 11.4
BARMM 40.8 42.4 4.0 -1.8 5.9
CALABARZON 37.4 38.7 3.5 -3.1 9.8
Cagayan Valley 38.0 39.3 3.3 -13.4 11.0
CAR 37.8 38.9 2.9 -1.6 6.3
Central Visayas 44.3 44.8 1.1 -2.6 8.4
Central Luzon 37.7 38.0 0.8 -8.5 8.0Read it the way a reader of the report would:
- The size: nationally, the real price is 6.9% above 2022. The shop price rose much more (from ₱43.58 a kilo on average in 2022 to ₱55.16 so far in 2026), but most of that rise is inflation, and in 2018 pesos rice is still cheaper than it was in 2018.
- The places: the biggest rises are in Mindanao, led by Davao Region (14.9%) and SOCCSKSARGEN (14.2%), and the same regions lead for regular-milled rice. Central Luzon barely moved (0.8%).
- How sure: the month-by-month range is wide. Davao Region's change is 12.0% at its lowest month and 22.5% at its highest, so it clearly rose. But the regions in the middle of the table overlap, and their order means little. Report the ends of the ranking, not every place in it.
Check what you learned
Sources
Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.
- Philippine Statistics Authority: Consumer Price Index and inflation rate: the CPI by region, for real pesos
- statsmodels: statsmodels.tsa.seasonal.STL: decomposing a monthly series
- Hyndman and Athanasopoulos, Forecasting: Principles and Practice, 3rd ed., chapter 3: time series components
- Diez, Çetinkaya-Rundel and Barr, OpenIntro Statistics, 4th ed.: intervals, tests and regression