-
Notifications
You must be signed in to change notification settings - Fork 315
/
Table 4-1-2.r
65 lines (54 loc) · 2.18 KB
/
Table 4-1-2.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# R code for Table 4-1-2 #
# Required packages #
# - data.table: data management #
# - systemfit: SUR #
library(data.table)
library(systemfit)
# Download data and unzip the data
download.file('http://economics.mit.edu/files/397', 'asciiqob.zip')
unzip('asciiqob.zip')
# Read the data into a data.table
pums <- fread('asciiqob.txt',
header = FALSE,
stringsAsFactors = FALSE)
names(pums) <- c('lwklywge', 'educ', 'yob', 'qob', 'pob')
# Create binary variable
pums$z <- (pums$qob == 3 | pums$qob == 4) * 1
# Compare means (and differences)
ttest.lwklywge <- t.test(lwklywge ~ z, pums)
ttest.educ <- t.test(educ ~ z, pums)
# Compute Wald estimate
sur <- systemfit(list(first = educ ~ z,
second = lwklywge ~ z),
data = pums,
method = "SUR")
wald <- deltaMethod(sur, "second_z / first_z")
wald.estimate <- (mean(pums$lwklywge[pums$z == 1]) - mean(pums$lwklywge[pums$z == 0])) /
(mean(pums$educ[pums$z == 1]) - mean(pums$educ[pums$z == 0]))
wald.se <- wald.estimate^2 * ()
# OLS estimate
ols <- lm(lwklywge ~ educ, pums)
# Construct table
lwklywge.row <- c(ttest.lwklywge$estimate[1],
ttest.lwklywge$estimate[2],
ttest.lwklywge$estimate[2] - ttest.lwklywge$estimate[1])
educ.row <- c(ttest.educ$estimate[1],
ttest.educ$estimate[2],
ttest.educ$estimate[2] - ttest.educ$estimate[1])
wald.row.est <- c(NA, NA, wald$Estimate)
wald.row.se <- c(NA, NA, wald$SE)
ols.row.est <- c(NA, NA, summary(ols)$coef['educ' , 'Estimate'])
ols.row.se <- c(NA, NA, summary(ols)$coef['educ' , 'Std. Error'])
table <- rbind(lwklywge.row, educ.row,
wald.row.est, wald.row.se,
ols.row.est, ols.row.se)
colnames(table) <- c("Born in the 1st or 2nd quarter of year",
"Born in the 3rd or 4th quarter of year",
"Difference")
rownames(table) <- c("ln(weekly wage)",
"Years of education",
"Wald estimate",
"Wald std error",
"OLS estimate",
"OLS std error")
# End of script