# Official Data Observatory
# Official Data - Data structures, trends, and evidence
# Dataset: Official economic indicator

# Official Data Observatory
#
# Load an official indicator exported by Ceteris Lab, plot the time series, calculate growth rates, and write a short limitation note.

# %% Cell 2
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("official-data.csv")
df.head()

# %% Cell 3
df["date"] = pd.to_datetime(df["date"], errors="coerce")
df = df.dropna(subset=["date", "value"]).sort_values("date")

ax = df.plot(x="date", y="value", legend=False, figsize=(8, 4), title=df["indicator"].iloc[0])
ax.set_xlabel("Date")
ax.set_ylabel(df["unit"].iloc[0])
plt.tight_layout()
plt.show()

# %% Cell 4
df["growth_rate"] = df["value"].pct_change() * 100
df[["date", "value", "growth_rate"]].tail(10)

# Trend and limitations
#
# - What long-run pattern do you see?
# - Are there breaks, recessions, or unusual years?
# - What would be risky to infer from this series alone?
# - Which econometrics lesson does this connect to: data structures, simple regression, multiple regression, inference, or asymptotics?
