Skip to main content

3. Xử lý dữ liệu

Verified Environments & Platforms:Academic FreeResearcher ProInstitutional VIP

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/.

Applied Quantitative Data Analysis w3. Xử lý dữ liệuApplied Econometrics, Statistical Modeling, and Hypothesis Testing · 8 Detailed LessoStata 18 MPR 4.xPython 3.11+TNSAI Ecosystem

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​

Yi=β0+∑k=1KβkXik+εi,E[εi∣Xi]=0[1]Y_i = \beta_0 + \sum_{k=1}^K \beta_k X_{ik} + \varepsilon_i, \quad \mathbb{E}[\varepsilon_i \mid \mathbf{X}_i] = 0 \tag*{[1]} Var^HC1(β^)=NN−K−1(X′X)−1(∑i=1Nε^i2xixi′)(X′X)−1[2]\widehat{\text{Var}}_{\text{HC1}}(\hat{\boldsymbol{\beta}}) = \frac{N}{N - K - 1}\left(\mathbf{X}'\mathbf{X}\right)^{-1}\left(\sum_{i=1}^N \hat{\varepsilon}_i^2 \mathbf{x}_i \mathbf{x}_i'\right)\left(\mathbf{X}'\mathbf{X}\right)^{-1} \tag*{[2]}

1.2. Core Identification Assumptions and Applicability Conditions​

  1. Correct functional form specification in parameters without omitting relevant covariates correlated with included regressors.
  2. Zero conditional mean of disturbances E[εi∣Xi]=0\mathbb{E}[\varepsilon_i \mid \mathbf{X}_i] = 0, ensuring unbiasedness and asymptotic consistency.
  3. Full column rank of the design matrix X\mathbf{X} without exact multicollinearity, paired with HC1 or cluster-robust standard errors under heteroskedasticity.
Methodological Scope Boundary:When explanatory variables are endogenous due to simultaneity, measurement error, or omitted confounders, OLS estimates are biased and inconsistent; transition to IV/2SLS or GMM estimation.

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.

5. Format Journal-Grade Tables and Cross-Verify on EcoLab

Report point estimates, standard errors in parentheses, and statistical significance stars following APA 7th / AER Booktabs standards, or automate the entire reporting pipeline on EcoLab and VietLOD.

4. Multi-Platform Implementation Scripts in Stata, R, and Python​

* 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)

5. Post-Estimation Diagnostic and Interpretation Guide​

Diagnostic CriterionNull Hypothesis H0H_0Benchmark ThresholdCorrective Action When H0H_0 Is Rejected
HeteroskedasticityConstant error variance Var(εi)=σ2\text{Var}(\varepsilon_i) = \sigma^2p-value<0.05p\text{-value} < 0.05 rejects H0H_0Apply vce(robust), vcovHC(HC1), or FGLS/WLS weighted estimation
MulticollinearityNo severe linear dependence among regressorsVIF<10\text{VIF} < 10 acceptableDrop redundant covariates, center interactions, or apply LASSO/Ridge regularization
Ramsey RESET Functional FormNo omitted nonlinear or higher-order termsp-value>0.05p\text{-value} > 0.05 retains H0H_0Add interaction terms, quadratic polynomials, or log-transform skewed positive variables
Regressor ExogeneityOrthogonality Cov(X,ε)=0\text{Cov}(X, \varepsilon)=0Durbin-Wu-Hausman p>0.05p > 0.05Transition 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
Lesson CodeLesson TitleSupported SoftwareOriginal Source Link on SachKTL
3.1Tính toán các biếnIBM SPSS 29Open Original Lesson on SachKTL
3.2Chuẩn hóa biếnStata 18 MP, IBM SPSS 29Open Original Lesson on SachKTL
3.3Chuyển hóa biếnIBM SPSS 29Open Original Lesson on SachKTL
3.4Biến danh mụcIBM SPSS 29Open Original Lesson on SachKTL
3.5Biến thứ tựIBM SPSS 29Open Original Lesson on SachKTL
3.6Sử dụng trọng sốIBM SPSS 29Open Original Lesson on SachKTL
3.7Sắp xếp dữ liệuIBM SPSS 29Open Original Lesson on SachKTL
3.8Gộp tách dữ liệuIBM SPSS 29Open Original Lesson on SachKTL