6. Regression Models With Qualitative Variables
This practical how-to guide presents the theoretical foundations, structural mathematical equations, detailed breakdown of 3 specialized lessons, and multi-platform replication workflows for 6. Regression Models With Qualitative Variables from the textbook Econometrics: Theory and Practice, with direct cross-references to the authoritative source material at https://sachktl.tnsai.vn/vi/dsask19u1/c6/.
1. Methodological Foundations, Mathematical Specification, and Identification
Mô hình hồi quy với biến định tính Trong phân tích kinh tế lượng, chúng ta thường xuyên làm việc với các biến số có thể đo lường được như thu nhập, chi tiêu, hay số năm đi học. Tuy nhiên, thực tế kinh tế-xã hội phức tạp hơn nhiều và thường bị ảnh hưởng bởi các yếu tố không thể định lượng một cách trực tiếp, chẳng hạn như giới tính, khu vực địa lý, ngành nghề, hay tình trạng hôn nhân. Vậy làm thế nào để đưa những yếu tố định tính này vào một mô hình hồi quy tuyến tính một cách khoa học và hiệu quả? Câu trả lời nằm ở một công cụ mạnh mẽ và linh hoạt: biến giả .
1.1. Structural Equations and Representative Estimator
1.2. Core Identification Assumptions and Applicability Conditions
- Correct functional form specification in parameters without omitting relevant covariates correlated with included regressors.
- Zero conditional mean of disturbances , ensuring unbiasedness and asymptotic consistency.
- Full column rank of the design matrix without exact multicollinearity, paired with HC1 or cluster-robust standard errors under heteroskedasticity.
Read the complete theoretical derivations, mathematical proofs, and worked examples for this chapter on SachKTL.
Extract standardized Vietnamese macroeconomic, corporate financial, and household survey data for hands-on replication.
Execute econometric specifications, run diagnostic battery tests, and export APA 7th / AER publication-grade tables automatically.
2. Lesson-by-Lesson Academic Breakdown
2.1. Giới thiệu biến giả trong mô hình hồi quy
Tiếp nối bài giới thiệu tổng quan, bài học đầu tiên này sẽ đặt những viên gạch nền tảng vững chắc nhất cho việc sử dụng biến định tính trong phân tích hồi quy. Mục tiêu cốt lõi của chúng ta là hiểu rõ bản chất của biến giả, một công cụ cho phép "lượng hóa" các thông tin không thể đo lường trực tiếp. Chúng ta sẽ bắt đầu với trường hợp đơn giản nhất: một biến định tính chỉ có hai hạng mục, sau đó mở rộng sang các biến có nhiều hạng mục phức tạp hơn .
Key Methodological Sub-Topics Covered in This Lesson:
-
Nền tảng lý thuyết về biến giả chặn
-
Trường hợp nhân tố nhị phân
-
Trường hợp nhân tố đa biến
-
Cảnh báo: Bẫy biến giả
-
Tổng kết bài học
-
Quy tắc thực hành cần nhớ
-
Analytical Environments:
Stata 18 MP, R 4.x, Python 3.11+· Authoritative Source: Read Full Original Lesson on SachKTL
2.2. Tương tác biến giả và ứng dụng với stata
Trong bài học trước, chúng ta đã tìm hiểu cách sử dụng biến giả để tạo ra các mô hình có điểm chặn khác nhau cho từng nhóm, giả định rằng tác động của các biến giải thích khác là như nhau trên mọi nhóm. Tuy nhiên, giả định này có thể quá cứng nhắc trong nhiều bối c ảnh thực tế. Liệu lợi tức của một năm học thêm có thực sự giống hệt nhau giữa nam và nữ? Liệu tác động của một chính sách có như nhau ở khu vực thành thị và nông thôn? Để trả lời những câu hỏi tinh vi này, chúng ta cần một công cụ mạnh mẽ hơn: biến giả tương tác .
Key Methodological Sub-Topics Covered in This Lesson:
-
Nền tảng lý thuyết về biến giả tương tác
-
Tương tác giữa hai biến định tính
-
Tương tác giữa biến định tính và biến định lượng
-
Ví dụ minh họa với Stata
-
Mô hình cộng thêm với nhiều biến giả
-
Mô hình tương tác định tính - định lượng
-
Analytical Environments:
Stata 18 MP· Authoritative Source: Read Full Original Lesson on SachKTL
2.3. Hướng dẫn thực hành với Stata
Chào mừng bạn đến với bài học cuối cùng trong hành trình khám phá vai trò của biến định tính trong mô hình hồi quy. Sau khi đã xây dựng nền tảng vững chắc về biến giả chặn ở Bài 1 và khám phá sức mạnh của biến giả tương tác ở Bài 2, bài học này sẽ là nơi ch úng ta tổng hợp và áp dụng toàn bộ kiến thức đó vào một quy trình phân tích dữ liệu thực tế từ đầu đến cuối.
Key Methodological Sub-Topics Covered in This Lesson:
-
Dữ liệu và câu hỏi nghiên cứu
-
Hướng dẫn quy trình phân tích từ A-Z
-
Bước 1: Khám phá và tóm tắt dữ liệu
-
Bước 2: Xây dựng mô hình cơ sở
-
Bước 3: Xây dựng mô hình cộng thêm
-
Bước 4: Xây dựng mô hình tương tác
-
Analytical Environments:
Stata 18 MP· Authoritative Source: Read Full Original Lesson on SachKTL
3. Step-by-Step Empirical Implementation Workflow
1. Formulate the Research Question and Prepare Data on EcoData & Finco
Define the dependent variable, core explanatory variables, and control covariates aligned with 6. Regression Models With Qualitative Variables. Extract standardized Vietnamese empirical series from EcoData or Finco, and screen for missing observations and extreme outliers.
2. Conduct Descriptive Profiling, Correlation Analysis, and Pre-Estimation Checks
Examine empirical distributions, construct summary statistics tables, and evaluate collinearity using pairwise correlation matrices and Variance Inflation Factors (VIF).
3. Estimate the Model Across Stata 18 MP, R 4.x, and Python 3.11+
Execute the parameter estimation scripts matching the structural equations in Section 1.1 while cross-checking theoretical derivations at SachKTL.
4. Perform Post-Estimation Diagnostics and Robust Variance Correction
Test for heteroskedasticity, serial correlation, Ramsey RESET functional form misspecification, and regressor endogeneity. Apply White HC1 or cluster-robust standard errors for valid inference.
4. Multi-Platform Implementation Scripts in Stata, R, and Python
- Stata 18 MP
- R 4.x
- Python 3.11+
* Thiết lập môi trường, ước lượng mô hình và kiểm định chẩn đoán toàn diện
version 18.0
clear all
set more off
import delimited "sachktl_empirical_ecodata.csv", clear encoding("utf-8")
describe
summarize y x1 x2 x3, detail
* 1. Ước lượng mô hình cơ sở và kiểm định phương sai thay đổi / đa cộng tuyến / dạng hàm
regress y x1 x2 x3
estat hettest
estat imtest, white
estat vif
estat ovtest
* 2. Ước lượng với sai số chuẩn vững White HC1 và xuất tác động biên
regress y c.x1##c.x2 x3, vce(robust)
margins, dydx(x1 x2 x3)
# Nạp thư viện phân tích kinh tế lượng và thực thi kiểm định chẩn đoán
library(tidyverse)
library(lmtest)
library(sandwich)
library(car)
df <- read.csv("sachktl_empirical_ecodata.csv")
summary(df)
# 1. Ước lượng mô hình tuyến tính và kiểm định Breusch-Pagan, RESET, VIF
fit <- lm(y ~ x1 + x2 + x3, data = df)
bptest(fit)
resettest(fit, power = 2:3, type = "fitted")
vif(fit)
# 2. Xuất bảng hệ số ước lượng với sai số chuẩn vững HC1
coeftest(fit, vcov = vcovHC(fit, type = "HC1"))
# Nạp thư viện statsmodels và thực thi ước lượng kèm chẩn đoán phần dư
import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf
from statsmodels.stats.diagnostic import het_breuschpagan, linear_reset
from statsmodels.stats.outliers_influence import variance_inflation_factor
df = pd.read_csv("sachktl_empirical_ecodata.csv")
# 1. Ước lượng mô hình với sai số chuẩn vững HC1
model = smf.ols("y ~ x1 + x2 + x3", data=df).fit(cov_type="HC1")
print(model.summary())
# 2. Kiểm định phương sai thay đổi Breusch-Pagan, Ramsey RESET và hệ số VIF
bp_lm, bp_pval, _, _ = het_breuschpagan(model.resid, model.model.exog)
reset_res = linear_reset(model, power=2, use_f=True)
X = sm.add_constant(df[["x1", "x2", "x3"]].dropna())
vifs = {col: variance_inflation_factor(X.values, i) for i, col in enumerate(X.columns)}
print(f"Breusch-Pagan p={bp_pval:.4f} | RESET p={reset_res.pvalue:.4f} | VIF={vifs}")
5. Post-Estimation Diagnostic and Interpretation Guide
| Diagnostic Criterion | Null Hypothesis | Benchmark Threshold | Corrective Action When Is Rejected |
|---|---|---|---|
| Heteroskedasticity | Constant error variance | rejects | Apply vce(robust), vcovHC(HC1), or FGLS/WLS weighted estimation |
| Multicollinearity | No severe linear dependence among regressors | acceptable | Drop redundant covariates, center interactions, or apply LASSO/Ridge regularization |
| Ramsey RESET Functional Form | No omitted nonlinear or higher-order terms | retains | Add interaction terms, quadratic polynomials, or log-transform skewed positive variables |
| Regressor Exogeneity | Orthogonality | Durbin-Wu-Hausman | Transition to IV/2SLS, LIML, or GMM estimation with validated instruments |
6. Video Tutorial Walkthrough
Video Tutorial: Practical Walkthrough for 6. Regression Models With Qualitative Variables on SachKTL
7. Complete Lesson Directory and Backlinks to Original SachKTL Articles
| Lesson Code | Lesson Title | Supported Software | Original Source Link on SachKTL |
|---|---|---|---|
| 6.1 | Giới thiệu biến giả trong mô hình hồi quy | Stata 18 MP, R 4.x, Python 3.11+ | Open Original Lesson on SachKTL |
| 6.2 | Tương tác biến giả và ứng dụng với stata | Stata 18 MP | Open Original Lesson on SachKTL |
| 6.3 | Hướng dẫn thực hành với Stata | Stata 18 MP | Open Original Lesson on SachKTL |