3. Xử lý dữ liệu
This practical how-to guide presents the theoretical foundations, structural mathematical equations, detailed breakdown of 8 specialized lessons, and multi-platform replication workflows for 3. Xử lý dữ liệu from the textbook Applied Quantitative Data Analysis with IBM SPSS, with direct cross-references to the authoritative source material at https://sachktl.tnsai.vn/vi/spss/xu-ly-du-lieu/.
1. Methodological Foundations, Mathematical Specification, and Identification
Part 1: Working with Variables Most of the time, you'll need to make modifications to your variables before you can analyze your data. These types of modifications can include changing a variable's type from numeric to string, merging the categories of a nominal or ordinal variable, dichotomizing a continuous variable at a cut point, or computing a new summary variable from existing variables. This section will focus on transformations applied to individual variables, particularly recoding and computing new variables.
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. Tính toán các biến
Computing Variables Sometimes you may need to compute a new variable based on existing information in your data. For example, you may want to: Convert the units of a variable from feet to meters Use a subject's height and weight to compute their BMI Compute a subscale score from items on a survey Apply a computation conditionally, so that a new variable is only computed for cases where certain conditions are met In this tutorial, we'll discuss how to compute variables in SPSS using numeric expressions, built-in functions, and conditional.
Key Methodological Sub-Topics Covered in This Lesson:
-
Computing Variables
-
Computing Variables using Syntax
-
Example: Computing a New Variable Using Arithmetic
-
Using the Compute Variables Dialog Window
-
Using Syntax
-
Example: Computing a New Variable Using a Built-In Function
-
Analytical Environments:
IBM SPSS 29· Authoritative Source: Read Full Original Lesson on SachKTL
2.2. Chuẩn hóa biến
Introduction Mean centering refers to a type of variable transformation wherein the average of a variable is subtracted from every observation of that variable. The result of this transformation is a new variable that retains its original units, but whose mean value is 0. Mean centering is often used when fitting linear regression models because of how it affects the interpretation of the intercept term. With an uncentered predictor variable, the intercept of a linear regression represents the expected value of y when the x variable is zero.
Key Methodological Sub-Topics Covered in This Lesson:
-
Introduction
-
Aggregating Data
-
Example: Mean-centering a variable about the grand mean
-
Problem Statement
-
Running the Procedure
-
Using the Dialog Windows
-
Analytical Environments:
Stata 18 MP, IBM SPSS 29· Authoritative Source: Read Full Original Lesson on SachKTL
2.3. Chuyển hóa biến
Recoding Variables Sometimes you will want to transform a variable by combining some of its categories or values together. For example, you may want to change a continuous variable into an ordinal categorical variable, or you may want to merge the categories of a nominal variable. In SPSS, this type of transform is called recoding.
Key Methodological Sub-Topics Covered in This Lesson:
-
Recoding Variables
-
Recode into Different Variables
-
Old and New Values
-
The “If” option
-
Recode into Same Variables
-
DO IF - ELSE IF Syntax
-
Analytical Environments:
IBM SPSS 29· Authoritative Source: Read Full Original Lesson on SachKTL
2.4. Biến danh mục
Recoding Categorical String Variables to Labeled Numeric Variables using Automatic Recode When writing down the observed values of a categorical variable, you can choose to write the data values as words or as numeric codes. Either method of recording categorical variables is valid, but it is often easier to work with numeric codes in SPSS than it is to work with strings. This is because, when referring to the content of a string during a computation, the content must match exactly.
Key Methodological Sub-Topics Covered in This Lesson:
-
Recoding Categorical String Variables to Labeled Numeric Variables using Automatic Recode
-
Running the Automatic Recode Procedure
-
Example: Recognizing Blank Strings as User-Missing Values
-
Problem Statement
-
Running the Procedure
-
Using the Automatic Recode Dialog Window
-
Analytical Environments:
IBM SPSS 29· Authoritative Source: Read Full Original Lesson on SachKTL
2.5. Biến thứ tự
Introduction A rank variable represents the ordering of the values of a numeric variable from smallest to largest . Ranking is its own type of variable transformation, and is also useful when you want to convert a numeric variable into a categorical variable using percentiles. Rank Cases In SPSS, rank transforms and percentile groupings can be computed using the Rank Cases procedure. To open Rank Cases, click Transform > Rank Cases. A Variables: The variables to compute rank transforms on. The new ranks will be saved to new variables .
Key Methodological Sub-Topics Covered in This Lesson:
-
Introduction
-
Rank Cases
-
Example: Rank Transforms for Non-Normal Data
-
Before the Procedure
-
Running the Procedure
-
Syntax
-
Analytical Environments:
IBM SPSS 29· Authoritative Source: Read Full Original Lesson on SachKTL
2.6. Sử dụng trọng số
Weighting Cases In SPSS, weighting cases allows you to assign "importance" or "weight" to the cases in your dataset. Some situations where this can be useful include: Your data is in the form of counts of factors or events. The "weight" is the number of occurrences. Your data requires adjustments to correct for over- or under-representation of certain characteristics in your sample. The Pew Research Center often makes their raw survey data available online to the public.
Key Methodological Sub-Topics Covered in This Lesson:
-
Weighting Cases
-
Example: Reproducing an Existing 3x2 Table
-
Problem Statement
-
Running the Procedure
-
Syntax
-
Output
-
Analytical Environments:
IBM SPSS 29· Authoritative Source: Read Full Original Lesson on SachKTL
2.7. Sắp xếp dữ liệu
Sorting Data Sorting data allows us to re-organize the data in ascending or descending order with respect to a specific variable. Some procedures in SPSS require that your data be sorted in a certain way before the procedure will execute. There are two options for sorting data: Sort Cases Sort Variables We cover how to perform each sorting option below. Sort Cases Sorting cases will rearrange the rows based on a given variable.
Key Methodological Sub-Topics Covered in This Lesson:
-
Sorting Data
-
Sort Cases
-
Sorting from the Data View
-
Sorting with the Sort Cases procedure
-
Sorting with Syntax
-
Sort Variables
-
Analytical Environments:
IBM SPSS 29· Authoritative Source: Read Full Original Lesson on SachKTL
2.8. Gộp tách dữ liệu
Grouping or Splitting Data When analyzing data, it is sometimes useful to temporarily "group" or "split" your data in order to compare results across different subsets. This can be useful when you want to compare frequency distributions or descriptive statistics with respect to the categories of some variable - especially if you want separate tables of results for each group. To split your dataset, click Data > Split File. SPSS Version 25 Drop-Down Menu SPSS Version 22 Drop-Down Menu The Split File window will appear.
Key Methodological Sub-Topics Covered in This Lesson:
-
Grouping or Splitting Data
-
Turning Off Split File
-
Syntax
-
Example
-
Problem Statement
-
Splitting using Compare Groups
-
Analytical Environments:
IBM SPSS 29· 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 3. Xử lý dữ liệu. 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 3. Xử lý dữ liệu on SachKTL
7. Complete Lesson Directory and Backlinks to Original SachKTL Articles
| Lesson Code | Lesson Title | Supported Software | Original Source Link on SachKTL |
|---|---|---|---|
| 3.1 | Tính toán các biến | IBM SPSS 29 | Open Original Lesson on SachKTL |
| 3.2 | Chuẩn hóa biến | Stata 18 MP, IBM SPSS 29 | Open Original Lesson on SachKTL |
| 3.3 | Chuyển hóa biến | IBM SPSS 29 | Open Original Lesson on SachKTL |
| 3.4 | Biến danh mục | IBM SPSS 29 | Open Original Lesson on SachKTL |
| 3.5 | Biến thứ tự | IBM SPSS 29 | Open Original Lesson on SachKTL |
| 3.6 | Sử dụng trọng số | IBM SPSS 29 | Open Original Lesson on SachKTL |
| 3.7 | Sắp xếp dữ liệu | IBM SPSS 29 | Open Original Lesson on SachKTL |
| 3.8 | Gộp tách dữ liệu | IBM SPSS 29 | Open Original Lesson on SachKTL |