Documente Academic
Documente Profesional
Documente Cultură
390)
12.3. Wooldridge Source: C.M. Krupp and P.S. Pollard (1999), Market Responses to Antidumpting Laws:
Some Evidence from the U.S. Chemical Industry, Canadian Journal of Economics 29, 199-227. They are
monthly data covering February 1978 through December 1988.
lchnimp: log(chnimp)
lgas: log(gas)
lrtwex: log(rtwex)
lchempi: log(chempi)
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 1/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
t: time trend
apr:
may:
jun:
jul:
aug:
sep:
oct:
nov:
dec:
> library(dynlm);library(stargazer);library(wooldridge)
> data(barium, package='wooldridge')
> dados=barium
> attach(dados)
> library(knitr)
> kable(dados[,1:5],caption="Dados do exemplo")
Dados do exemplo
220.4620 9578.376 0 0 0
94.7980 11219.480 0 0 0
219.3575 9719.900 0 0 0
317.4215 12920.950 0 0 0
114.6390 9790.446 0 0 0
129.5240 11020.470 0 0 0
110.0920 8302.168 0 0 0
39.6830 9583.325 0 0 0
262.8230 9880.729 0 0 0
173.9980 9003.923 0 0 0
548.9455 10153.390 0 0 0
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 2/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
433.9755 10527.060 0 0 0
213.7855 9238.292 0 0 0
788.6440 11740.390 0 0 0
287.0395 13699.070 0 0 0
278.9545 17716.330 0 0 0
429.8970 15868.760 0 0 0
344.8820 15512.320 0 0 0
538.9150 13831.560 0 0 0
535.7180 13669.760 0 0 0
445.3290 16691.211 0 0 0
649.2550 16617.330 0 0 0
639.3350 15912.760 0 0 0
209.4370 9401.297 0 0 0
512.5915 9195.309 0 0 0
605.3425 11727.520 0 0 0
144.2360 20584.260 0 0 0
405.5360 8929.146 0 0 0
621.1075 10912.110 0 0 0
893.7185 13581.910 0 0 0
140.2300 9218.409 0 0 0
243.4765 20751.770 0 0 0
330.5750 12935.290 0 0 0
46.5860 26984.199 0 0 0
215.1960 18886.381 0 0 0
214.8385 25679.510 0 0 0
238.2085 15502.940 0 0 0
265.6545 18247.141 0 0 0
315.2515 12060.010 0 0 0
426.5905 17777.609 0 0 0
124.7860 14406.150 0 0 0
387.8990 20570.359 0 0 0
400.5400 14210.780 0 0 0
876.8340 15190.780 0 0 0
535.9930 14593.670 0 0 0
815.9555 14044.220 0 0 0
771.8130 10431.430 0 0 0
352.8730 13228.840 0 0 0
431.9340 12801.710 0 0 0
1211.4520 16403.340 0 0 0
575.9175 13591.700 0 0 0
1491.6219 16239.280 0 0 0
380.2920 20010.461 0 0 0
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 3/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
391.5965 16873.131 0 0 0
505.5120 15379.570 0 0 0
341.0220 10551.650 0 0 0
372.5765 20755.381 0 0 0
483.3590 18066.199 0 0 0
224.0470 17886.760 0 0 0
532.3940 19134.020 0 0 0
239.1405 17455.141 0 0 0
689.4535 18215.721 0 0 0
318.0120 20764.830 1 0 0
1048.0360 28414.789 1 0 0
945.7295 18819.391 1 0 0
295.3720 11737.220 1 0 0
319.4580 12520.280 1 0 0
855.1370 16988.230 1 0 0
671.8070 15835.780 0 0 0
657.9315 17282.949 0 1 0
847.9595 26960.510 0 1 0
849.8735 25137.689 0 1 0
852.9305 19807.490 0 1 0
435.8370 32134.600 0 1 0
204.7075 22954.551 0 1 0
241.5675 24438.789 0 0 0
244.1380 19057.439 0 0 0
656.4015 26784.340 0 0 0
588.0975 37244.379 0 0 0
1128.4440 28129.359 0 0 0
1328.9670 37253.469 0 0 0
227.0635 18289.359 0 0 1
583.2610 14795.910 0 0 1
499.8935 25700.260 0 0 1
165.3460 25240.311 0 0 1
1057.9720 24854.939 0 0 1
465.8225 24119.289 0 0 1
349.4040 27244.980 0 0 0
466.8240 30912.420 0 0 0
717.0470 23173.529 0 0 0
826.7580 29031.439 0 0 0
1571.7360 19400.510 0 0 0
542.9925 29887.711 0 0 0
670.7935 20670.631 0 0 0
430.2755 34375.250 0 0 0
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 4/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
524.8625 19555.820 0 0 0
317.7500 27362.230 0 0 0
442.8195 31952.500 0 0 0
322.6325 19578.160 0 0 0
742.0795 26605.789 0 0 0
665.3660 20034.420 0 0 0
737.2670 33408.488 0 0 0
1065.2111 20967.311 0 0 0
547.3285 26526.840 0 0 0
1258.4070 28304.020 0 0 0
976.5165 17168.150 0 0 0
1192.6840 12874.300 0 0 0
1047.2390 16153.360 0 0 0
944.7875 15638.680 0 0 0
840.0295 18391.830 0 0 0
578.9175 18786.789 0 0 0
828.1195 17661.711 0 0 0
1010.0570 17623.770 0 0 0
1546.4830 18482.400 0 0 0
1160.1580 21132.420 0 0 0
862.6800 16421.520 0 0 0
692.2970 16128.660 0 0 0
451.3840 14769.440 0 0 0
766.4015 34192.180 0 0 0
1794.5160 17537.230 0 0 0
972.8010 25518.910 0 0 0
738.5085 36649.191 0 0 0
786.1805 18668.000 0 0 0
849.0650 19710.660 0 0 0
895.4205 38521.531 0 0 0
814.3615 19679.381 0 0 0
589.4220 31686.859 0 0 0
529.7335 16370.340 0 0 0
968.0375 15653.960 0 0 0
794.0600 45716.609 0 0 0
1087.8060 29580.500 0 0 0
1 Resultados
1.1 Estimação
Fazendo as regressoes com uso de logaritmos.
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 5/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
Call:
dynlm(formula = log(chnimp) ~ log(chempi) + log(gas) + log(rtwex) +
befile6 + affile6 + afdec6, data = tsdata)
Residuals:
Min 1Q Median 3Q Max
-2.03356 -0.39080 0.03048 0.40248 1.51720
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -17.80277 21.04537 -0.846 0.3992
log(chempi) 3.11719 0.47920 6.505 1.72e-09 ***
log(gas) 0.19634 0.90662 0.217 0.8289
log(rtwex) 0.98302 0.40015 2.457 0.0154 *
befile6 0.05957 0.26097 0.228 0.8198
affile6 -0.03241 0.26430 -0.123 0.9026
afdec6 -0.56524 0.28584 -1.978 0.0502 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> plot(chnimp)
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 6/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
Vamos utilizar o pacote stargazer para organizar as saídas de resultados. Se a saída fosse apenas pelo comando summary, sairia da forma:
> summary(mod1)
Call:
dynlm(formula = log(chnimp) ~ log(chempi) + log(gas) + log(rtwex) +
befile6 + affile6 + afdec6, data = tsdata)
Residuals:
Min 1Q Median 3Q Max
-2.03356 -0.39080 0.03048 0.40248 1.51720
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -17.80277 21.04537 -0.846 0.3992
log(chempi) 3.11719 0.47920 6.505 1.72e-09 ***
log(gas) 0.19634 0.90662 0.217 0.8289
log(rtwex) 0.98302 0.40015 2.457 0.0154 *
befile6 0.05957 0.26097 0.228 0.8198
affile6 -0.03241 0.26430 -0.123 0.9026
afdec6 -0.56524 0.28584 -1.978 0.0502 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 7/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
Multiple R-squared: 0.3049, Adjusted R-squared: 0.2712
F-statistic: 9.064 on 6 and 124 DF, p-value: 3.255e-08
Agora, criando uma tabela com as várias saídas de modelos, com o pacote stargazer tem-se, com a geração de AIC e BIC:
> library(stargazer)
> mod1$AIC <- AIC(mod1)
>
> mod1$BIC <- BIC(mod1)
>
> library(stargazer)
> star.1 <- stargazer(mod1,
+ title="Título: Resultado da Regressão",
+ align=TRUE,
+ type = "text", style = "all",
+ keep.stat=c("aic","bic","rsq", "adj.rsq","n")
+ )
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 8/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
Call:
dynlm(formula = residual ~ L(residual) + L(residual, 2) + L(residual,
3) + log(chempi) + log(gas) + log(rtwex) + befile6 + affile6 +
afdec6, data = tsdata)
Residuals:
Min 1Q Median 3Q Max
-1.89072 -0.32250 0.05873 0.36376 1.19650
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -14.36906 20.65566 -0.696 0.4880
L(residual) 0.22149 0.09166 2.417 0.0172 *
L(residual, 2) 0.13404 0.09216 1.454 0.1485
L(residual, 3) 0.12554 0.09112 1.378 0.1709
log(chempi) -0.14316 0.47203 -0.303 0.7622
log(gas) 0.62330 0.88597 0.704 0.4831
log(rtwex) 0.17867 0.39103 0.457 0.6486
befile6 -0.08592 0.25101 -0.342 0.7327
affile6 -0.12212 0.25470 -0.479 0.6325
afdec6 -0.06683 0.27437 -0.244 0.8080
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> linearHypothesis(resreg,
+ c("L(residual)","L(residual, 2)","L(residual, 3)"))
Hypothesis:
L(residual) = 0
L(residual, 2) = 0
L(residual, 3) = 0
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 9/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
> r2aux<-summary(resreg)$r.squared
> r2aux
[1] 0.1159108
> nr2<-n*r2aux
> nr2
[1] 15.18431
data: mod1
LM test = 14.768, df = 3, p-value = 0.002026
data: mod1
LM test = 5.1247, df1 = 3, df2 = 121, p-value = 0.002264
> dw.mod1<-dwtest(mod1)
> dw.mod1
Durbin-Watson test
data: mod1
DW = 1.4584, p-value = 0.0001688
alternative hypothesis: true autocorrelation is greater than 0
Fiz uma rotina para rodar vários BGtest até ordem 12.
data: mod1
LM test = 9.8291, df = 1, p-value = 0.001718
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 10/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
data: mod1
LM test = 12.935, df = 2, p-value = 0.001553
data: mod1
LM test = 14.768, df = 3, p-value = 0.002026
data: mod1
LM test = 17.463, df = 4, p-value = 0.001571
data: mod1
LM test = 17.465, df = 5, p-value = 0.003697
data: mod1
LM test = 17.555, df = 6, p-value = 0.007445
data: mod1
LM test = 18.881, df = 7, p-value = 0.008569
data: mod1
LM test = 18.9, df = 8, p-value = 0.0154
data: mod1
LM test = 22.435, df = 9, p-value = 0.007598
data: mod1
LM test = 22.438, df = 10, p-value = 0.01302
data: mod1
LM test = 23.335, df = 11, p-value = 0.01585
data: mod1
LM test = 23.935, df = 12, p-value = 0.02076
> d
bgtest.chi.statistic bgtest.chi.p.value
LM test 9.829115 0.001717710
LM test1 12.934847 0.001553223
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 11/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
LM test2 14.768156 0.002025887
LM test3 17.463024 0.001570843
LM test4 17.465245 0.003696957
LM test5 17.555240 0.007445324
LM test6 18.880776 0.008569139
LM test7 18.900273 0.015402181
LM test8 22.434946 0.007598117
LM test9 22.437807 0.013023155
LM test10 23.334705 0.015849005
LM test11 23.935057 0.020758676
Call:
dynlm(formula = log(chnimp) ~ log(chempi) + log(gas) + log(rtwex) +
befile6 + affile6 + afdec6, data = tsdata)
number of interaction: 8
rho 0.293362
Durbin-Watson statistic
(original): 1.45841 , p-value: 1.688e-04
(transformed): 2.06330 , p-value: 4.91e-01
coefficients:
(Intercept) log(chempi) log(gas) log(rtwex) befile6 affile6
-37.322241 2.947434 1.054858 1.136918 -0.016372 -0.033082
afdec6
-0.577158
> library(prais)
> barium_prais_winsten <- prais_winsten(log(chnimp)~log(chempi)+log(gas)+log(rtwex)+
+ befile6+affile6+afdec6, data=tsdata)
Iteration 0: rho = 0
Iteration 1: rho = 0.2708
Iteration 2: rho = 0.291
Iteration 3: rho = 0.293
Iteration 4: rho = 0.2932
Iteration 5: rho = 0.2932
Iteration 6: rho = 0.2932
Iteration 7: rho = 0.2932
> summary(barium_prais_winsten)
Call:
prais_winsten(formula = log(chnimp) ~ log(chempi) + log(gas) +
log(rtwex) + befile6 + affile6 + afdec6, data = tsdata)
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 12/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
Residuals:
Min 1Q Median 3Q Max
-1.99386 -0.32219 0.03747 0.40226 1.50281
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -37.07742 22.77831 -1.628 0.1061
log(chempi) 2.94095 0.63284 4.647 8.46e-06 ***
log(gas) 1.04637 0.97734 1.071 0.2864
log(rtwex) 1.13279 0.50666 2.236 0.0272 *
befile6 -0.01648 0.31938 -0.052 0.9589
affile6 -0.03316 0.32181 -0.103 0.9181
afdec6 -0.57681 0.34199 -1.687 0.0942 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> # library(sandwich)
> # OLS regression
> # foi feita a mod1
> mod1 <- dynlm(log(chnimp)~log(chempi)+log(gas)+log(rtwex)+
+ befile6+affile6+afdec6, data=tsdata )
> # resultados com erros-padrões usuais
> coeftest(mod1)
t test of coefficients:
t test of coefficients:
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 13/14
07/01/2019 RPubs - Econometria: exemplos Bário 10.5 e 12.3 do Wooldridge (2016, p.390)
Call:
dynlm(formula = log(chnimp) ~ log(chempi) + log(gas) + log(rtwex) +
befile6 + affile6 + afdec6, data = tsdata)
Residuals:
Min 1Q Median 3Q Max
-2.03356 -0.39080 0.03048 0.40248 1.51720
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -17.80277 26.49705 -0.672 0.5029
log(chempi) 3.11719 0.65419 4.765 5.19e-06 ***
log(gas) 0.19634 1.19662 0.164 0.8699
log(rtwex) 0.98302 0.45021 2.183 0.0309 *
befile6 0.05957 0.15326 0.389 0.6982
affile6 -0.03241 0.23379 -0.139 0.8900
afdec6 -0.56524 0.24956 -2.265 0.0253 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
http://rpubs.com/amrofi/ex_wooldridge_12_3_autocorrelation 14/14