```{r setup, include=FALSE,echo=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


# Returns to education again
```{r,message=FALSE}
library(AER)
library(dplyr)
df=read.csv("https://www.dropbox.com/s/diecbkq03gfid0p/card1993.csv?dl=1") 
#from https://davidcard.berkeley.edu/data_sets.html

lm(wage76 ~ ed76, data = df) %>% summary()
```

```{r}
library(ggplot2)
ggplot(data=df, aes(x=ed76,y=wage76)) + geom_point() + theme_minimal()

```


```{r,message=FALSE}
#  library(ggplot2)
#  ggplot(data=CollegeDistance, aes(x=distance)) + geom_histogram() + theme_minimal()
```




```{r}
 first=lm(ed76~nearc4a, data = df)   
 first %>% summary()
```


```{r}
iv=ivreg(wage76 ~ ed76  | nearc4a, data=df)
iv %>% summary()

```


```{r}
iv=ivreg(wage76 ~ ed76+factor(region)+nearc4b+nearc2 | nearc4a+nearc4b+nearc2+factor(region)
         , data=df )
iv %>% summary()


```

```{r}
 first=lm(ed76~nearc4a+factor(region)+nearc4b+nearc2, data = df)   
 first %>% summary()
 linearHypothesis(first,c("nearc4a=0"))
 
```


```{r}
 reduced=lm(wage76~nearc4a+factor(region)+nearc4b+nearc2, data = df)   
 reduced %>% summary()
 
```


# The effect of subsidies on unemployment


```{r}
  library(haven)
  library(AER)
  df=read.csv( "https://www.dropbox.com/s/8pdffaq268v7m8o/unempprep.csv?dl=1")
  #names(df)
  summary(df$DDDNGE)
	
  

```  
	
### Simple OLS	
```{r} 
	 regOLS=lm(  DDDln1Punemp ~ DDDNGE ,df)
   summary(regOLS)
```



### IV

List of historic deprivation controls
```{r}
controls=c("gdp91","manufshare_1991","popdens_1981","current_unemprate1991","actrate_1991","resid_emp_rate92")
fff=paste(controls, collapse  ="+")
fff
```


Now run iv:

```{r}
 fffiv  =paste0( "DDDln1Punemp ~ DDDNGE+     ",fff, "| DDDxnivav +",fff)
 fffiv
 summary(ivreg(  fffiv ,data=df))
```


Check first stage

```{r}
  ffffs  =paste0( "DDDNGE~DDDxnivav+     ",fff)
 
  regFS=lm(  ffffs ,df)
  summary(regFS)	 
  linearHypothesis(regFS,"DDDxnivav=0")
```
Reduced Form:

```{r}
  fffrf  =paste0( "DDDln1Punemp~DDDxnivav+     ",fff)
  summary(lm(  fffrf ,df))
  
```




