#!/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 17 — Nhóm 5.5 Dữ liệu bảng phụ thuộc chéo thế hệ 2
Bài giảng: B079 — Ước lượng gộp hiệu ứng tương quan chung
Tên quốc tế: Common Correlated Effects Pooled Estimator
Mã mô hình : ccep
Phần mềm : Python 3.11+ — Thư viện: linearmodels
Dữ liệu   : vietlod_ccep_ecodata.csv
Kiểm định : Kiểm định Pesaran CD phần dư, Pesaran–Yamagata $\hat{\Delta}_{\text{adj}}$ kiểm chứng điều kiện gộp hệ số, $R^2_{\text{MG/CCEP}}$.
"""

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_ccep_ecodata.csv"
if not os.path.exists(DATA_FILE):
    DATA_FILE = "https://sachktl.tnsai.vn/src/ecoaz/data/vietlod_ccep_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 B079 — Ước lượng gộp hiệu ứng tương quan chung
import pandas as pd
df = pd.read_csv('vietlod_ccep_ecodata.csv')
print(df.describe())
# PanelOLS.from_formula('y ~ 1 + x1 + x2 + mean_y + mean_x1 + EntityEffects', data=pdata).fit()

print("Hoan tat uoc luong mo hinh B079 (ccep) tren Python 3.11+.")
