Skip to content

Instantly share code, notes, and snippets.

@dill
Last active August 27, 2020 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dill/c0cde2fe99d575363977322f1570bbfb to your computer and use it in GitHub Desktop.
Save dill/c0cde2fe99d575363977322f1570bbfb to your computer and use it in GitHub Desktop.
NBER isn't good at models
# data digitized from https://twitter.com/nberpubs/status/1062080096549261312
# thanks @tpoi and co! https://cran.r-project.org/web/packages/digitize/index.html
# load the above data
dat <- read.csv("nber.csv")
# it's ya boi, mgcv
library(mgcv)
# fit the next stupidest model
b <- gam(y~s(x), data=dat)
# make predictions for plotting, incl uncertainty
preddat <- data.frame(x=seq(min(dat$x), max(dat$x), len=200))
pred <- predict(b, preddat, se=TRUE, unconditional=TRUE)
preddat$y <- pred$fit
# make +/- 2 std errors
preddat$upper <- pred$fit + 2*pred$se
preddat$lower <- pred$fit - 2*pred$se
# make a plotto
plot(dat, xlab="90th percentile-earner personal-income marginal tax rate(%)", ylab="log patents", type="n")
polygon(c(preddat$upper, rev(preddat$lower)),
x=c(preddat$x, rev(preddat$x)),
border=FALSE, col=grey(.8))
lines(preddat$x, preddat$y)
points(dat, pch=19, cex=0.6)
x y
-2.75506828 -0.077672676
-1.99675696 -0.110666901
-2.26950144 0.023157974
-1.84655654 -0.005664207
-1.65585928 -0.030414573
-1.42045090 0.001646266
-1.52673038 0.037121165
-1.05459664 0.051817282
-1.27775720 0.081002794
-0.91249558 0.015058196
-0.75182524 0.026139795
-1.17174112 0.101311751
-0.97129829 0.112781738
-0.83769168 0.084824035
-0.69657835 0.126795044
-0.63349549 0.127947680
-0.55796726 0.102364158
-0.45728490 0.111140484
-0.37596201 0.096275230
-0.51668025 0.074963980
-0.32460018 0.054573587
-0.27468701 0.146270845
-0.20416327 0.125604821
-0.07220288 0.128041645
-0.13851232 0.084755127
-0.01537562 0.059904532
0.06495954 0.042946991
0.13831477 -0.010230903
0.21147245 -0.006760465
0.45945790 -0.026850170
0.52096040 -0.046206948
0.38076895 -0.069610484
0.26803632 -0.107960710
0.34060136 -0.110441385
0.67517759 0.067033339
0.57271732 0.005429921
0.75715897 0.042176479
0.89616515 0.033694576
1.15771539 -0.012655199
0.94555152 -0.025290352
1.27248932 -0.066898029
1.03398606 -0.159390857
1.41656584 -0.161433028
1.53272259 -0.173786286
1.73237524 -0.142257915
2.35029755 -0.152832103
1.88705336 -0.264236942
2.07630195 -0.283625042
2.82598711 -0.273044589
3.82392111 -0.111199369
@dill
Copy link
Author

dill commented Nov 13, 2018

The resulting plot:

screen shot 2018-11-13 at 12 41 23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment