Skip to content

Instantly share code, notes, and snippets.

@johnjosephhorton
Created December 16, 2017 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save johnjosephhorton/3737259262cbde0de5fb56835d5539a6 to your computer and use it in GitHub Desktop.
Save johnjosephhorton/3737259262cbde0de5fb56835d5539a6 to your computer and use it in GitHub Desktop.
library(lfe)
library(stargazer)
set.seed(6152011)
# Number of cities
L <- 1000
# Number of industries
K <- 3
# National growth rates by industry
g.raw <- runif(K)
g.k <- g.raw/sum(g.raw)
CreateCity <- function(g.k, eta.s){
# Give each city some industry shares
K <- length(g.k)
z.raw <- runif(K)
z <- z.raw / sum(z.raw)
# Give each city some idiosyncratic growth by industry
g.kl.tilde <- g.raw/sum(g.raw)
# Change in employement is inner product of the national + idiosyncratic component with industry share
x <- (g.kl.tilde + g.k) %*% z
# Bartik instrument (national growth & city industry share inner product)
B <- g.k %*% z
# Realized change in wage
y <- (1/eta.s) * x + rnorm(1,0,1/10)
list("y" = y, "B" = B, "x" = x)
}
# Create a city data frame
city.data <- rep(CreateCity(g.k, 1), L)
df <- data.frame(matrix(unlist(city.data), ncol = 3))
colnames(df) <- c("y", "B", "x")
# Estimates
m.ols <- felm(y ~ x | 0 | 0 | 0, data = df)
m.iv <- felm(y ~ 1 | 0 | (x ~ B) | 0, data = df)
stargazer(m, m.iv, type = "text")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment