Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. library("AER")
  2. library("ggplot2")
  3. library("dplyr")
  4.  
  5. data("CigarettesSW")
  6. h <- CigarettesSW
  7. glimpse(h)
  8. help("CigarettesSW")
  9.  
  10. h2 <- filter(h, year=="1995")
  11. glimpse(h2)
  12.  
  13. # a <- 7
  14. # a == 9
  15.  
  16. h3 <- mutate(h2, rprice = price/cpi, rtax = tax/cpi,
  17. rtaxs = taxs/cpi, rincome = income/population/cpi)
  18.  
  19. glimpse(h3)
  20.  
  21. # МНК
  22.  
  23. model_0 <- lm(log(packs)~log(rprice), data=h3)
  24. summary(model_0)
  25.  
  26. # Двухшаговый МНК
  27.  
  28. # Шаг 1
  29. step_1 <- lm(data=h3, log(rprice)~rtax)
  30. fitted(step_1) # прогнозы
  31. coef(step_1) # оценки коэффициентов
  32. resid(step_1) # остатки
  33.  
  34. h3$hat_log_p <- fitted(step_1)
  35. glimpse(h3)
  36.  
  37. # Шаг 2
  38. step_2 <- lm(data=h3, log(packs)~hat_log_p)
  39. summary(step_2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement