-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathps1_iv_card_schholing.Rmd
135 lines (108 loc) · 3.71 KB
/
ps1_iv_card_schholing.Rmd
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
---
title: "IO & Econometrics workshop - PS1"
author: "Doron Zamir"
output:
html_document:
keep_md: yes
df_print: paged
pdf_document: default
---
This is a markdown file created using RStudio.
### Using Packeges
I used these packages to create the data:
```{r warning= FALSE, message=FALSE}
library(tidyverse)
library(knitr)
library(magrittr)
library(AER)
library(broom)
```
```{r, include=FALSE}
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
```
## Tidy the Data
### Importing Data
I used the data from [David Card's website](https://davidcard.berkeley.edu/data_sets.html)
The relevant file is `nls.dat` saved in the `Data` directory.
```{r }
data <- read.table("Data/nls.dat") %>% as_data_frame()
head(data)
```
### Changing col names & type
Using variable names from `code_bk.txt'
```{r}
colnames(data) <-(c("id","nearc2","nearc4","nearc4a","nearc4b","ed76","ed66","age76","daded","nodaded","momed","nomomed","weight","momdad14","sinmom14","step14","reg661","reg662","reg663","reg664","reg665","reg666","reg667","reg668","reg669","south66","work76","work78","lwage76","lwage78","famed","black","smsa76r","smsa78r","reg76r","reg78r","reg80r","smsa66r","wage76","wage78","wage80","noint78","noint80","enroll76","enroll78","enroll80","kww","iq","marsta76","marsta78","marsta80","libcrd14"))
data %<>% mutate_if(is_character,suppressWarnings(as.numeric))
head(data)
```
### Creating new Varibales for experiance
$$exp76=age76-ed76-6$$
$$exp762=exp76*exp76$$
```{r}
data <- data %>% mutate(exp76 = age76-ed76 - 6)
data <- data %>% mutate(exp762 = exp76 ** 2)
```
### Sumaarise Data
```{r}
data_summary <- data[-1] %>%
summarise_all(list(
Min = min,
Mean = mean,
Max = max,
SD = sd)) %>%
pivot_longer(everything(),
names_to = c("Var","Stat"),
names_sep = "_") %>%
pivot_wider(names_from = "Stat") %>% column_to_rownames("Var")
data_summary %>% format(scientific = FALSE, digits = 2,trim = TRUE)
```
## Plotting
```{r}
data_to_plot <- data %>%
mutate(
black = factor(black,labels = c("no","yes")),
nearc4=factor(nearc4,labels = c("no","yes")),
)
```
### Education and lwage
```{r}
data_to_plot %>% ggplot(aes(ed76,lwage78)) +
geom_point(aes(
color = nearc4),
alpha =0.4 ) +
geom_smooth(method = lm)
```
### Splitting by distance from collage
```{r}
data_to_plot %>% ggplot(aes(ed76,lwage78)) +
geom_point(aes(
color = black),
alpha =0.4 ) +
geom_smooth(method = lm)+
facet_grid(cols = vars(nearc4))
```
### Histogram of ed76
```{r}
data_to_plot %>% ggplot(aes(ed76)) +
geom_bar(aes(
fill = black)) +
facet_grid(row = vars(nearc4))
```
## Estimating a model
### OLS
$$ lwage78 = \alpha \cdot ed76 + \beta \cdot X + u$$
I used model #2 from Card's paper
```{r}
ols_model <- data %>% lm(lwage78~ed76 + exp76 +exp762+smsa76r+ reg76r+smsa66r+
+reg662+reg663+reg664+reg665+reg666+reg667+reg668+reg669, data = .)
kable(tidy(ols_model))
```
### 2SLS
$$ lwage78 = \alpha \cdot (\delta \cdot nearc4 + v) + \beta \cdot X + u$$
```{r}
IV_model <- data %>% ivreg(lwage78~ed76 + exp76 +exp762+smsa76r+reg76r+smsa66r+reg662+reg663+reg664+reg665+reg666+reg667+reg668+reg669|exp76 +exp762+smsa76r+reg76r+smsa66r+reg662+reg663+reg664+reg665+reg666+reg667+reg668+reg669 + nearc4, data = .)
kable(tidy(IV_model))
```
I used a standard model of wage as function of education, controlling experince ($ exp^2) and using panel data for race, region of living, etc.
For IV, I used procimity to collage (as card did). It sounds like a reasnble IV as it is corelated with education, but it can fail.
It can effect wage and earnings in more ways the just throw education: it can effect the quality of education, the enveirmont a perso grows in, etc.