# =============================================================================
# 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 14 — Nhóm 5.2 Dữ liệu bảng động
# Bài giảng: B067 — Ước lượng biến giả hiệu chỉnh chệch Nickell
# Tên quốc tế: Bias-Corrected LSDV
# Mã mô hình : bias_corrected_lsdv
# Phần mềm : R 4.x — Gói lệnh: plm
# Dữ liệu   : vietlod_bias_corrected_lsdv_ecodata.csv
# Kiểm định : Đánh giá độ hội tụ từ bộ ước lượng khởi tạo Arellano–Bond hoặc Blundell–Bond và khoảng tin cậy Bootstrap tham số
# =============================================================================

options(scipen = 999, digits = 4)

# 1. Nạp bộ dữ liệu thực hành chuẩn hóa
data_file <- "vietlod_bias_corrected_lsdv_ecodata.csv"
if (!file.exists(data_file)) {
  data_file <- "https://sachktl.tnsai.vn/src/ecoaz/data/vietlod_bias_corrected_lsdv_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 B067 — Ước lượng biến giả hiệu chỉnh chệch Nickell
df <- read.csv('vietlod_bias_corrected_lsdv_ecodata.csv')
summary(df)
# plm::plm(y ~ lag(y, 1) + x1 + x2, data = pdata, model = 'within')

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