#!/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 1: Kinh tế lượng nền tảng và mô hình dữ liệu chéo thực nghiệm
Buổi học : Buổi 13 — Nhóm 5.1 Dữ liệu bảng tĩnh
Bài giảng: B064 — Sai số chuẩn bền vững không gian–thời gian Driscoll–Kraay
Tên quốc tế: Driscoll–Kraay Spatial-Temporal SCC Panel
Mã mô hình : driscoll_kraay_fe
Phần mềm : Python 3.11+ — Thư viện: linearmodels
Dữ liệu   : vietlod_driscoll_kraay_fe_ecodata.csv
Kiểm định : Kiểm định Pesaran CD, Wooldridge panel autocorrelation, within-$R^2$, độ rộng băng thông Bartlett tự động $m = \lfloor 4^{2/9} \rfloor$.
"""

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_driscoll_kraay_fe_ecodata.csv"
if not os.path.exists(DATA_FILE):
    DATA_FILE = "https://sachktl.tnsai.vn/src/ecoaz/data/vietlod_driscoll_kraay_fe_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 B064 — Sai số chuẩn bền vững không gian–thời gian Driscoll–Kraay
import pandas as pd
df = pd.read_csv('vietlod_driscoll_kraay_fe_ecodata.csv')
print(df.describe())
# PanelOLS.from_formula('y ~ 1 + x1 + x2 + EntityEffects', data=pdata).fit(cov_type='kernel', kernel='bartlett', bandwidth=3)

print("Hoan tat uoc luong mo hinh B064 (driscoll_kraay_fe) tren Python 3.11+.")
