library(htmltab)
url= "https://en.wikipedia.org/wiki/List_of_freedom_indices"
path="/html/body/div[3]/div[3]/div[5]/div[1]/table[2]"
demo = htmltab(url, path, encoding = "UTF-8")
head(demo)
## Country Freedom in the World 2021
## 2 Â Afghanistan not free
## 3 Â Albania partly free
## 4 Â Algeria not free
## 5 Â Andorra free
## 6 Â Angola not free
## 7 Â Antigua and Barbuda free
## 2021 Index of Economic Freedom 2021 Press Freedom Index 2020 Democracy Index
## 2 mostly unfree difficult situation authoritarian regime
## 3 moderately free noticeable problems flawed democracy
## 4 repressed difficult situation authoritarian regime
## 5 n/a satisfactory situation n/a
## 6 mostly unfree noticeable problems authoritarian regime
## 7 n/a satisfactory situation n/a
#pregunta 1 y 2
#Los avances que habia hecho en esta pregunta lo elimine para poder generar mi archivo html
#pregunta 3
mortality="https://github.com/Fiorella2021/examen_2_unemployement/raw/main/mortality.csv"
datosmortality=read.csv(mortality)
unemployment="https://github.com/Fiorella2021/examen_2_unemployement/raw/main/unemployment.csv"
datosunemployment=read.csv(unemployment)
migracion="https://github.com/Fiorella2021/examen_2_unemployement/raw/main/migration.csv"
datosmigracionr=read.csv(migracion)
#juntemos la base de datos
colnames(datosmortality)[3] <- "valuemortality"
colnames(datosunemployment)[3] <- "valueunemployment"
colnames(datosmigracionr)[3] <- "valuemigracionr"
#Realizamos el merge
fusion = merge(datosmortality, datosunemployment, by= "name", all.x = T)
fusion2 = merge(fusion, datosmigracionr, by= "name", all.x = T)
#limpiamos la base de datos
#Eliminamos las columnas que no necesitamos
fusion2 = fusion2[,-c(4,5,6,7,9,10,11,12,14,15,16)]
head(demo)
## Country Freedom in the World 2021
## 2 Â Afghanistan not free
## 3 Â Albania partly free
## 4 Â Algeria not free
## 5 Â Andorra free
## 6 Â Angola not free
## 7 Â Antigua and Barbuda free
## 2021 Index of Economic Freedom 2021 Press Freedom Index 2020 Democracy Index
## 2 mostly unfree difficult situation authoritarian regime
## 3 moderately free noticeable problems flawed democracy
## 4 repressed difficult situation authoritarian regime
## 5 n/a satisfactory situation n/a
## 6 mostly unfree noticeable problems authoritarian regime
## 7 n/a satisfactory situation n/a
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
str(fusion2)
## 'data.frame': 226 obs. of 5 variables:
## $ name : chr "Afghanistan" "Albania" "Algeria" "American Samoa" ...
## $ slug.x : chr "afghanistan" "albania" "algeria" "american-samoa" ...
## $ valuemortality : num 106.8 11.1 20.2 10.2 3.5 ...
## $ valueunemployment: num 23.9 5.83 11.7 29.8 3.7 6.6 8 11 9.84 18.9 ...
## $ valuemigracionr : num -0.1 -3.24 -0.84 -32.18 0 ...
modelo1=formula(valuemortality~valueunemployment+valuemigracionr)
reg1=lm(modelo1, data=fusion2)
stargazer(reg1, type="text")
##
## ===============================================
## Dependent variable:
## ---------------------------
## valuemortality
## -----------------------------------------------
## valueunemployment 0.475***
## (0.114)
##
## valuemigracionr -0.345*
## (0.199)
##
## Constant 14.337***
## (1.680)
##
## -----------------------------------------------
## Observations 214
## R2 0.091
## Adjusted R2 0.082
## Residual Std. Error 17.408 (df = 211)
## F Statistic 10.576*** (df = 2; 211)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
Encontramos que mortalidad tiene relación con ambas, si consideramos un pvalor del 0.1.
fusion3=fusion2
str(fusion3)
## 'data.frame': 226 obs. of 5 variables:
## $ name : chr "Afghanistan" "Albania" "Algeria" "American Samoa" ...
## $ slug.x : chr "afghanistan" "albania" "algeria" "american-samoa" ...
## $ valuemortality : num 106.8 11.1 20.2 10.2 3.5 ...
## $ valueunemployment: num 23.9 5.83 11.7 29.8 3.7 6.6 8 11 9.84 18.9 ...
## $ valuemigracionr : num -0.1 -3.24 -0.84 -32.18 0 ...
modelo3=formula(valueunemployment~valuemortality+valuemigracionr)
reg2=lm(modelo3, data=fusion3)
summary(reg2)
##
## Call:
## lm(formula = modelo3, data = fusion3)
##
## Residuals:
## Min 1Q Median 3Q Max
## -17.933 -5.445 -2.554 1.694 61.569
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.26159 1.01795 7.134 1.54e-11 ***
## valuemortality 0.16088 0.03851 4.178 4.31e-05 ***
## valuemigracionr -0.01898 0.11692 -0.162 0.871
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.13 on 211 degrees of freedom
## (12 observations deleted due to missingness)
## Multiple R-squared: 0.07834, Adjusted R-squared: 0.06961
## F-statistic: 8.968 on 2 and 211 DF, p-value: 0.0001829
stargazer(reg2, type="text")
##
## ===============================================
## Dependent variable:
## ---------------------------
## valueunemployment
## -----------------------------------------------
## valuemortality 0.161***
## (0.039)
##
## valuemigracionr -0.019
## (0.117)
##
## Constant 7.262***
## (1.018)
##
## -----------------------------------------------
## Observations 214
## R2 0.078
## Adjusted R2 0.070
## Residual Std. Error 10.132 (df = 211)
## F Statistic 8.968*** (df = 2; 211)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
#Encontramos que por cada punto que aumente la migración, el desempleo disminuye en 0.019 pues #el desempleo esta afectado de manera directa por la mortalidad y de manera inversa por la #migracion
fusion4=fusion2
str(fusion4)
## 'data.frame': 226 obs. of 5 variables:
## $ name : chr "Afghanistan" "Albania" "Algeria" "American Samoa" ...
## $ slug.x : chr "afghanistan" "albania" "algeria" "american-samoa" ...
## $ valuemortality : num 106.8 11.1 20.2 10.2 3.5 ...
## $ valueunemployment: num 23.9 5.83 11.7 29.8 3.7 6.6 8 11 9.84 18.9 ...
## $ valuemigracionr : num -0.1 -3.24 -0.84 -32.18 0 ...
modelo4=formula(valuemigracionr~valuemortality+valueunemployment)
reg3=lm(modelo4, data=fusion4)
summary(reg3)
##
## Call:
## lm(formula = modelo4, data = fusion4)
##
## Residuals:
## Min 1Q Median 3Q Max
## -31.730 -1.120 0.378 1.884 35.167
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.16120 0.66759 0.241 0.8094
## valuemortality -0.04052 0.02343 -1.730 0.0851 .
## valueunemployment -0.00658 0.04053 -0.162 0.8712
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.965 on 211 degrees of freedom
## (12 observations deleted due to missingness)
## Multiple R-squared: 0.01606, Adjusted R-squared: 0.006738
## F-statistic: 1.722 on 2 and 211 DF, p-value: 0.1811
stargazer(reg3, type="text")
##
## ===============================================
## Dependent variable:
## ---------------------------
## valuemigracionr
## -----------------------------------------------
## valuemortality -0.041*
## (0.023)
##
## valueunemployment -0.007
## (0.041)
##
## Constant 0.161
## (0.668)
##
## -----------------------------------------------
## Observations 214
## R2 0.016
## Adjusted R2 0.007
## Residual Std. Error 5.965 (df = 211)
## F Statistic 1.722 (df = 2; 211)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
#Encontramos que migración tiene relación inversa débil con ambas