Skip to content

Commit

Permalink
was maps
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamstark committed Feb 26, 2025
1 parent 48b8c42 commit 20d242c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 86 deletions.
8 changes: 4 additions & 4 deletions matching/matching_funcs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ end
# 1 -> Any


function shs_tenuremap( tenure :: Union{Int,Missing} ) :: Vector{Int}
function shs_map_tenure( tenure :: Union{Int,Missing} ) :: Vector{Int}
out = fill( 0, 3 )
if ismissing( tenure ) # || tenure >= 5
return out;
Expand Down Expand Up @@ -397,7 +397,7 @@ function age( age :: Union{Int,Missing} ) :: Vector{Int}
return out
end

function frs_tenuremap( tentyp2 :: Union{Int,Missing} ) :: Vector{Int}
function frs_map_tenure( tentyp2 :: Union{Int,Missing} ) :: Vector{Int}
out = fill( 0, 3 )
out[3] = 1
if ismissing( tentyp2 )
Expand Down Expand Up @@ -889,7 +889,7 @@ function create_donor_and_recip_datasets( frs_all_years_scot_he :: DataFrame, sh
end

assign!( recip, :shelter, setone.( frs_all_years_scot_he.shelter ))
assign!( recip, :tenure, frs_tenuremap.(frs_all_years_scot_he.tentyp2))
assign!( recip, :tenure, frs_map_tenure.(frs_all_years_scot_he.tentyp2))
assign!( recip, :singlepar, setone.(frs_all_years_scot_he.hhcomps, is_sp))
assign!( recip, :numadults, total_people.( frs_all_years_scot_he.adulth, -777, false ))
assign!( recip, :numkids, total_people.( frs_all_years_scot_he.depchldh, -776, true ))
Expand All @@ -902,7 +902,7 @@ function create_donor_and_recip_datasets( frs_all_years_scot_he :: DataFrame, sh
assign!( recip, :bedrooms, bedrooms.( frs_all_years_scot_he.bedroom6 ))

assign!( donor, :shelter, setone.( shs_all_years.accsup1 ))
assign!( donor, :tenure, shs_tenuremap.(shs_all_years.tenure))
assign!( donor, :tenure, shs_map_tenure.(shs_all_years.tenure))
assign!( donor, :singlepar, setone.( shs_all_years.hhtype_new, 3 ))
assign!( donor, :numadults, total_people.( shs_all_years.totads, -888, false ))

Expand Down
86 changes: 4 additions & 82 deletions src/matching/SHS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ end
2 -> Rented
3 -> Other
"""
function tenuremap( tenure :: Union{Int,Missing} ) :: Vector{Int}
function map_tenure( tenure :: Union{Int,Missing} ) :: Vector{Int}
if ismissing( tenure ) # || tenure >= 5
return [rand(Int),rand(Int)];
end
Expand All @@ -115,7 +115,7 @@ end
"""
Harmonised FRS tenure, as above
"""
function shs_model_tenure( tenure :: Tenure_Type )::Vector{Int}
function model_to_shs_map_tenure( tenure :: Tenure_Type )::Vector{Int}
t1, t2 = if tenure == Owned_outright
1,1
elseif tenure == Mortgaged_Or_Shared
Expand All @@ -132,71 +132,7 @@ function shs_model_tenure( tenure :: Tenure_Type )::Vector{Int}
return [t1,t2]
end

"""
level 1 -> actual number of people
level 2
0 -> 0 (for kids)
1 -> 1
2 -> 2
3 -> 3:5
4 -> > 5
level 3
1 adult -> 0
2 adults -> 1
> 2 adults -> 2
0 child -> 0
> 0 child -> 1
"""
function total_people( n :: Union{Int,Missing}, is_child :: Bool ) :: Vector{Int}
out = fill( 0, 3 )
if ismissing( n )
return rand(Int,3)
end
out[1] = n
if n == 0
out[2] = 0
elseif n == 1
out[2] = 1
elseif n == 2
out[2] = 2
elseif n in 3:5
out[2] = 3
else
out[2] = 4
end
if is_child # any children
out[3] = out[2] > 0 ? 1 : 0
else
@assert out[2] > 0 "no adults"
if out[2] == 1
out[3] == 0
elseif out[2] == 2
out[3] = 1
else
out[3] = 2
end
end
return out
end


"""
1. age (max 80)
2. age 5 year bands
3. age 20 year bands
"""
function age( age :: Union{Int,Missing} ) :: Vector{Int}
out = fill( 0, 3 )
if ismissing( age )
return out
end
age = min( 80, age )
out[1] = age
out[2] = Int(trunc(age/5))
out[3] = Int(trunc(age/20))
return out
end

"""
# SHS hihecon
# Value = 1.0 Label = A - Self employed
Expand Down Expand Up @@ -389,20 +325,6 @@ function shs_model_map_social( soc :: Standard_Occupational_Classification ) ::
return map_social(o)
end


function bedrooms( rooms :: Union{Missing,Int} ) :: Vector{Int}
rooms = min(6, rooms )
out = fill(0,3)
if (ismissing(rooms) || (rooms == 0 ))
return [0,0, 1]
end
out = fill(0,3)
out[1] = rooms
out[2] = min( rooms, 3)
out[3] = rooms == 1 ? 1 : 2
return out
end

"""
Pos. = 2,761 Variable = hb1 Variable label = hb1 - Is the household's accommodation...
Expand All @@ -426,7 +348,7 @@ out: detatached = 1
all other = 5
"""
function accomtype( hb1 :: Union{Missing,Int}, hb2 :: Union{Missing,Int} ) :: Vector{Int}
function map_accom( hb1 :: Union{Missing,Int}, hb2 :: Union{Missing,Int} ) :: Vector{Int}
out = fill( 0, 2 )
if ismissing(hb1)
return out
Expand Down Expand Up @@ -471,7 +393,7 @@ Out:
other 5
with na distributed randomly
"""
function model_to_shs_accommap( dwelling :: DwellingType ):: Vector{Int}
function model_to_shs_map_accom( dwelling :: DwellingType ):: Vector{Int}
if dwelling == dwell_na
println( "na dwelling ")
dwelling = rand([detatched,semi_detached,terraced,flat_or_maisonette,converted_flat])
Expand Down

0 comments on commit 20d242c

Please sign in to comment.