forked from DataAccess2020/Class_exercise_1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript.R
More file actions
70 lines (51 loc) · 2.61 KB
/
Script.R
File metadata and controls
70 lines (51 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
library(tidyverse)
library(rio)
europeanvalues <- import("ZA7505_v2-0-0.dta")
View(europeanvalues)
table(europeanvalues$D081)
table(europeanvalues$F118)
table(europeanvalues$X025A_01)
europeanvalues$D081
europeanvalues <-mutate(
europeanvalues,
homo_parents = ifelse(europeanvalues$D081 == 1,"Agree strongly",
ifelse(europeanvalues$D081 == 2, "Agree",
ifelse(europeanvalues$D081 == 3, "Neither agree nor disagree",
ifelse(europeanvalues$D081 == 4, "Disagree",
ifelse(europeanvalues$D081 == 5, "Disagree strongly",
"missing"
))))))
table(europeanvalues$homo_parents)
#The variable goes on a scale from 1 to 10, while the previous one from 1 to 5. In order to work
#on the same number of categories I grouped each one for 2. For example 'never justifiable' corresponds
#to 1 and 2, etc...
europeanvalues <-mutate(
europeanvalues,
justifiable_homo = ifelse(europeanvalues$F118 == 1: 2, "Never justifiable",
ifelse(europeanvalues$F118 == 3: 4, "Sometimes justifiable",
ifelse(europeanvalues$F118 == 5: 6, "Neither justifiable nor not",
ifelse(europeanvalues$F118 == 7: 8, "Often justifiable",
ifelse(europeanvalues$F118 == 9: 10, "Always justifiable",
"missing"
))))))
table(europeanvalues$justifiable_homo)
europeanvalues$X025A_01
#I had doubts on how to recode the variable 'X025A_01 - Highest educational level attained', so I
#read the Variable report and I found another variable that was already recoded: 'Less than primary',
#'Primary' and 'Lower secondary' are under the category 'Lower'; 'Upper secondary' and
#'Post-secondary non tertiary' are under the category 'Middle'; the remaining ones are under
#the category 'Upper'.
europeanvalues$X025R
europeanvalues <-mutate(
europeanvalues,
edu_level = ifelse(europeanvalues$X025R == 1, "Lower",
ifelse(europeanvalues$X025R == 2, "Middle",
ifelse(europeanvalues$X025R == 3, "Upper",
"missing"
))))
table(europeanvalues$edu_level)
table(europeanvalues$homo_parents)
table(europeanvalues$justifiable_homo)
table(europeanvalues$edu_level)
tab_int <-select(europeanvalues, homo_parents, justifiable_homo, edu_level)
View(tab_int)