Abstract
We analyse specifications of dummy and trend variables to the Wooldridge’s examples 10.4 and 10.8. This is an exercise using a linear multiple regression.This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
License: CC BY-SA 4.0
Sugestão de citação: FIGUEIREDO, Adriano Marcos Rodrigues. Econometria: exercício Efeitos da Isenção de Impostos nas Taxas de Fertilidade. Campo Grande-MS,Brasil: RStudio/Rpubs, 2019. Disponível em http://www.rpubs.com/amrofi/ex_wooldridge_10_8_update.
Os primeiros passos são criar ou abrir um diretório de trabalho. Se optar por criar um novo projeto, haverá a possibilidade de criar em uma pasta vazia. Os dados básicos estão no pacote wooldridge
, dataset fertil3
.
Example 10.4 Effects of Personal exemption on fertility rates. The general fertility rate (gfr) is the number of children born to every 1,000 women of childbearing age. For the years 1913 through 1984, the equation, \[ gfr_t= \beta _0 + \beta _1 pe_t +\beta _2 ww2_t + \beta _3 pill_t + \mu _t ,\] explains gfr in terms of the average real dollar value of the personal tax exemption (pe) and two binary variables. The variable ww2 takes on the value unity during the years 1941 through 1945, when the United States was involved in World War II. The variable pill is unity from 1963 onward, when the birth control pill was made available for contraception. Using the data in FERTIL3, which were taken from the article by Whittington, Alm, and Peters (1990).
library(dynlm)
library(stargazer)
data(fertil3, package = "wooldridge")
# exemplo 10.8 do livro do Wooldridge, Introdução a Econometria dados
# basicos de: Wooldridge Source: L.A. Whittington, J. Alm, and H.E. Peters
# (1990), “Fertility and the Personal Exemption: Implicit Pronatalist Policy
# in the United States,” American Economic Review 80, 545-556.
# data.frame with 72 observations on 24 variables:
# gfr: births per 1000 women 15-44 [tgf = taxa geral de fertilidade] pe:
# real value pers. exemption, $ [ip = valor real da taxa de isenção de
# impostos] year: 1913 to 1984 [ano] t: time trend, t=1,...,72 [tendencia]
# tsq: t^2 [tendencia ao quadrado] pill: =1 if year >= 1963 [pilula
# anticoncepcional] ww2: =1, 1941 to 1945 [world war dummy] tcu: t^3
# [tendencia cubica] cgfr: change in gfr: gfr - gfr_1 [mudanca na tx de
# fertilidade]
# Definir time series anual iniciando em 1913
attach(fertil3)
tsdata <- ts(fertil3, start = 1913)
O gráfico da variável dependente gfr (tgr - taxa geral de fertilidade) é:
require(fpp2)
autoplot(as.ts(gfr))
Vamos estimar o modelo linear múltipla fazendo a regressão inicial conforme o exemplo 10.4.
# Regressao Linear :
reg1 <- dynlm(gfr ~ pe + ww2 + pill, data = tsdata)
reg1$AIC <- AIC(reg1) # Akaike
reg1$BIC <- BIC(reg1) # Schwarz
stargazer(reg1, title = "Título: Resultado da Regressão OLS", align = TRUE,
type = "text", style = "all", keep.stat = c("AIC", "BIC", "rsq", "adj.rsq",
"n"))
Título: Resultado da Regressão OLS
===============================================
Dependent variable:
---------------------------
gfr
-----------------------------------------------
pe 0.083***
(0.030)
t = 2.784
p = 0.007
ww2 -24.238***
(7.458)
t = -3.250
p = 0.002
pill -31.594***
(4.081)
t = -7.742
p = 0.000
Constant 98.682***
(3.208)
t = 30.760
p = 0.000
-----------------------------------------------
Observations 72
R2 0.473
Adjusted R2 0.450
Akaike Inf. Crit. 597.115
Bayesian Inf. Crit. 608.499
===============================================
Note: *p<0.1; **p<0.05; ***p<0.01
São realizados dois procedimentos, um com a função trend(tsdata)
e outro com a variável \(t\) construída previamente, de modo que o leitor verá que ambos resultam no mesmo resultado.
# Regressao exemplo 10.8 - incluindo tendencia
reg2 <- dynlm(gfr ~ pe + ww2 + pill + trend(tsdata), data = tsdata)
reg2.a <- dynlm(gfr ~ pe + ww2 + pill + t, data = tsdata)
reg2$AIC <- AIC(reg2) # com tendencia
reg2$BIC <- BIC(reg2) # com tendencia
reg2.a$AIC <- AIC(reg2.a) # com tendencia
reg2.a$BIC <- BIC(reg2.a) # com tendencia
stargazer(reg2, reg2.a, title = "Título: Resultados das Regressões OLS
com tendência",
align = TRUE, type = "text", style = "all", keep.stat = c("AIC", "BIC",
"rsq", "adj.rsq", "n"))
Título: Resultados das Regressões OL
================================================
Dependent variable:
----------------------------
gfr
(1) (2)
------------------------------------------------
pe 0.279*** 0.279***
(0.040) (0.040)
t = 6.968 t = 6.968
p = 0.000 p = 0.000
ww2 -35.592*** -35.592***
(6.297) (6.297)
t = -5.652 t = -5.652
p = 0.00000 p = 0.00000
pill 0.997 0.997
(6.262) (6.262)
t = 0.159 t = 0.159
p = 0.874 p = 0.874
trend(tsdata) -1.150***
(0.188)
t = -6.119
p = 0.00000
t -1.150***
(0.188)
t = -6.119
p = 0.00000
Constant 111.769*** 111.769***
(3.358) (3.358)
t = 33.287 t = 33.287
p = 0.000 p = 0.000
------------------------------------------------
Observations 72 72
R2 0.662 0.662
Adjusted R2 0.642 0.642
Akaike Inf. Crit. 567.148 567.148
Bayesian Inf. Crit. 580.808 580.808
================================================
Note: *p<0.1; **p<0.05; ***p<0.01
reg3 <- dynlm(gfr ~ pe + ww2 + pill + t + I(t^2), data = tsdata)
reg3$AIC <- AIC(reg3) # com tendencia quadratica
reg3$BIC <- BIC(reg3) # com tendencia quadratica
reg4 <- dynlm(gfr ~ pe + ww2 + pill + t + I(t^2) + tcu, data = tsdata)
reg4$AIC <- AIC(reg4) # com tendencia cubica
reg4$BIC <- BIC(reg4) # com tendencia cubica
Para a tabela, a função com tendência será a número (1 - reg2.a), a quadrática a (2 - reg3) e a cúbica a (3 - reg4).
# library(stargazer)
star.1 <- stargazer(reg2.a, reg3, reg4, title = "Título: Resultados das Regressões",
align = TRUE, type = "text", keep.stat = c("aic", "bic", "rsq", "adj.rsq",
"n"))
Título: Resultados das Regressões
====================================================
Dependent variable:
--------------------------------
gfr
(1) (2) (3)
----------------------------------------------------
pe 0.279*** 0.348*** 0.162***
(0.040) (0.040) (0.041)
ww2 -35.592*** -35.880*** -19.047***
(6.297) (5.708) (5.042)
pill 0.997 -10.120 -25.010***
(6.262) (6.336) (5.346)
t -1.150*** -2.531*** -5.612***
(0.188) (0.389) (0.543)
I(t2) 0.020*** 0.155***
(0.005) (0.020)
tcu -0.001***
(0.0002)
Constant 111.769*** 124.092*** 142.795***
(3.358) (4.361) (4.338)
----------------------------------------------------
Observations 72 72 72
R2 0.662 0.727 0.840
Adjusted R2 0.642 0.706 0.826
Akaike Inf. Crit. 567.148 553.901 517.138
Bayesian Inf. Crit. 580.808 569.838 535.351
====================================================
Note: *p<0.1; **p<0.05; ***p<0.01
É possível observar que a expressão cúbica, (3), foi a de maiores valores de \(R^2\), \(R^2\) ajustado, e menores valores de Akaike (AIC) e Schwarz (Bayesian - BIC). Desta forma, a princípio, esta é a melhor expressão.
Faremos a investigação apenas para o melhor modelo, que conforme a última tabela, é o da função cúbica, (3), que na modelagem é o objeto reg4
.
library(lmtest)
resettest(reg4, power = 2:3, type = "fitted")
RESET test
data: reg4
RESET = 21.721, df1 = 2, df2 = 63, p-value = 6.687e-08
O teste RESET conclui pela rejeição de que as variáveis dependentes estimadas ao quadrado e ao cubo tenham coeficientes nulos, com probabilidade do teste de 6.687e-08. Desta forma, acusa que ainda existe algum problema de especificação.
O teste para outliers foi o Bonferonni do pacote car
. Conforme resultado abaixo, não foi identificado outlier da regressão.
library(car)
outlierTest(reg4)
No Studentized residuals with Bonferroni p < 0.05
Largest |rstudent|:
rstudent unadjusted p-value Bonferroni p
1963 2.403918 0.019127 NA
# obtendo residuos do modelo da tendencia cúbica
u.hat <- resid(reg4)
# teste de media zero dos residuos
t.test(u.hat)
One Sample t-test
data: u.hat
t = -4.0193e-16, df = 71, p-value = 1
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-1.858849 1.858849
sample estimates:
mean of x
-3.747003e-16
hist.reg4 <- hist(u.hat, freq = FALSE)
curve(dnorm, add = TRUE, col = "red")
split.screen(c(2, 2))
[1] 1 2 3 4
screen(1)
reg4.plot1 <- plot(reg4, which = 1)
screen(2)
reg4.plot2 <- plot(reg4, which = 2)
screen(3)
reg4.plot3 <- plot(reg4, which = 3)
screen(4)
reg4.plot4 <- plot(reg4, which = 4)
close.screen(all = TRUE) # exit split-screen mode
# testes dos residuos da regressao cubica
library(car)
residualPlots(reg4)
## normalidade dos residuos no R
qqPlot(reg4) #car
1963 1964
51 52
# teste de jarque-bera para normalidade
JB.reg4 <- tseries::jarque.bera.test(u.hat)
JB.reg4
Jarque Bera Test
data: u.hat
X-squared = 1.6922, df = 2, p-value = 0.4291
É possível concluir pela inexistência de outliers (o teste Bonferonni feito acima), a média dos resíduos é zero, e os eventuais outliers apontados no Q-Q plot anterior evidencia que os valores estão dentro dos limites tracejados, podendo concluir pela normalidade dos resíduos no gráfico e também no teste Jarque-Bera, cuja probabilidade do teste foi de 0.42, portanto, não podendo rejeitar H0 de que os resíduos têm distribuição normal.
# outros testes de normalidade
library(nortest)
# Testes
t1.2 <- ks.test(u.hat, "pnorm", mean(u.hat), summary(reg4)$sigma) # KS
t2.2 <- lillie.test(u.hat) # Lilliefors
t3.2 <- cvm.test(u.hat) # Cramér-von Mises
t4.2 <- shapiro.test(u.hat) # Shapiro-Wilk
t5.2 <- sf.test(u.hat) # Shapiro-Francia
t6.2 <- ad.test(u.hat) # Anderson-Darling
# Tabela de resultados
testes <- c(t1.2$method, t2.2$method, t3.2$method, t4.2$method, t5.2$method,
t6.2$method)
estt <- as.numeric(c(t1.2$statistic, t2.2$statistic, t3.2$statistic, t4.2$statistic,
t5.2$statistic, t6.2$statistic))
valorp <- c(t1.2$p.value, t2.2$p.value, t3.2$p.value, t4.2$p.value, t5.2$p.value,
t6.2$p.value)
resultados <- cbind(estt, valorp)
rownames(resultados) <- testes
colnames(resultados) <- c("Estatística", "valor-prob")
# print(resultados, digits = 4)
knitr::kable(resultados, digits = 4)
Estatística | valor-prob | |
---|---|---|
One-sample Kolmogorov-Smirnov test | 0.0565 | 0.9656 |
Lilliefors (Kolmogorov-Smirnov) normality test | 0.0671 | 0.5862 |
Cramer-von Mises normality test | 0.0552 | 0.4320 |
Shapiro-Wilk normality test | 0.9762 | 0.1900 |
Shapiro-Francia normality test | 0.9818 | 0.3252 |
Anderson-Darling normality test | 0.4327 | 0.2958 |