# =============================================================================
# HỆ SINH THÁI HỌC THUẬT TNSAI — SACHKTL.TNSAI.VN & VIETLOD.TNSAI.VN
# Khóa học : Khóa 2: Kinh tế lượng dữ liệu bảng và chuỗi thời gian tài chính
# Buổi học : Buổi 13 — Nhóm 7.3 Phương pháp chiếu cục bộ
# Bài giảng: B115 — Chiếu cục bộ trên dữ liệu bảng đa đơn vị
# Tên quốc tế: Panel Local Projections
# Mã mô hình : panel_local_projections
# Phần mềm : R 4.x — Gói lệnh: lpirfs / fixest
# Dữ liệu   : vietlod_panel_local_projections_ecodata.csv
# Kiểm định : Dải phản ứng xung bảng theo $h$, kiểm định tiền xu hướng tại $h = -3, -2$, Driscoll–Kraay cross-dependence check.
# =============================================================================

options(scipen = 999, digits = 4)

# 1. Nạp bộ dữ liệu thực hành chuẩn hóa
data_file <- "vietlod_panel_local_projections_ecodata.csv"
if (!file.exists(data_file)) {
  data_file <- "https://sachktl.tnsai.vn/src/ecoaz/data/vietlod_panel_local_projections_ecodata.csv"
}
df <- read.csv(data_file, stringsAsFactors = FALSE)
cat("Kich thuoc mau thuc hanh:", nrow(df), "quan sat,", ncol(df), "bien so\n")

# 2. Thực thi kịch bản ước lượng và kiểm định B115 — Chiếu cục bộ trên dữ liệu bảng đa đơn vị
df <- read.csv('vietlod_panel_local_projections_ecodata.csv')
summary(df)
# lpirfs::lp_lin_panel(data_set = df, endog_data = 'y', shock = 'shock', panel_model = 'within', hor = 8)

cat("Hoan tat uoc luong mo hinh B115 (panel_local_projections) tren R 4.x.\n")
