Aprendiendo a abrir la data usando la función read_csv() je
# Paquetes que se usarán #
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(data.table)
##
## Attaching package: 'data.table'
## The following objects are masked from 'package:dplyr':
##
## between, first, last
library(devtools)
## Loading required package: usethis
library(foreign)
library(rio)
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
library(corrplot)
## corrplot 0.92 loaded
library(lm.beta)
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
data <- read.spss("usa.sav",
use.value.labels = T,
to.data.frame=TRUE)
## Warning in read.spss("usa.sav", use.value.labels = T, to.data.frame = TRUE):
## Undeclared level(s) 0, 1, 2, 3, 5, 7, 9, 10, 12, 15, 20, 25, 28, 30, 31, 32, 33,
## 35, 40, 42, 45, 46, 47, 48, 49, 50, 51, 52, 55, 58, 60, 65, 66, 68, 70, 75, 78,
## 79, 80, 85, 86, 87, 89, 90, 93, 95, 100 added in variable: clintpre
## Warning in read.spss("usa.sav", use.value.labels = T, to.data.frame = TRUE):
## Undeclared level(s) 0, 1, 2, 3, 5, 6, 8, 10, 14, 15, 20, 25, 30, 32, 33, 35,
## 40, 45, 46, 48, 49, 50, 51, 52, 54, 55, 57, 59, 60, 63, 65, 66, 70, 72, 75, 76,
## 79, 80, 82, 83, 84, 85, 87, 88, 90, 92, 94, 95, 98, 99, 100 added in variable:
## gorepre
## Warning in read.spss("usa.sav", use.value.labels = T, to.data.frame = TRUE):
## Undeclared level(s) 0, 1, 2, 4, 5, 6, 7, 10, 15, 16, 20, 25, 30, 35, 40, 45, 48,
## 49, 50, 51, 52, 55, 60, 62, 65, 66, 67, 68, 69, 70, 75, 77, 78, 79, 80, 85, 90,
## 92, 95, 96, 98, 99, 100 added in variable: gbushpre
## Warning in read.spss("usa.sav", use.value.labels = T, to.data.frame = TRUE):
## Undeclared level(s) 0, 1, 2, 3, 4, 5, 9, 10, 15, 20, 25, 30, 32, 35, 40, 45,
## 49, 50, 51, 52, 55, 60, 63, 65, 69, 70, 75, 80, 85, 88, 89, 90, 95, 98, 99, 100
## added in variable: clintpst
## Warning in read.spss("usa.sav", use.value.labels = T, to.data.frame = TRUE):
## Undeclared level(s) 0, 1, 2, 3, 5, 8, 10, 15, 20, 25, 30, 33, 35, 39, 40, 43,
## 45, 49, 50, 51, 54, 55, 57, 60, 65, 70, 72, 75, 76, 78, 79, 80, 82, 85, 86, 87,
## 89, 90, 94, 95, 96, 97, 98, 99, 100 added in variable: gorepst
## Warning in read.spss("usa.sav", use.value.labels = T, to.data.frame = TRUE):
## Undeclared level(s) 0, 1, 2, 3, 5, 8, 10, 15, 20, 25, 30, 35, 38, 40, 41, 45,
## 49, 50, 51, 54, 55, 60, 65, 67, 69, 70, 73, 75, 78, 80, 85, 87, 90, 94, 95, 98,
## 99, 100 added in variable: gbushpst
AHORA: A. Filtrar los casos de las personas mayores de 60 años que sí votaron en el 2000 (voto00), ordenado de manera ascendente en cuanto a la edad y que estos casos que se seleccionen las variables cómo se considera políticamente (consipol) e interés en las campañas (intecamp).
A=filter(data,edad>60,voto00=="Votó")%>%arrange(.,(edad))%>%select(., consipol, intecamp)
View(A)
B. Obtener la diferencia de la aprobación antes y después de las elecciones de Clinton, ordenado de manera descendente en cuanto a la diferencia de aprobación y que se seleccionen las variables “Politicamente se considera” (consipol) y “Diferencia de la aprobación antes y después de las elecciones de Clinton”.
data$clintpst<- as.numeric(data$clintpst)
data$clintpre<- as.numeric(data$clintpre)
B=mutate(data, difclint= clintpst- clintpre)%>%
arrange(., desc(difclint))%>%
select(., consipol, difclint)
View(B)
ESTO ES POR SI QUIERES EVALUAR SOLO LA DIFERENCIA: ES UNA OPCIÓN, PERO SOLO LO HACE A PARTE DE LA BASE, NO PUEDES SELECCIONAR NADA, PORQUE ESTÁ SOLO SOLIN SOLITO…
data$clintpst<- as.numeric(data$clintpst)
data$clintpre<- as.numeric(data$clintpre)
diferencia=transmute(data, difclint = clintpst - clintpre)%>%arrange(., desc(difclint))
View(diferencia)