#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
HỆ SINH THÁI HỌC THUẬT TNSAI — SACHKTL.TNSAI.VN & VIETLOD.TNSAI.VN
Khóa học : Khóa 3: Suy diễn nhân quả, đánh giá chính sách, kinh tế lượng không gian và sinh tồn
Buổi học : Buổi 05 — Nhóm 9.5 Sai biệt trong sai biệt lệch pha hiện đại
Bài giảng: B152 — Sai biệt trong sai biệt tổng hợp
Tên quốc tế: Synthetic Difference-in-Differences
Mã mô hình : synthetic_did
Phần mềm : Python 3.11+ — Thư viện: pysyncon
Dữ liệu   : vietlod_synthetic_did_ecodata.csv
Kiểm định : Sai số khớp tiền xử lý pre-treatment RMSE, độ tập trung trọng số hiệu dụng $N_{\text{eff}} = 1/\sum \hat{\omega}_i^2$, so sánh tam giác DID vs SC vs SDID.
"""

import os
import warnings
import numpy as np
import pandas as pd

warnings.filterwarnings("ignore")

# 1. Nạp bộ dữ liệu thực hành chuẩn hóa
DATA_FILE = "vietlod_synthetic_did_ecodata.csv"
if not os.path.exists(DATA_FILE):
    DATA_FILE = "https://sachktl.tnsai.vn/src/ecoaz/data/vietlod_synthetic_did_ecodata.csv"

df = pd.read_csv(DATA_FILE)
print(f"Kich thuoc mau thuc hanh {DATA_FILE}: {df.shape[0]} quan sat x {df.shape[1]} bien so")

# 2. Thực thi kịch bản ước lượng và kiểm định B152 — Sai biệt trong sai biệt tổng hợp
import pandas as pd
df = pd.read_csv('vietlod_synthetic_did_ecodata.csv')
print(df.describe())
# SynthDID().fit(Y_panel, N0, T0)

print("Hoan tat uoc luong mo hinh B152 (synthetic_did) tren Python 3.11+.")
