Exemplo 10-7: Tendência Wooldridge (2006, p.331) - investimento imobiliário e preços de imóveis. Ver também HEISS (p.176), e MOHR (https://www.r-econometrics.com/reproduction/wooldridge/wooldridge10/). São dados anuais de investimento imobiliário real per capita (invpc em milhares de USD) e um índice de preços de imóveis (price, 1982=1) dos EUA de 1947 a 1988.
# https://www.r-econometrics.com/reproduction/wooldridge/wooldridge10/
library(wooldridge)
data("hseinv")
#esquisse::esquisser()
library(ggplot2)
ggplot(hseinv) +
aes(x = year, y = lprice) +
geom_line(size = 1L, colour = "#0c4c8a") +
theme_minimal()
# Plot de invpc
library(ggplot2)
ggplot(hseinv) +
aes(x = t, y = invpc) +
geom_line(size = 1L, colour = "#0c4c8a") +
theme_minimal()
# Plot de price
ggplot(hseinv) +
aes(x = t, y = price) +
geom_line(size = 1L, colour = "#0c4c8a") +
theme_minimal()
# regressão básica
lm.10.7.1 <- lm(linvpc ~ lprice, data = hseinv)
summary(lm.10.7.1)
##
## Call:
## lm(formula = linvpc ~ lprice, data = hseinv)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.45991 -0.08694 -0.01264 0.08651 0.34672
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.55023 0.04303 -12.788 1.03e-15 ***
## lprice 1.24094 0.38242 3.245 0.00238 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1554 on 40 degrees of freedom
## Multiple R-squared: 0.2084, Adjusted R-squared: 0.1886
## F-statistic: 10.53 on 1 and 40 DF, p-value: 0.002376
# regressão incluindo tendencia
lm.10.7.2 <- lm(linvpc ~ lprice + t+lprice_1, data = hseinv)
summary(lm.10.7.2)
##
## Call:
## lm(formula = linvpc ~ lprice + t + lprice_1, data = hseinv)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.282964 -0.073618 -0.005161 0.081887 0.205221
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.086488 0.115368 -9.418 2.29e-11 ***
## lprice 3.259517 0.960045 3.395 0.00165 **
## t 0.013447 0.002947 4.562 5.41e-05 ***
## lprice_1 -4.486770 0.958514 -4.681 3.76e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1153 on 37 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.5641, Adjusted R-squared: 0.5287
## F-statistic: 15.96 on 3 and 37 DF, p-value: 8.091e-07
# http://www.urfie.net/downloads10.html
#
library(dynlm);library(stargazer)
data(hseinv, package='wooldridge')
# Define Yearly time series beginning in 1947
tsdata <- ts(hseinv, start=1947)
class(tsdata)
## [1] "mts" "ts" "matrix"
# Linear regression of model with lags:
res1 <- dynlm(log(invpc) ~ log(price) , data=tsdata)
res2 <- dynlm(log(invpc) ~ log(price) + trend(tsdata)+
L(log(price)), data=tsdata)
res1$AIC<-AIC(res1)
res2$AIC<-AIC(res2)
star.1 <- stargazer(res1,res2,
title="Título: Resultados das Regressões",
align=TRUE,
type = "text", style = "all",
keep.stat=c("aic","rsq", "adj.rsq","n")
)
##
## Título: Resultados das Regressões
## ==============================================
## Dependent variable:
## ----------------------------
## log(invpc)
## (1) (2)
## ----------------------------------------------
## log(price) 1.241*** 3.260***
## (0.382) (0.960)
## t = 3.245 t = 3.395
## p = 0.003 p = 0.002
## trend(tsdata) 0.013***
## (0.003)
## t = 4.562
## p = 0.0001
## L(log(price)) -4.487***
## (0.959)
## t = -4.681
## p = 0.00004
## Constant -0.550*** -1.086***
## (0.043) (0.115)
## t = -12.788 t = -9.418
## p = 0.000 p = 0.000
## ----------------------------------------------
## Observations 42 41
## R2 0.208 0.564
## Adjusted R2 0.189 0.529
## Akaike Inf. Crit. -33.233 -54.983
## ==============================================
## Note: *p<0.1; **p<0.05; ***p<0.01