aula2<-url("https://sites.google.com/site/andersonmoreiraadossantos/base-de-dados/aula2.RData")
load(aula2)
# Criando ln das variáveis
serie_gujarati$lny<-log(serie_gujarati$y)
serie_gujarati$lnx<-log(serie_gujarati$x)
# séries de tempo
dados<-ts(serie_gujarati, start=1960)
plot(dados)
library(ggplot2)

# Gráfico de lny e lnx
p<-ggplot()+
geom_line(data=serie_gujarati, aes(x=ano,y=lny, color="lny"))+
geom_line(data=serie_gujarati, aes(x=ano,y=lnx, color="lnx"))+
xlab('ano')+
ylab('Séries')
print (p)

# Gráfico de dispersão
p<-ggplot(serie_gujarati,aes(x=x,y=y))
p<-p+geom_point(size=0.9)
print(p)

# MQO
ols<-lm(lny~lnx, data=dados)
summary(ols)
##
## Call:
## lm(formula = lny ~ lnx, data = dados)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.041164 -0.017041 0.001037 0.018077 0.038719
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.60668 0.05471 29.37 <2e-16 ***
## lnx 0.65222 0.01235 52.80 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.02208 on 44 degrees of freedom
## Multiple R-squared: 0.9845, Adjusted R-squared: 0.9841
## F-statistic: 2788 on 1 and 44 DF, p-value: < 2.2e-16
# Teste de Durbin-Watson
#install.packages("lmtest")
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
dwtest(lny ~ lnx, data=dados)
##
## Durbin-Watson test
##
## data: lny ~ lnx
## DW = 0.21756, p-value < 2.2e-16
## alternative hypothesis: true autocorrelation is greater than 0
#Breusch-Godfrey test
bgtest(lny ~ lnx, order = 1, type="F", data=dados)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: lny ~ lnx
## LM test = 122.1, df1 = 1, df2 = 43, p-value = 3.825e-14
bgtest(lny ~ lnx, order = 2, type="F", data=dados)
##
## Breusch-Godfrey test for serial correlation of order up to 2
##
## data: lny ~ lnx
## LM test = 61.277, df1 = 2, df2 = 42, p-value = 3.514e-13
# Cochran Orcutt
#install.packages("orcutt")
library(orcutt)
coch <- cochrane.orcutt(ols)
coch
## Cochrane-orcutt estimation for first order autocorrelation
##
## Call:
## lm(formula = lny ~ lnx, data = dados)
##
## number of interaction: 19
## rho 0.868978
##
## Durbin-Watson statistic
## (original): 0.21756 , p-value: 5.098e-19
## (transformed): 1.70388 , p-value: 1.253e-01
##
## coefficients:
## (Intercept) lnx
## 1.955389 0.576819
# results with HAC SE
#install.packages("sandwich")
library(sandwich)
coeftest(ols)
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.606680 0.054709 29.368 < 2.2e-16 ***
## lnx 0.652216 0.012353 52.800 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftest(ols, vcovHAC)
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.606680 0.119460 13.450 < 2.2e-16 ***
## lnx 0.652216 0.026714 24.415 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
############################################### MQ2E
library(AER)
## Loading required package: car
## Loading required package: survival
library("mfx")
## Loading required package: MASS
## Loading required package: betareg
library(lmtest)
library(car)
##
attach(trabalho)
Z<-cbind(nonmomi,educ,age,agesq,black,hispan)
I<-cbind(multi2nd,samesex)
### MQO
mqo<-lm(hours~ kids +Z, data=trabalho)
summary(mqo)
##
## Call:
## lm(formula = hours ~ kids + Z, data = trabalho)
##
## Residuals:
## Min 1Q Median 3Q Max
## -33.261 -18.186 3.546 16.176 90.167
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -10.446952 6.575591 -1.589 0.112127
## kids -2.325836 0.114636 -20.289 < 2e-16 ***
## Znonmomi -0.057833 0.005397 -10.716 < 2e-16 ***
## Zeduc 0.586008 0.036635 15.996 < 2e-16 ***
## Zage 2.048793 0.447939 4.574 4.81e-06 ***
## Zagesq -0.027720 0.007697 -3.601 0.000317 ***
## Zblack 1.058285 1.349776 0.784 0.433019
## Zhispan -5.114147 1.351898 -3.783 0.000155 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 18.78 on 31849 degrees of freedom
## Multiple R-squared: 0.0727, Adjusted R-squared: 0.0725
## F-statistic: 356.7 on 7 and 31849 DF, p-value: < 2.2e-16
### Primeiro estágio
est1<-lm(kids~Z+I, data=trabalho)
summary(est1)
##
## Call:
## lm(formula = kids ~ Z + I, data = trabalho)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.0951 -0.6482 -0.2658 0.4473 8.8067
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.043e+00 3.201e-01 6.385 1.74e-10 ***
## Znonmomi -2.788e-03 2.624e-04 -10.626 < 2e-16 ***
## Zeduc -8.531e-02 1.719e-03 -49.620 < 2e-16 ***
## Zage 5.634e-02 2.181e-02 2.583 0.0098 **
## Zagesq 4.357e-05 3.749e-04 0.116 0.9075
## Zblack 1.057e-02 6.573e-02 0.161 0.8723
## Zhispan -4.204e-02 6.584e-02 -0.639 0.5231
## Imulti2nd 7.632e-01 5.530e-02 13.802 < 2e-16 ***
## Isamesex 7.044e-02 1.025e-02 6.873 6.39e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.9145 on 31848 degrees of freedom
## Multiple R-squared: 0.1244, Adjusted R-squared: 0.1242
## F-statistic: 565.5 on 8 and 31848 DF, p-value: < 2.2e-16
### Segundo estágio
est2<-lm(hours~ fitted(est1) +Z, data=trabalho)
summary(est2)
##
## Call:
## lm(formula = hours ~ fitted(est1) + Z, data = trabalho)
##
## Residuals:
## Min 1Q Median 3Q Max
## -33.510 -18.349 3.881 15.988 87.442
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -9.103834 7.153308 -1.273 0.203143
## fitted(est1) -2.986165 1.340511 -2.228 0.025912 *
## Znonmomi -0.059665 0.006575 -9.074 < 2e-16 ***
## Zeduc 0.529633 0.119833 4.420 9.91e-06 ***
## Zage 2.088150 0.457764 4.562 5.09e-06 ***
## Zagesq -0.027726 0.007746 -3.579 0.000345 ***
## Zblack 1.067778 1.358500 0.786 0.431875
## Zhispan -5.140945 1.361579 -3.776 0.000160 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 18.9 on 31849 degrees of freedom
## Multiple R-squared: 0.06086, Adjusted R-squared: 0.06065
## F-statistic: 294.8 on 7 and 31849 DF, p-value: < 2.2e-16
###MQ2E comando
mq2e<-ivreg(hours~ kids +Z | I +Z, data=trabalho)
summary(mq2e)
##
## Call:
## ivreg(formula = hours ~ kids + Z | I + Z, data = trabalho)
##
## Residuals:
## Min 1Q Median 3Q Max
## -33.443 -18.170 3.445 16.189 91.385
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -9.103834 7.111779 -1.280 0.200517
## kids -2.986165 1.332728 -2.241 0.025056 *
## Znonmomi -0.059665 0.006537 -9.127 < 2e-16 ***
## Zeduc 0.529633 0.119137 4.446 8.80e-06 ***
## Zage 2.088150 0.455106 4.588 4.49e-06 ***
## Zagesq -0.027726 0.007701 -3.600 0.000318 ***
## Zblack 1.067778 1.350614 0.791 0.429191
## Zhispan -5.140945 1.353675 -3.798 0.000146 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 18.79 on 31849 degrees of freedom
## Multiple R-Squared: 0.07173, Adjusted R-squared: 0.07153
## Wald test: 298.3 on 7 and 31849 DF, p-value: < 2.2e-16
###Control function
fcontrole<-lm(hours~ kids +Z+resid(est1), data=trabalho)
summary(fcontrole)
##
## Call:
## lm(formula = hours ~ kids + Z + resid(est1), data = trabalho)
##
## Residuals:
## Min 1Q Median 3Q Max
## -33.242 -18.181 3.559 16.184 90.130
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -9.103834 7.108161 -1.281 0.200288
## kids -2.986165 1.332050 -2.242 0.024982 *
## Znonmomi -0.059665 0.006534 -9.132 < 2e-16 ***
## Zeduc 0.529633 0.119077 4.448 8.70e-06 ***
## Zage 2.088150 0.454875 4.591 4.44e-06 ***
## Zagesq -0.027726 0.007697 -3.602 0.000316 ***
## Zblack 1.067778 1.349926 0.791 0.428956
## Zhispan -5.140945 1.352986 -3.800 0.000145 ***
## resid(est1) 0.665256 1.337011 0.498 0.618791
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 18.78 on 31848 degrees of freedom
## Multiple R-squared: 0.07271, Adjusted R-squared: 0.07247
## F-statistic: 312.1 on 8 and 31848 DF, p-value: < 2.2e-16
### Teste de restrições de sobreidentificação -- exogeneidade dos instrumentos
res.aux<-lm(resid(mq2e)~Z+I, data=trabalho)
(r2<-summary(res.aux)$r.squared)
## [1] 1.567711e-05
(n<-nobs(res.aux))
## [1] 31857
(SH<-n*r2)
## [1] 0.4994258
(pval_SH<-1-pchisq(SH,1))
## [1] 0.4797525
detach(trabalho)
##################################################Variável de resposta binária
attach(ocup_filhos)
X<-cbind(nwifeinc, educ, exper, expersq, age, kidslt6, kidsge6 )
##MPL
mpl<-lm(inlf~X, data=ocup_filhos)
summary(mpl)
##
## Call:
## lm(formula = inlf ~ X, data = ocup_filhos)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.93432 -0.37526 0.08833 0.34404 0.99417
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.5855192 0.1541780 3.798 0.000158 ***
## Xnwifeinc -0.0034052 0.0014485 -2.351 0.018991 *
## Xeduc 0.0379953 0.0073760 5.151 3.32e-07 ***
## Xexper 0.0394924 0.0056727 6.962 7.38e-12 ***
## Xexpersq -0.0005963 0.0001848 -3.227 0.001306 **
## Xage -0.0160908 0.0024847 -6.476 1.71e-10 ***
## Xkidslt6 -0.2618105 0.0335058 -7.814 1.89e-14 ***
## Xkidsge6 0.0130122 0.0131960 0.986 0.324415
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4271 on 745 degrees of freedom
## Multiple R-squared: 0.2642, Adjusted R-squared: 0.2573
## F-statistic: 38.22 on 7 and 745 DF, p-value: < 2.2e-16
mpl
##
## Call:
## lm(formula = inlf ~ X, data = ocup_filhos)
##
## Coefficients:
## (Intercept) Xnwifeinc Xeduc Xexper Xexpersq
## 0.5855192 -0.0034052 0.0379953 0.0394924 -0.0005963
## Xage Xkidslt6 Xkidsge6
## -0.0160908 -0.2618105 0.0130122
coeftest(mpl, vcov=hccm)
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.58551922 0.15358032 3.8125 0.000149 ***
## Xnwifeinc -0.00340517 0.00155826 -2.1852 0.029182 *
## Xeduc 0.03799530 0.00733982 5.1766 2.909e-07 ***
## Xexper 0.03949239 0.00598359 6.6001 7.800e-11 ***
## Xexpersq -0.00059631 0.00019895 -2.9973 0.002814 **
## Xage -0.01609081 0.00241459 -6.6640 5.183e-11 ***
## Xkidslt6 -0.26181047 0.03215160 -8.1430 1.621e-15 ***
## Xkidsge6 0.01301223 0.01366031 0.9526 0.341123
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##logit
logit<-glm(inlf~X,family=binomial(link="logit"), data=ocup_filhos)
summary(logit)
##
## Call:
## glm(formula = inlf ~ X, family = binomial(link = "logit"), data = ocup_filhos)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.1770 -0.9063 0.4473 0.8561 2.4032
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.425452 0.860365 0.495 0.62095
## Xnwifeinc -0.021345 0.008421 -2.535 0.01126 *
## Xeduc 0.221170 0.043439 5.091 3.55e-07 ***
## Xexper 0.205870 0.032057 6.422 1.34e-10 ***
## Xexpersq -0.003154 0.001016 -3.104 0.00191 **
## Xage -0.088024 0.014573 -6.040 1.54e-09 ***
## Xkidslt6 -1.443354 0.203583 -7.090 1.34e-12 ***
## Xkidsge6 0.060112 0.074789 0.804 0.42154
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 1029.75 on 752 degrees of freedom
## Residual deviance: 803.53 on 745 degrees of freedom
## AIC: 819.53
##
## Number of Fisher Scoring iterations: 4
#Razão de chances
logitor(inlf~X,data=ocup_filhos)
## Call:
## logitor(formula = inlf ~ X, data = ocup_filhos)
##
## Odds Ratio:
## OddsRatio Std. Err. z P>|z|
## Xnwifeinc 0.9788810 0.0082435 -2.5346 0.011256 *
## Xeduc 1.2475360 0.0541921 5.0915 3.553e-07 ***
## Xexper 1.2285929 0.0393847 6.4220 1.345e-10 ***
## Xexpersq 0.9968509 0.0010129 -3.1041 0.001909 **
## Xage 0.9157386 0.0133450 -6.0403 1.538e-09 ***
## Xkidslt6 0.2361344 0.0480729 -7.0898 1.343e-12 ***
## Xkidsge6 1.0619557 0.0794229 0.8038 0.421539
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Efeito marginal médio
logitmfx(inlf~X, atmean=FALSE, start=NULL, data=ocup_filhos)
## Call:
## logitmfx(formula = inlf ~ X, data = ocup_filhos, atmean = FALSE,
## start = NULL)
##
## Marginal Effects:
## dF/dx Std. Err. z P>|z|
## Xnwifeinc -0.00381181 0.00153898 -2.4769 0.013255 *
## Xeduc 0.03949652 0.00846811 4.6641 3.099e-06 ***
## Xexper 0.03676411 0.00655577 5.6079 2.048e-08 ***
## Xexpersq -0.00056326 0.00018795 -2.9968 0.002728 **
## Xage -0.01571936 0.00293269 -5.3600 8.320e-08 ***
## Xkidslt6 -0.25775366 0.04263493 -6.0456 1.489e-09 ***
## Xkidsge6 0.01073482 0.01339130 0.8016 0.422769
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Efeito marginal na média
logitmfx(inlf~X,data=ocup_filhos)
## Call:
## logitmfx(formula = inlf ~ X, data = ocup_filhos)
##
## Marginal Effects:
## dF/dx Std. Err. z P>|z|
## Xnwifeinc -0.00519005 0.00204820 -2.5340 0.011278 *
## Xeduc 0.05377731 0.01056074 5.0922 3.539e-07 ***
## Xexper 0.05005693 0.00782462 6.3974 1.581e-10 ***
## Xexpersq -0.00076692 0.00024768 -3.0965 0.001959 **
## Xage -0.02140302 0.00353973 -6.0465 1.480e-09 ***
## Xkidslt6 -0.35094982 0.04963897 -7.0700 1.549e-12 ***
## Xkidsge6 0.01461621 0.01818832 0.8036 0.421625
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##probit
probit<-glm(inlf~X,family=binomial(link="probit"), data=ocup_filhos)
summary(probit)
##
## Call:
## glm(formula = inlf ~ X, family = binomial(link = "probit"), data = ocup_filhos)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.2156 -0.9151 0.4315 0.8653 2.4553
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.2700736 0.5080782 0.532 0.59503
## Xnwifeinc -0.0120236 0.0049392 -2.434 0.01492 *
## Xeduc 0.1309040 0.0253987 5.154 2.55e-07 ***
## Xexper 0.1233472 0.0187587 6.575 4.85e-11 ***
## Xexpersq -0.0018871 0.0005999 -3.145 0.00166 **
## Xage -0.0528524 0.0084624 -6.246 4.22e-10 ***
## Xkidslt6 -0.8683247 0.1183773 -7.335 2.21e-13 ***
## Xkidsge6 0.0360056 0.0440303 0.818 0.41350
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 1029.7 on 752 degrees of freedom
## Residual deviance: 802.6 on 745 degrees of freedom
## AIC: 818.6
##
## Number of Fisher Scoring iterations: 4
# Efeito marginal médio
probitmfx(inlf~X, atmean=FALSE, start=NULL, data=ocup_filhos)
## Call:
## probitmfx(formula = inlf ~ X, data = ocup_filhos, atmean = FALSE,
## start = NULL)
##
## Marginal Effects:
## dF/dx Std. Err. z P>|z|
## Xnwifeinc -0.00361618 0.00146972 -2.4604 0.013876 *
## Xeduc 0.03937009 0.00726571 5.4186 6.006e-08 ***
## Xexper 0.03709734 0.00516823 7.1780 7.076e-13 ***
## Xexpersq -0.00056755 0.00017708 -3.2050 0.001351 **
## Xage -0.01589566 0.00235868 -6.7392 1.592e-11 ***
## Xkidslt6 -0.26115346 0.03190239 -8.1860 2.700e-16 ***
## Xkidsge6 0.01082889 0.01322413 0.8189 0.412859
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Efeito marginal na média
probitmfx(inlf~X,data=ocup_filhos)
## Call:
## probitmfx(formula = inlf ~ X, data = ocup_filhos)
##
## Marginal Effects:
## dF/dx Std. Err. z P>|z|
## Xnwifeinc -0.00469619 0.00192965 -2.4337 0.014945 *
## Xeduc 0.05112843 0.00992310 5.1525 2.571e-07 ***
## Xexper 0.04817690 0.00734505 6.5591 5.413e-11 ***
## Xexpersq -0.00073705 0.00023464 -3.1412 0.001683 **
## Xage -0.02064309 0.00330485 -6.2463 4.203e-10 ***
## Xkidslt6 -0.33914996 0.04634765 -7.3175 2.526e-13 ***
## Xkidsge6 0.01406306 0.01719895 0.8177 0.413546
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
detach(ocup_filhos)
############################################### Dados em Painel
###OLS
MQO<-lm(log(pob)~log(gini)+log(renda),data=painel_pob)
summary(MQO)
##
## Call:
## lm(formula = log(pob) ~ log(gini) + log(renda), data = painel_pob)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.38574 -0.05008 0.01704 0.06227 0.26326
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.72056 0.08019 96.275 <2e-16 ***
## log(gini) 0.38651 0.04414 8.757 <2e-16 ***
## log(renda) -0.66078 0.01369 -48.251 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1018 on 303 degrees of freedom
## Multiple R-squared: 0.8849, Adjusted R-squared: 0.8842
## F-statistic: 1165 on 2 and 303 DF, p-value: < 2.2e-16
yhat <-MQO$fitted
### Efeitos Fixos
#install.packages("plm")
library(plm)
## Loading required package: Formula
EF <-plm(log(pob)~log(gini)+log(renda), data=painel_pob, index=c("id", "ano"), model="within")
summary(EF)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = log(pob) ~ log(gini) + log(renda), data = painel_pob,
## model = "within", index = c("id", "ano"))
##
## Balanced Panel: n=102, T=3, N=306
##
## Residuals :
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.3002290 -0.0513266 0.0076317 0.0464454 0.2332787
##
## Coefficients :
## Estimate Std. Error t-value Pr(>|t|)
## log(gini) 0.51126 0.05792 8.827 5.151e-16 ***
## log(renda) -0.73021 0.01744 -41.870 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 18.882
## Residual Sum of Squares: 1.9403
## R-Squared: 0.89724
## Adj. R-Squared: 0.84484
## F-statistic: 881.882 on 2 and 202 DF, p-value: < 2.22e-16
### random effects
EA <-plm(log(pob)~log(gini)+log(renda), data=painel_pob, index=c("id", "ano"), model="random")
summary(EA)
## Oneway (individual) effect Random Effect Model
## (Swamy-Arora's transformation)
##
## Call:
## plm(formula = log(pob) ~ log(gini) + log(renda), data = painel_pob,
## model = "random", index = c("id", "ano"))
##
## Balanced Panel: n=102, T=3, N=306
##
## Effects:
## Warning in sqrt(sigma2): NaNs produzidos
## var std.dev share
## idiosyncratic 0.0096056 0.0980079 1.042
## individual -0.0003841 NA -0.042
## theta: -0.06599
##
## Residuals :
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.397085 -0.052396 0.016588 0.064991 0.270651
##
## Coefficients :
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 7.690561 0.079505 96.7308 < 2.2e-16 ***
## log(gini) 0.379003 0.043762 8.6605 2.846e-16 ***
## log(renda) -0.655797 0.013608 -48.1903 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 28.437
## Residual Sum of Squares: 3.2803
## R-Squared: 0.88465
## Adj. R-Squared: 0.88388
## F-statistic: 1161.84 on 2 and 303 DF, p-value: < 2.22e-16
### Teste de Hausman
phtest(EF, EA)
##
## Hausman Test
##
## data: log(pob) ~ log(gini) + log(renda)
## chisq = 47.176, df = 2, p-value = 5.7e-11
## alternative hypothesis: one model is inconsistent
### Teste de Breusch-Pagan
pool<- plm(log(pob)~ log(gini)+log(renda), data=painel_pob, index=c("id", "ano"), model="pooling")
summary(pool)
## Pooling Model
##
## Call:
## plm(formula = log(pob) ~ log(gini) + log(renda), data = painel_pob,
## model = "pooling", index = c("id", "ano"))
##
## Balanced Panel: n=102, T=3, N=306
##
## Residuals :
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.385737 -0.050084 0.017044 0.062274 0.263260
##
## Coefficients :
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 7.720562 0.080193 96.2750 < 2.2e-16 ***
## log(gini) 0.386510 0.044138 8.7569 < 2.2e-16 ***
## log(renda) -0.660784 0.013695 -48.2511 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 27.291
## Residual Sum of Squares: 3.1405
## R-Squared: 0.88492
## Adj. R-Squared: 0.88416
## F-statistic: 1165.02 on 2 and 303 DF, p-value: < 2.22e-16
plmtest(pool, type=c("bp"))
##
## Lagrange Multiplier Test - (Breusch-Pagan) for balanced panels
##
## data: log(pob) ~ log(gini) + log(renda)
## chisq = 0.0065517, df = 1, p-value = 0.9355
## alternative hypothesis: significant effects
### Testando efeitos fixos de tempo
EF_tempo<-plm(log(pob)~log(gini)+log(renda)+factor(ano), data=painel_pob, index=c("id", "ano"), model="within")
summary(EF_tempo)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = log(pob) ~ log(gini) + log(renda) + factor(ano),
## data = painel_pob, model = "within", index = c("id", "ano"))
##
## Balanced Panel: n=102, T=3, N=306
##
## Residuals :
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.2605659 -0.0392788 0.0039333 0.0391787 0.1816556
##
## Coefficients :
## Estimate Std. Error t-value Pr(>|t|)
## log(gini) 0.400768 0.065157 6.1508 4.124e-09 ***
## log(renda) -0.296417 0.046050 -6.4369 8.851e-10 ***
## factor(ano)2000 -0.111515 0.017111 -6.5171 5.705e-10 ***
## factor(ano)2010 -0.358826 0.035575 -10.0866 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 18.882
## Residual Sum of Squares: 1.2858
## R-Squared: 0.93191
## Adj. R-Squared: 0.89616
## F-statistic: 684.277 on 4 and 200 DF, p-value: < 2.22e-16
pFtest(EF_tempo, EF)
##
## F test for individual effects
##
## data: log(pob) ~ log(gini) + log(renda) + factor(ano)
## F = 50.907, df1 = 2, df2 = 200, p-value < 2.2e-16
## alternative hypothesis: significant effects
plmtest(EF, c("time"), type=("bp"))
##
## Lagrange Multiplier Test - time effects (Breusch-Pagan) for
## balanced panels
##
## data: log(pob) ~ log(gini) + log(renda)
## chisq = 166.05, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects