Guest User

Untitled

a guest
Oct 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. set.seed(1234)
  2. library ('arm')
  3. lalondedat <- data('lalonde')
  4. datacont <- subset(lalonde, treat == '0')
  5.  
  6. contmodel <- lm(datacont$re78 ~ datacont$age+datacont$educ+datacont$re74+datacont$re75+(datacont$educ*datacont$re74)+(datacont$educ*datacont$re75)+(datacont$age*datacont$re74)+(datacont$age*datacont$re75)+(datacont$re74*datacont$re75))
  7. summary(contmodel)
  8. simulations <- sim(contmodel, n.sims = 10000)
  9.  
  10. storage_array <- rep(0:10000)
  11. result_matrix <- matrix(rep(1:10000*39), nrow = 39, ncol = 10000)
  12.  
  13. for (i in 17:55){
  14. matrix_1 <- matrix(c(1,i,quantile(datacont$educ, 0.9),quantile(datacont$re74, 0.9),quantile(datacont$re75, 0.9),quantile(datacont$educ, 0.9)*quantile(datacont$re74, 0.9),quantile(datacont$educ, 0.9)*quantile(datacont$re75, 0.9),i*quantile(datacont$re74, 0.9),i*quantile(datacont$re75, 0.9),quantile(datacont$re74, 0.9)*quantile(datacont$re75, 0.9)))
  15. storage_array <- simulations@coef %*% matrix_1 + rnorm(10000,0,simulations@sigma)
  16. result_matrix[i -16,] <- storage_array
  17. }
  18.  
  19. q_lower_quantile <- rep(0:39)
  20. q_upper_quantile <- rep(0:39)
  21. age <- rep(0:39)
  22.  
  23. for (i in 1:39){
  24. q_lower_quantile[i] <- quantile(result_matrix[i,], 0.025)
  25. q_upper_quantile[i] <- quantile(result_matrix[i,], 0.975)
  26. age[i] <- i+16
  27. }
  28.  
  29. pointestimates <- data.frame(age,q_lower_quantile,q_upper_quantile)
  30. write.csv(pointestimates, file = "Quantile Point Estimates.csv")
  31.  
  32. plot(c(1:100), c(1:100), type = 'n', ylim = c(-7000, 20000), xlim = c(17,55),
  33. main = "Scatter Plot While Holding Predictors at 90% Quantile", xlab = "Age", ylab = "Real Earning Income 1978")
  34. for (i in 17:55) {
  35. segments(
  36. x0 = i,
  37. y0= q_lower_quantile[i - 16],
  38. x1 = i,
  39. y1= q_upper_quantile[i - 16])
  40. }
Add Comment
Please, Sign In to add comment