Memuat
Memuat
Tobit and Heckman Selection Models for Education and Learning
0 views
Estimating the effect of parental income and child grade level on censored tutoring expenditure with Tobit and Heckman selection models using synthetic data for demonstration. The Tobit model handles a dependent variable censored at zero (many zero observations), while the Heckman selection model corrects the bias when the outcome is only observed for participants. It suits theses on spending, hours or wages that are often zero or unobserved.

Estimating the effect of parental income and child grade level on censored tutoring expenditure with Tobit and Heckman selection models using synthetic data for demonstration.
| Role | Variable | Unit |
|---|---|---|
| Main | Tutoring expenditure | IDR thousand |
| Supporting 1 | Parental income | IDR million |
| Supporting 2 | Child grade level | grade |
45.7% of Tutoring expenditure observations are zero, so OLS (Parental income coefficient 7.426) is biased towards zero relative to the Tobit model (11.645; p < 0.001). The two-step Heckman model gives 6.836 for participants; the inverse Mills ratio (p = 0.018, rho = 0.50) indicates significant selection bias, so the Heckman correction matters.
Computed from illustrative synthetic data, not from a real study.
The Tobit model handles a dependent variable censored at zero (many zero observations), while the Heckman selection model corrects the bias when the outcome is only observed for participants. It suits theses on spending, hours or wages that are often zero or unobserved.
Report the share of zeros, then compare the OLS, Tobit and Heckman coefficients to show the OLS bias. Tobit coefficients are effects on the latent variable, Heckman coefficients are effects for participants, and a significant inverse Mills ratio (non-zero rho) signals selection bias.
A short starting script with this project's variable names. The delivered version is adapted to your data and fully commented.
# Contoh kode R: Tobit and Heckman Selection Models
suppressPackageStartupMessages({
library(ggplot2)
library(patchwork)
library(AER)
library(sampleSelection)
})
set.seed(42)
# ---- Gaya grafik ----
pal <- c("#1f6feb", "#e8590c", "#2f9e44", "#ae3ec9", "#f59f00")
warna <- list(bg = "#f4f6fa", panel = "#ffffff", teks = "#1f2933", redup = "#5f6b78", grid = "#e3e8ee", bar = "#1d3557")
tata <- 1
theme_set(theme_minimal(base_size = 11) + theme(legend.position = "bottom"))
# ---- Data sintetis: Y bernilai nol untuk yang tidak berpartisipasi ----
n <- max(300, 200)
d <- data.frame(parental_income = round(rnorm(n, 50, 10), 3),
child_grade_level = round(rnorm(n, 30, 6), 3),
akses = round(rnorm(n, 50, 10), 1)) # variabel eksklusi: hanya memengaruhi partisipasi
z1 <- as.numeric(scale(d$parental_income))
z2 <- as.numeric(scale(d$child_grade_level))
za <- as.numeric(scale(d$akses))
rho <- runif(1, 0.3, 0.7) # korelasi galat seleksi dan galat outcome
u <- rnorm(n)
e <- rho * u + sqrt(1 - rho^2) * rnorm(n)
# persamaan seleksi (partisipasi)
g0 <- qnorm(runif(1, 0.55, 0.72))
d$partisipasi <- as.integer(g0 + runif(1, 0.4, 0.8) * z1 + runif(1, 0.1, 0.3) * z2 + runif(1, 0.6, 1) * za + u > 0)
# persamaan outcome (hanya teramati bila partisipasi = 1)
b1 <- runif(1, 0.25, 0.45); b2 <- runif(1, 0.08, 0.25) * sample(c(-1, 1), 1)
y_star <- 100 * (1 + b1 * z1 + b2 * z2 + 0.3 * e)
d$tutoring_expenditure <- round(ifelse(d$partisipasi == 1, pmax(y_star, 0), 0), 3)
write.csv(d, "data_contoh.csv", row.names = FALSE)
# ---- Analisis 1: OLS naif dan Tobit (tersensor kiri di 0) ----
ols <- lm(tutoring_expenditure ~ parental_income + child_grade_level, data = d)
tob <- tobit(tutoring_expenditure ~ parental_income + child_grade_level, left = 0, data = d)
print(summary(ols)); print(summary(tob))
st <- coef(summary(tob))
sig_tob <- tob$scale
# ---- Analisis 2: Heckman dua tahap (heckit) dengan variabel eksklusi akses ----
hk <- selection(selection = partisipasi ~ parental_income + child_grade_level + akses,
outcome = tutoring_expenditure ~ parental_income + child_grade_level, data = d, method = "2step")
print(summary(hk))
sh <- coef(summary(hk))
io <- hk$param$index$betaO # baris persamaan outcome
b_hk <- sh[io, ]; rownames(b_hk) <- c("(Intercept)", "parental_income", "child_grade_level")
imr <- sh[hk$param$index$Mills, ] # koefisien inverse Mills ratio (lambda)
rho_hat <- unname(coef(hk)["rho"])
p_imr <- unname(imr[4])
nol <- 100 * mean(d$tutoring_expenditure == 0)
cat(sprintf("Proporsi nol: %.1f%%, rho = %.3f, p IMR = %.4f\n", nol, rho_hat, p_imr))
# ---- Grafik ----
# 1) histogram Y dengan massa di nol
d$jenis <- factor(ifelse(d$tutoring_expenditure == 0, "Zero (censored / not observed)", "Positive"),
levels = c("Zero (censored / not observed)", "Positive"))
p1 <- ggplot(d, aes(tutoring_expenditure, fill = jenis)) +
geom_histogram(bins = 30, colour = warna$panel, alpha = 0.9) +
scale_fill_manual(values = c(pal[2], pal[1]), name = NULL) +
labs(title = sprintf("Distribution of tutoring_expenditure (%.0f%% zeros)", 100 * mean(d$tutoring_expenditure == 0)), x = "tutoring_expenditure", y = "Count")
# 2) koefisien parental_income: OLS vs Tobit vs Heckman (IK 95%)
dk <- data.frame(model = factor(c("OLS", "Tobit", "Heckman"), levels = c("Heckman", "Tobit", "OLS")),
b = c(coef(ols)["parental_income"], st["parental_income", 1], b_hk["parental_income", 1]),
se = c(coef(summary(ols))["parental_income", 2], st["parental_income", 2], b_hk["parental_income", 2]))
dk$teks <- sprintf("%.3f", dk$b)
p2 <- ggplot(dk, aes(b, model, colour = model)) +
geom_errorbarh(aes(xmin = b - 1.96 * se, xmax = b + 1.96 * se), height = 0.18, linewidth = 1) +
geom_point(size = 3.2) +
geom_text(aes(label = teks), vjust = -1.2, size = 3, colour = warna$teks) +
scale_colour_manual(values = c(OLS = pal[2], Tobit = pal[1], Heckman = pal[3]), guide = "none") +
scale_y_discrete(expand = expansion(add = 0.7)) +
labs(title = "Coefficient of parental_income (95% CI)", x = "Estimate", y = NULL)
# 3) prediksi E[Y] menurut parental_income (X2 di rata-rata)
xs <- seq(min(d$parental_income), max(d$parental_income), length.out = 100)
nd <- data.frame(parental_income = xs, child_grade_level = mean(d$child_grade_level))
xb <- as.numeric(model.matrix(~ parental_income + child_grade_level, nd) %*% coef(tob))
dp <- rbind(data.frame(x = xs, y = predict(ols, nd), model = "OLS"),
data.frame(x = xs, y = pnorm(xb / sig_tob) * xb + sig_tob * dnorm(xb / sig_tob), model = "Tobit E[Y]"),
data.frame(x = xs, y = as.numeric(model.matrix(~ parental_income + child_grade_level, nd) %*% b_hk[, 1]), model = "Heckman E[Y*]"))
p3 <- ggplot() +
geom_point(data = d, aes(parental_income, tutoring_expenditure), colour = warna$redup, alpha = 0.3, size = 1.1) +
geom_line(data = dp, aes(x, y, colour = model), linewidth = 1.1) +
scale_colour_manual(values = c("OLS" = pal[2], "Tobit E[Y]" = pal[1], "Heckman E[Y*]" = pal[3]), name = NULL) +
labs(title = "Predicted tutoring_expenditure by parental_income", x = "parental_income", y = "tutoring_expenditure")
p_hasil <- if (tata == 1) p1 / (p2 | p3) else p1 | (p2 / p3)
print(p_hasil)
The original project file is available. It is not just the picture above: you get the working R project. It can be downloaded after payment, and we send it by WhatsApp or email.
ZIP: analisis.R + data_contoh.csv + BACA-DULU.txt
Choose how much help you need. Each higher package includes everything in the lower ones. Prices exclude 11% VAT.
Package 1
US$31
excl. 11% VAT
Duration: 7 working days
Output: R files + result figures
Deliverables
Package 2 · most chosen
US$94
excl. 11% VAT
Duration: 13 working days
Output: Code + analysis + interpretation notes
Includes all of Package 1, plus
Package 3
US$206
excl. 11% VAT
Duration: 18-21 working days
Output: Code + analysis + guidance until ready to present
Includes all of Packages 1 & 2, plus
Yes. The original project file is a ZIP containing the complete analisis.R script, a data_contoh.csv sample dataset and a BACA-DULU.txt guide. It can be downloaded after payment, and we send it by WhatsApp or email. For your own data (Package 2 and 3) the script is adapted to your dataset.
Yes. Tobit and Heckman Selection Models is commonly used at this level in Education and Learning. We adapt the analysis to your research question, your own data and your supervisor's requirements.
No. The sheet is computed from illustrative synthetic data so you can see the kind of output R Studio gives. For your order we run the same method on your own data.
That is the point of the packages. Every script is commented, and Package 3 includes two coaching sessions plus practice questions so you can explain the method and the results at your seminar and defence.
Each project has three packages: Package 1 (code and explanation) US$31, Package 2 (your data analysis and interpretation) US$94 and Package 3 (full guidance) US$206, excluding 11% VAT. Larger datasets, extra methods or tight deadlines adjust the quote after a short consultation.
The result sheet uses illustrative synthetic data. R is a programming language of the R Foundation project; RStudio and Posit are trademarks of Posit PBC.
Back to R Studio portfolio