# "limpar" ambiente
rm(list = ls())
# Carregar bibliotecas
library(readxl)
library(readr)
library(mfx)
library(caret)
library(pROC)
library( ResourceSelection)
library( modEvA)
library( foreign)
library( stargazer) #Hlavac, Marek (2022)
library(ggplot2)
library(glm2)
library(mfx)
# Carregar dados m1 contém os contratos ativos
m1 <- read_excel("C:/Users/kassy/OneDrive - caen.ufc.br/1. CAEN/3. Doutorado/Thesis/Test banco mundial/m3test1.xlsx")
# Carregar dados m2 sem contratos ativos
m2 <- read_excel("C:/Users/kassy/OneDrive - caen.ufc.br/1. CAEN/3. Doutorado/Thesis/Test banco mundial/m3test2.xlsx")
summary(m1)
## país Project name Financial closure year InvestmentYear
## Length:8411 Length:8411 Min. :1998 Min. :1998
## Class :character Class :character 1st Qu.:2004 1st Qu.:2006
## Mode :character Mode :character Median :2011 Median :2011
## Mean :2010 Mean :2011
## 3rd Qu.:2016 3rd Qu.:2016
## Max. :2022 Max. :2022
##
## BidCriteria catbid Type of PPI catppp
## Length:8411 Min. :1.000 Length:8411 Min. :1.000
## Class :character 1st Qu.:1.000 Class :character 1st Qu.:2.000
## Mode :character Median :1.000 Mode :character Median :3.000
## Mean :2.363 Mean :2.506
## 3rd Qu.:4.000 3rd Qu.:3.000
## Max. :8.000 Max. :4.000
##
## Subtype of PPI catsubtype RelatedNames Project status
## Length:8411 Min. : 1.00 Length:8411 Length:8411
## Class :character 1st Qu.: 1.00 Class :character Class :character
## Mode :character Median : 2.00 Mode :character Mode :character
## Mean : 3.76
## 3rd Qu.: 5.00
## Max. :14.00
##
## status_dummy Subsector catsetor catsetor2
## Min. :0.00000 Length:8411 Min. : 1.000 Min. : 1.000
## 1st Qu.:0.00000 Class :character 1st Qu.: 2.000 1st Qu.: 2.000
## Median :0.00000 Mode :character Median : 2.000 Median : 2.000
## Mean :0.02818 Mean : 4.367 Mean : 4.325
## 3rd Qu.:0.00000 3rd Qu.: 7.000 3rd Qu.: 7.000
## Max. :1.00000 Max. :17.000 Max. :12.000
##
## catsetor3 ContractPeriod DirectGovtSupportValue PercentPrivate
## Min. :1.000 Min. : 1.00 Min. :0 Min. : 0.00
## 1st Qu.:1.000 1st Qu.:25.00 1st Qu.:0 1st Qu.:100.00
## Median :1.000 Median :25.33 Median :0 Median :100.00
## Mean :1.792 Mean :25.33 Mean :0 Mean : 89.35
## 3rd Qu.:2.000 3rd Qu.:30.00 3rd Qu.:0 3rd Qu.:100.00
## Max. :5.000 Max. :99.00 Max. :0 Max. :400.00
## NA's :7277
## TotalInvestment1 PhysicalAssets TotalDebtFunding
## Min. : 0.03 Min. : 0.000 Min. : 0.0
## 1st Qu.: 29.42 1st Qu.: 9.199 1st Qu.: 202.5
## Median : 93.00 Median : 52.000 Median : 202.5
## Mean : 242.15 Mean : 182.264 Mean : 202.5
## 3rd Qu.: 242.15 3rd Qu.: 163.050 3rd Qu.: 202.5
## Max. :35586.50 Max. :14800.000 Max. :13415.0
##
#summary(m2)
# Verificar missing values
colSums(is.na(m1))
## país Project name Financial closure year
## 0 975 0
## InvestmentYear BidCriteria catbid
## 0 0 0
## Type of PPI catppp Subtype of PPI
## 0 0 0
## catsubtype RelatedNames Project status
## 0 5399 0
## status_dummy Subsector catsetor
## 0 0 0
## catsetor2 catsetor3 ContractPeriod
## 0 0 0
## DirectGovtSupportValue PercentPrivate TotalInvestment1
## 7277 0 0
## PhysicalAssets TotalDebtFunding
## 0 0
#colSums(is.na(m2))
#chart.Correlation(m1, histogram=TRUE, pch=19)
ITm1=m1$TotalInvestment1
percentprivm1=m1$PercentPrivate
tm1=m1$ContractPeriod
km1=m1$PhysicalAssets
debtm1=m1$TotalDebtFunding
(\(ITm1\), Investimento Total), (\(percentprivm1\), Percentual da Participação Privada), (\(tm1\) Período de Contrato) , (\(km1\), Investimentos em Ativos Físicos), (\(debtm1\), Financiamento total da dívida)
catpppm1=m1$catppp
#catsubtypem1=m1$catsubtype
#catsetorm1=m1$catsetor
#catsetor2m1=m1$catsetor2
catsetor3m1=m1$catsetor3
catbidm1=m1$catbid
#Status do projeto## #DEPENDENTE
dummystatusm1=m1$status_dummy
(\(catpppm1\), Tipo de PPI) \(\Rightarrow\) 1. Brownfield (Brownfield são semelhantes aos Greenfields, exceto que, em vez de construir um novo ativo, a entidade privada assume um ativo existente e geralmente faz uma melhoria nele (reabilitação) ou o expande. Eles geralmente assumem as operações do ativo existente primeiro e, em seguida, realizam o investimento de capital. Tal como a Greenfields, a entidade privada normalmente tem responsabilidade operacional por um determinado período de tempo, durante o qual recupera o seu investimento da operação do projeto, após o que o projeto pode reverter para o setor público.)
Divestiture (Uma entidade privada compra uma participação acionária em uma empresa estatal por meio de uma venda de ativos, oferta pública ou programa de privatização em massa. Uma alienação, como uma concessão, dá ao operador privado total responsabilidade pela operação, manuntenção e investimento.)
Greenfield project (Uma entidade privada ou uma joint venture público-privada constrói e explora uma nova instalação durante o período especificado no contrato de projeto. A entidade privada assume grande parte do risco financeiro e operacional e recupera seus investimentos ao longo da vida do projeto.)
#textual type = factor(type) sector = factor(sector)
# numericamente
catpppm1 = factor(catpppm1)
#catsetorm1 = factor(catsetorm1)
#catsetor2m1 = factor(catsetor2m1)
catsetor3m1 = factor(catsetor3m1)
catbidm1 = factor(catbidm1)
#catsubtypem1 = factor(catsubtypem1)
ITm2=m2$TotalInvestment1
percentprivpubm2=m2$PercentPrivate
tm2=m2$ContractPeriod
km2=m2$PhysicalAssets
debtm2=m2$TotalDebtFunding
catpppm2=m2$catppp
#catsubtypem2=m2$catsubtype
#catsetorm2=m2$catsetor
#catsetor2m2=m2$catsetor2
catsetor3m2=m2$catsetor3
catbidm2 = m2$catbid
#Status do projeto## #DEPENDENTE
dummystatusm2=m2$status_dummy
#textual type = factor(type) sector = factor(sector)
# numericamente
catpppm2 = factor(catpppm2)
#catsetorm2 = factor(catsetorm2)
#catsetor2m2 = factor(catsetor2m2)
catsetor3m2 = factor(catsetor3m2)
#catsubtypem2 = factor(catsubtypem2)
catbidm2 = factor(catbidm2)
m1log=glm(dummystatusm1~ ITm1 + km1 + tm1 + catpppm1 + catbidm1 + catsetor3m1 + debtm1 + percentprivm1 , family = binomial(link = "logit"), data=m1)
summary(m1log)
##
## Call:
## glm(formula = dummystatusm1 ~ ITm1 + km1 + tm1 + catpppm1 + catbidm1 +
## catsetor3m1 + debtm1 + percentprivm1, family = binomial(link = "logit"),
## data = m1)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.9710443 0.3958318 -4.979 6.37e-07 ***
## ITm1 -0.0002954 0.0002739 -1.078 0.28092
## km1 0.0002747 0.0003642 0.754 0.45072
## tm1 -0.0044601 0.0094932 -0.470 0.63849
## catpppm12 -0.2520811 0.2342114 -1.076 0.28179
## catpppm13 -1.5760158 0.1919183 -8.212 < 2e-16 ***
## catpppm14 -0.3909013 0.3087687 -1.266 0.20551
## catbidm12 -0.9847469 1.0178863 -0.967 0.33332
## catbidm13 0.6791630 0.4286901 1.584 0.11313
## catbidm14 -0.3189704 0.2113807 -1.509 0.13130
## catbidm15 -1.3867248 0.5926668 -2.340 0.01929 *
## catbidm16 -0.5155540 0.4786053 -1.077 0.28139
## catbidm17 -0.0876062 0.3588472 -0.244 0.80713
## catbidm18 -1.0362512 0.4637134 -2.235 0.02544 *
## catsetor3m12 -0.0583373 0.2031436 -0.287 0.77398
## catsetor3m13 0.2955180 0.2077791 1.422 0.15495
## catsetor3m14 1.1178148 0.2799499 3.993 6.53e-05 ***
## catsetor3m15 -2.0769276 1.0162089 -2.044 0.04097 *
## debtm1 0.0002434 0.0003423 0.711 0.47713
## percentprivm1 -0.0071389 0.0024072 -2.966 0.00302 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 2159.1 on 8410 degrees of freedom
## Residual deviance: 1969.6 on 8391 degrees of freedom
## AIC: 2009.6
##
## Number of Fisher Scoring iterations: 8
anova(m1log, test = "Chisq")
## Analysis of Deviance Table
##
## Model: binomial, link: logit
##
## Response: dummystatusm1
##
## Terms added sequentially (first to last)
##
##
## Df Deviance Resid. Df Resid. Dev Pr(>Chi)
## NULL 8410 2159.1
## ITm1 1 0.015 8409 2159.1 0.903995
## km1 1 1.203 8408 2157.9 0.272782
## tm1 1 0.259 8407 2157.6 0.611072
## catpppm1 3 123.643 8404 2034.0 < 2.2e-16 ***
## catbidm1 7 25.467 8397 2008.5 0.000627 ***
## catsetor3m1 4 30.119 8393 1978.4 4.629e-06 ***
## debtm1 1 0.707 8392 1977.7 0.400474
## percentprivm1 1 8.099 8391 1969.6 0.004429 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#stargazer(m1log, title="Resultados",type = "text")
logitor(dummystatusm1~ITm1 + km1 + tm1 + catbidm1 + catpppm1, data=m1)
## Call:
## logitor(formula = dummystatusm1 ~ ITm1 + km1 + tm1 + catbidm1 +
## catpppm1, data = m1)
##
## Odds Ratio:
## OddsRatio Std. Err. z P>|z|
## ITm1 0.99990998 0.00022127 -0.4068 0.68415
## km1 1.00018600 0.00027232 0.6831 0.49456
## tm1 0.99520504 0.00928573 -0.5151 0.60646
## catbidm12 0.32517710 0.33027244 -1.1061 0.26870
## catbidm13 1.53205361 0.63437909 1.0303 0.30288
## catbidm14 0.67658155 0.13814736 -1.9135 0.05569 .
## catbidm15 0.23679207 0.13959124 -2.4437 0.01454 *
## catbidm16 0.40903207 0.19072993 -1.9172 0.05522 .
## catbidm17 0.73583321 0.25329269 -0.8911 0.37286
## catbidm18 0.33549949 0.15432306 -2.3743 0.01758 *
## catpppm12 1.01399407 0.20154047 0.0699 0.94426
## catpppm13 0.19920576 0.03295806 -9.7518 < 2e-16 ***
## catpppm14 0.65625399 0.19719419 -1.4018 0.16099
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#exp(cbind(OR=coef(m1), confint(m1)))
m2log=glm(dummystatusm2~ ITm2 + km2 + tm2 + catpppm2 + catbidm2 + catsetor3m2 + debtm2 + percentprivpubm2 , family = binomial(link = "logit"), data=m2)
summary(m2log)
##
## Call:
## glm(formula = dummystatusm2 ~ ITm2 + km2 + tm2 + catpppm2 + catbidm2 +
## catsetor3m2 + debtm2 + percentprivpubm2, family = binomial(link = "logit"),
## data = m2)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -4.081e+00 2.257e+00 -1.808 0.07058 .
## ITm2 -6.360e-03 2.825e-03 -2.252 0.02435 *
## km2 1.093e-02 4.007e-03 2.728 0.00637 **
## tm2 2.522e-01 4.192e-02 6.016 1.79e-09 ***
## catpppm22 1.682e+01 1.508e+03 0.011 0.99110
## catpppm23 -2.678e-02 7.834e-01 -0.034 0.97273
## catpppm24 5.384e-01 9.457e-01 0.569 0.56914
## catbidm22 1.379e+01 1.075e+04 0.001 0.99898
## catbidm23 1.783e+01 3.839e+03 0.005 0.99629
## catbidm24 3.447e+00 1.370e+00 2.516 0.01187 *
## catbidm25 -7.702e-01 1.357e+00 -0.568 0.57022
## catbidm26 2.799e+00 1.085e+00 2.581 0.00986 **
## catbidm27 8.794e-02 1.029e+00 0.085 0.93191
## catbidm28 1.737e+00 1.365e+00 1.272 0.20328
## catsetor3m22 -1.791e+00 8.093e-01 -2.213 0.02690 *
## catsetor3m23 -7.045e-02 7.904e-01 -0.089 0.92898
## catsetor3m24 2.011e+00 1.140e+00 1.765 0.07764 .
## catsetor3m25 1.752e+01 1.075e+04 0.002 0.99870
## debtm2 4.412e-03 8.496e-03 0.519 0.60350
## percentprivpubm2 7.922e-03 9.807e-03 0.808 0.41922
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 426.52 on 343 degrees of freedom
## Residual deviance: 139.76 on 324 degrees of freedom
## AIC: 179.76
##
## Number of Fisher Scoring iterations: 18
anova(m2log, test = "Chisq")
## Analysis of Deviance Table
##
## Model: binomial, link: logit
##
## Response: dummystatusm2
##
## Terms added sequentially (first to last)
##
##
## Df Deviance Resid. Df Resid. Dev Pr(>Chi)
## NULL 343 426.52
## ITm2 1 3.471 342 423.04 0.0624376 .
## km2 1 74.318 341 348.73 < 2.2e-16 ***
## tm2 1 160.914 340 187.81 < 2.2e-16 ***
## catpppm2 3 17.171 337 170.64 0.0006516 ***
## catbidm2 7 15.862 330 154.78 0.0264033 *
## catsetor3m2 4 14.091 326 140.69 0.0070110 **
## debtm2 1 0.276 325 140.41 0.5992099
## percentprivpubm2 1 0.648 324 139.76 0.4207488
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#stargazer(m1log, title="Resultados",type = "text")
logitor(dummystatusm2~ITm2 + km2 + tm2 + catbidm2 + catpppm2, data=m2)
## Call:
## logitor(formula = dummystatusm2 ~ ITm2 + km2 + tm2 + catbidm2 +
## catpppm2, data = m2)
##
## Odds Ratio:
## OddsRatio Std. Err. z P>|z|
## ITm2 9.9500e-01 1.7577e-03 -2.8396 0.004517 **
## km2 1.0104e+00 3.8517e-03 2.7063 0.006803 **
## tm2 1.2925e+00 4.7375e-02 7.0010 2.541e-12 ***
## catbidm22 5.0946e+05 5.4788e+09 0.0012 0.999025
## catbidm23 2.8335e+07 1.0665e+11 0.0046 0.996363
## catbidm24 2.3242e+01 2.9525e+01 2.4765 0.013269 *
## catbidm25 1.3490e+00 1.4629e+00 0.2761 0.782496
## catbidm26 1.0697e+01 1.1424e+01 2.2192 0.026473 *
## catbidm27 1.0001e+00 1.0515e+00 0.0001 0.999941
## catbidm28 7.5596e+00 9.8920e+00 1.5459 0.122133
## catpppm22 6.5423e+07 1.0069e+11 0.0117 0.990670
## catpppm23 3.9146e+00 2.4033e+00 2.2229 0.026220 *
## catpppm24 4.9977e+00 3.8802e+00 2.0724 0.038231 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#exp(cbind(OR=coef(m1), confint(m1)))