-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadfunctions.jl
91 lines (69 loc) · 1.96 KB
/
loadfunctions.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# formatted reporting
function report(reporttext, reportcalc)
cursorstart = 45
countlinebreaks = 0
for i in 1:length(reporttext)
if reporttext[1:i] != "\n"
break
end
countlinebreaks += 1
end
cursorstart = max(length(reporttext) - countlinebreaks, cursorstart) + 3 * (reportcalc >= 0) + 2 * (reportcalc < 0)
charfill = join(fill(" ", cursorstart - length(reporttext) + countlinebreaks), "")
println(reporttext, charfill, reportcalc)
end
# convert variable from cohort-view to period-view
function coh2per(inmat)
maxage, numcoh = size(inmat)
numper = numcoh-(maxage-1)
if numper<=0
error("coh2per: insufficient number of columns in input matrix")
end
outmat = zerosmat(maxage,numper)
for a in 1:maxage
outmat[a,:] = inmat[a,(maxage:numcoh).-(a-1)]
end
return outmat
end
# convert variable from cohort-view to period-view and aggregate over age
function aggcoh2per(inmat)
return sum(coh2per(inmat),dims=1)
end
# convert variable from period-view to cohort-view
function per2coh(inmat)
maxage, numper = size(inmat)
numcoh = numper+(maxage-1)
calibvec = inmat[:,1]
outmat = zerosmat(maxage,numcoh)
for a in 1:maxage
if a < maxage
outmat[a,1:(maxage-a)] = onesrow(maxage-a)*calibvec[a]
end
outmat[a,(maxage:numcoh).-(a-1)] = inmat[a,:]
if a > 1
outmat[a,(numcoh-(a-2)):numcoh] = onesrow(a-1)*inmat[a,numper]
end
end
return outmat
end
function seq(from,to,lengthout=to-from+1)
return collect(range(from,to,length=floor(Int,lengthout)))
end
function zeroscol(dim1)
return zeros(dim1,1)
end
function zerosrow(dim1)
return zeros(1,dim1)
end
function zerosmat(dim1,dim2)
return zeros(dim1,dim2)
end
function onescol(dim1)
return ones(dim1,1)
end
function onesrow(dim1)
return ones(1,dim1)
end
function onesmat(dim1,dim2)
return ones(dim1,dim2)
end