#HOLA 1. Cargar data
link="https://docs.google.com/spreadsheets/d/e/2PACX-1vSPZ-j8hoFfZbf5qNnAf0tNIiaucIPMVljywf5s4B3sXzGtB0xbbpIw3Zr8o_ulTcFo21qjFwDOZ32t/pub?gid=2057947663&single=true&output=csv"
pavidata=read.csv(link,stringsAsFactors = T)
str(pavidata)
## 'data.frame': 1096 obs. of 8 variables:
## $ poblacioncienmil: num 20.9155 0.2406 0.0398 0.0558 0.2723 ...
## $ nbi : num 12.2 33.8 28.5 33.1 27.1 ...
## $ consejocomunal : num 0 0 0 0 0 0 0 0 0 0 ...
## $ priorizado : num 0 1 0 0 0 0 0 0 1 0 ...
## $ uribista : num 0 1 1 1 1 1 1 1 1 NA ...
## $ ejecucion : num 0 0 0 0 0 0 0 0 0 0 ...
## $ apropiaciondolar: num 102.17 4.19 1.59 0 0 ...
## $ pctopo : num 14.82 14.51 15.08 6.15 47.31 ...
Hacer ajustes:
# pavidata[,c("consejocomunal","priorizado","uribista","ejecucion)]
pavidata[,(3:6)]=lapply(pavidata[,(3:6)],as.factor)
3.1 simple:
summary(pavidata)
## poblacioncienmil nbi consejocomunal priorizado uribista
## Min. : 0.00158 Min. : 5.36 0:1036 0:820 0 :332
## 1st Qu.: 0.07422 1st Qu.:28.35 1: 60 1:276 1 :560
## Median : 0.13998 Median :41.30 NA's:204
## Mean : 0.40470 Mean :42.96
## 3rd Qu.: 0.26255 3rd Qu.:55.48
## Max. :69.26836 Max. :98.81
## NA's :30
## ejecucion apropiaciondolar pctopo
## 0:1055 Min. : 0.000 Min. : 0.000
## 1: 41 1st Qu.: 0.000 1st Qu.: 5.922
## Median : 0.000 Median :20.308
## Mean : 8.276 Mean :27.874
## 3rd Qu.: 9.385 3rd Qu.:45.711
## Max. :132.643 Max. :99.419
## NA's :7
Modificar orden:
newOrder=c("apropiaciondolar","pctopo","uribista","priorizado","consejocomunal","ejecucion","poblacioncienmil","nbi")
pavidata=pavidata[,newOrder]
Primer intento:
library("papeR")
## Loading required package: car
## Loading required package: carData
## Loading required package: xtable
## Registered S3 method overwritten by 'papeR':
## method from
## Anova.lme car
##
## Attaching package: 'papeR'
## The following object is masked from 'package:utils':
##
## toLatex
summarize(pavidata)
## Factors are dropped from the summary
## N Missing Mean SD Min Q1 Median Q3 Max
## 1 apropiaciondolar 1096 0 8.28 16.04 0.00 0.00 0.00 9.40 132.64
## 2 pctopo 1089 7 27.87 25.59 0.00 5.92 20.31 45.71 99.42
## 3 poblacioncienmil 1096 0 0.40 2.39 0.00 0.07 0.14 0.26 69.27
## 4 nbi 1066 30 42.96 18.70 5.36 28.34 41.30 55.49 98.81
Sin mensajes:
library("papeR")
summarize(pavidata)
## N Missing Mean SD Min Q1 Median Q3 Max
## 1 apropiaciondolar 1096 0 8.28 16.04 0.00 0.00 0.00 9.40 132.64
## 2 pctopo 1089 7 27.87 25.59 0.00 5.92 20.31 45.71 99.42
## 3 poblacioncienmil 1096 0 0.40 2.39 0.00 0.07 0.14 0.26 69.27
## 4 nbi 1066 30 42.96 18.70 5.36 28.34 41.30 55.49 98.81
summarize(pavidata, type = "factor")
## Non-factors are dropped from the summary
## Level N %
## 1 uribista 0 332 30.3
## 2 1 560 51.1
## 3 <Missing> 204 18.6
## 4 priorizado 0 820 74.8
## 5 1 276 25.2
## 6 consejocomunal 0 1036 94.5
## 7 1 60 5.5
## 8 ejecucion 0 1055 96.3
## 9 1 41 3.7
Sin cuartiles:
summarize(pavidata,quantiles = FALSE)
## N Missing Mean SD
## 1 apropiaciondolar 1096 0 8.28 16.04
## 2 pctopo 1089 7 27.87 25.59
## 3 poblacioncienmil 1096 0 0.40 2.39
## 4 nbi 1066 30 42.96 18.70
Sin valores perdidos:
summarize(pavidata,quantiles = FALSE,show.NAs=FALSE)
## Factors are dropped from the summary
## N Mean SD
## 1 apropiaciondolar 1096 8.28 16.04
## 2 pctopo 1089 27.87 25.59
## 3 poblacioncienmil 1096 0.40 2.39
## 4 nbi 1066 42.96 18.70
Etiquetas nuevas:
newVarLabels=c("Apropiacion Presupuestal (millones de US$)", "Votos Oposición (%)", "Alcalde coalición Uribista", "Prioridad Técnica","Consejo Comunal","Consejo Comunal con ejecucion d recursos", "Poblacion (100 000 habs.", "NBI")
newColLabels=c("Variables","N" ,"Promedio", "Desv. Tipica")
##
summarize(pavidata,quantiles=F,
show.NAs=FALSE,
variable.labels=newVarLabels,
colnames=newColLabels)
## Factors are dropped from the summary
## Variables N Promedio Desv. Tipica
## 1 Apropiacion Presupuestal (millones de US$) 1096 8.28 16.04
## 2 Votos Oposición (%) 1089 27.87 25.59
## 3 Poblacion (100 000 habs. 1096 0.40 2.39
## 4 NBI 1066 42.96 18.70
Para tu pdf:
##
# header-includes:
# \usepackage{booktabs}
##
xtable(summarize(pavidata,quantiles=F,
show.NAs=FALSE,
variable.labels=newVarLabels,
colnames=newColLabels))
## Factors are dropped from the summary
## NOTE: Output requires \usepackage{booktabs} in your preamble.
# solo para pdf
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
stargazer(pavidata, type = "latex",summary.stat = c("n", "min", "sd","max","mean"))
% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu % Date and time: Thu, Jul 09, 2020 - 20:26:57
regresion=lm(apropiaciondolar~.,data=pavidata)
summary(regresion)
##
## Call:
## lm(formula = apropiaciondolar ~ ., data = pavidata)
##
## Residuals:
## Min 1Q Median 3Q Max
## -60.201 -8.207 -5.875 2.505 92.488
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 14.13182 1.67651 8.429 < 2e-16 ***
## pctopo -0.03096 0.02126 -1.456 0.14563
## uribista1 -2.57184 1.09188 -2.355 0.01872 *
## priorizado1 -2.21395 1.18715 -1.865 0.06253 .
## consejocomunal1 14.05017 2.32452 6.044 2.23e-09 ***
## ejecucion1 2.95688 2.80758 1.053 0.29255
## poblacioncienmil 1.83866 0.20024 9.182 < 2e-16 ***
## nbi -0.09292 0.02941 -3.160 0.00163 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 15.38 on 868 degrees of freedom
## (220 observations deleted due to missingness)
## Multiple R-squared: 0.1751, Adjusted R-squared: 0.1684
## F-statistic: 26.32 on 7 and 868 DF, p-value: < 2.2e-16
stargazer(regresion, type = "html")
| Dependent variable: | |
| apropiaciondolar | |
| pctopo | -0.031 |
| (0.021) | |
| uribista1 | -2.572** |
| (1.092) | |
| priorizado1 | -2.214* |
| (1.187) | |
| consejocomunal1 | 14.050*** |
| (2.325) | |
| ejecucion1 | 2.957 |
| (2.808) | |
| poblacioncienmil | 1.839*** |
| (0.200) | |
| nbi | -0.093*** |
| (0.029) | |
| Constant | 14.132*** |
| (1.677) | |
| Observations | 876 |
| R2 | 0.175 |
| Adjusted R2 | 0.168 |
| Residual Std. Error | 15.378 (df = 868) |
| F Statistic | 26.316*** (df = 7; 868) |
| Note: | p<0.1; p<0.05; p<0.01 |
newVarLabels2=c( "Votos Oposición (%)", "Alcalde coalición Uribista", "Prioridad Técnica","Consejo Comunal","Consejo Comunal con ejecucion d recursos", "Poblacion (100 000 habs.", "NBI", "Constante")
depLabel="Apropiacion Presupuestal (millones de US$)"
stargazer(regresion, type = "html",
covariate.labels =newVarLabels2,
dep.var.caption = "Variable Dependiente",
dep.var.labels = depLabel)
| Variable Dependiente | |
| Apropiacion Presupuestal (millones de US) | |
| Votos Oposición (%) | -0.031 |
| (0.021) | |
| Alcalde coalición Uribista | -2.572** |
| (1.092) | |
| Prioridad Técnica | -2.214* |
| (1.187) | |
| Consejo Comunal | 14.050*** |
| (2.325) | |
| Consejo Comunal con ejecucion d recursos | 2.957 |
| (2.808) | |
| Poblacion (100 000 habs. | 1.839*** |
| (0.200) | |
| NBI | -0.093*** |
| (0.029) | |
| Constante | 14.132*** |
| (1.677) | |
| Observations | 876 |
| R2 | 0.175 |
| Adjusted R2 | 0.168 |
| Residual Std. Error | 15.378 (df = 868) |
| F Statistic | 26.316*** (df = 7; 868) |
| Note: | p<0.1; p<0.05; p<0.01 |
regresion2=lm(apropiaciondolar~.,data=pavidata[,-c(7,8)])
newVarLabels3=c( "Votos Oposición (%)", "Alcalde coalición Uribista", "Prioridad Técnica","Consejo Comunal","Consejo Comunal con ejecucion d recursos", "Constante")
depLabel="Apropiacion Presupuestal (millones de US$)"
stargazer(regresion2, type = "html",
covariate.labels =newVarLabels3,
dep.var.caption = "Variable Dependiente",
dep.var.labels = depLabel)
| Variable Dependiente | |
| Apropiacion Presupuestal (millones de US) | |
| Votos Oposición (%) | -0.040* |
| (0.022) | |
| Alcalde coalición Uribista | -2.908** |
| (1.139) | |
| Prioridad Técnica | -1.204 |
| (1.240) | |
| Consejo Comunal | 18.989*** |
| (2.366) | |
| Consejo Comunal con ejecucion d recursos | 1.984 |
| (2.946) | |
| Constante | 10.968*** |
| (1.207) | |
| Observations | 888 |
| R2 | 0.078 |
| Adjusted R2 | 0.073 |
| Residual Std. Error | 16.173 (df = 882) |
| F Statistic | 14.998*** (df = 5; 882) |
| Note: | p<0.1; p<0.05; p<0.01 |
stargazer(regresion2,regresion,type='html',
covariate.labels =newVarLabels2,
dep.var.caption = "Variable Dependiente",
dep.var.labels = depLabel)
| Variable Dependiente | ||
| Apropiacion Presupuestal (millones de US) | ||
| (1) | (2) | |
| Votos Oposición (%) | -0.040* | -0.031 |
| (0.022) | (0.021) | |
| Alcalde coalición Uribista | -2.908** | -2.572** |
| (1.139) | (1.092) | |
| Prioridad Técnica | -1.204 | -2.214* |
| (1.240) | (1.187) | |
| Consejo Comunal | 18.989*** | 14.050*** |
| (2.366) | (2.325) | |
| Consejo Comunal con ejecucion d recursos | 1.984 | 2.957 |
| (2.946) | (2.808) | |
| Poblacion (100 000 habs. | 1.839*** | |
| (0.200) | ||
| NBI | -0.093*** | |
| (0.029) | ||
| Constante | 10.968*** | 14.132*** |
| (1.207) | (1.677) | |
| Observations | 888 | 876 |
| R2 | 0.078 | 0.175 |
| Adjusted R2 | 0.073 | 0.168 |
| Residual Std. Error | 16.173 (df = 882) | 15.378 (df = 868) |
| F Statistic | 14.998*** (df = 5; 882) | 26.316*** (df = 7; 868) |
| Note: | p<0.1; p<0.05; p<0.01 | |
library(jtools) # broom / ggstance / broom.mixed
plot_summs(regresion2,regresion)
## Registered S3 methods overwritten by 'broom':
## method from
## tidy.glht jtools
## tidy.summary.glht jtools
## Loading required namespace: broom.mixed
## Registered S3 methods overwritten by 'broom.mixed':
## method from
## augment.lme broom
## augment.merMod broom
## glance.lme broom
## glance.merMod broom
## glance.stanreg broom
## tidy.brmsfit broom
## tidy.gamlss broom
## tidy.lme broom
## tidy.merMod broom
## tidy.rjags broom
## tidy.stanfit broom
## tidy.stanreg broom