Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library("AER")
- library("ggplot2")
- library("dplyr")
- data("CigarettesSW")
- h <- CigarettesSW
- glimpse(h)
- help("CigarettesSW")
- h2 <- filter(h, year=="1995")
- glimpse(h2)
- # a <- 7
- # a == 9
- h3 <- mutate(h2, rprice = price/cpi, rtax = tax/cpi,
- rtaxs = taxs/cpi, rincome = income/population/cpi)
- glimpse(h3)
- # МНК
- model_0 <- lm(log(packs)~log(rprice), data=h3)
- summary(model_0)
- # Двухшаговый МНК
- # Шаг 1
- step_1 <- lm(data=h3, log(rprice)~rtax)
- fitted(step_1) # прогнозы
- coef(step_1) # оценки коэффициентов
- resid(step_1) # остатки
- h3$hat_log_p <- fitted(step_1)
- glimpse(h3)
- # Шаг 2
- step_2 <- lm(data=h3, log(packs)~hat_log_p)
- summary(step_2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement