-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_tidy_merge.jl
67 lines (58 loc) · 1.78 KB
/
05_tidy_merge.jl
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
## ------------------------------------------------------------------------
##
## Script name: 05_tidy_merge.jl
## Purpose: Merge cleaned data
## Author: Yanwen Wang
## Date Created: 2024-12-08
## Email: [email protected]
##
## ------------------------------------------------------------------------
##
## Notes:
##
## ------------------------------------------------------------------------
# 1 Combine cleaned data --------------------------------------------------
# Combine cleaned data
census = vcat(census_1982, census_1990, census_2000, census_2010)
# 2 Educational pair ------------------------------------------------------
edu_pair = Vector{Union{String,Missing}}(undef, nrow(census))
homo = Vector{Union{Int,Missing}}(undef, nrow(census))
heter = Vector{Union{Int,Missing}}(undef, nrow(census))
hyper = Vector{Union{Int,Missing}}(undef, nrow(census))
hypo = Vector{Union{Int,Missing}}(undef, nrow(census))
for i in 1:nrow(census)
m = census.edu_m[i]
f = census.edu_f[i]
if ismissing(m) || ismissing(f)
edu_pair[i] = missing
homo[i] = missing
heter[i] = missing
hyper[i] = missing
hypo[i] = missing
elseif m == f
edu_pair[i] = "homo"
homo[i] = 1
heter[i] = 0
hyper[i] = 0
hypo[i] = 0
elseif m > f
edu_pair[i] = "hyper"
homo[i] = 0
heter[i] = 1
hyper[i] = 1
hypo[i] = 0
elseif m < f
edu_pair[i] = "hypo"
homo[i] = 0
heter[i] = 1
hyper[i] = 0
hypo[i] = 1
end
end
census[!, :edu_pair] = edu_pair
census[!, :homo] = homo
census[!, :heter] = heter
census[!, :hyper] = hyper
census[!, :hypo] = hypo
# 3 Save ------------------------------------------------------------------
Arrow.write("Data_clean/census.arrow", census)