-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate Programs.do
More file actions
85 lines (71 loc) · 2.33 KB
/
Create Programs.do
File metadata and controls
85 lines (71 loc) · 2.33 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
* Create Programs
capture program drop prog_date_setup
program define prog_date_setup
foreach stub in `*'{
gen `stub'_Y=.m
gen `stub'_MY=.m
gen `stub'_Flag=0
}
end
capture program drop prog_labels
program define prog_labels
capture label define Activity ///
1 "Employment" 2 "Education" 3 "Unemployment" ///
4 "Homemaking/Caring" 5 "Training" 6 "Other"
capture label define Flag ///
0 "No Imputation" ///
1 "Seam Spell" ///
2 "Imputed, Month in Year" ///
3 "Imputed, Month and Year" ///
4 "Truncated across Waves" ///
5 "Truncated, Month in Year" ///
6 "Truncated, Month and Year"
label values Activity
end
capture program drop prog_datemiss
program define prog_datemiss
foreach date in `*'{
capture drop `date'_Miss
egen `date'_Miss=rowmiss(`date'_Y `date'_MY)
}
tab *_Miss
end
capture program drop prog_mytoy
program define prog_mytoy
foreach date in `*'{
replace `date'_Y=year(dofm(`date'_MY)) ///
if !missing(`date'_MY)
}
end
capture program drop prog_overlap
program prog_overlap
foreach i in F L{
local obs=cond("`i'"=="F","_n<_N","_n>1")
local op=cond("`i'"=="F","_n+1","_n-1")
capture drop `i'_*
gen `i'_Overlap=0
by NSID (Spell), sort: replace `i'_Overlap=1 if `obs' & Start_MY>=Start_MY[`op'] & End_MY<=End_MY[`op']
by NSID (Spell), sort: replace `i'_Overlap=2 if `obs' & Start_MY<Start_MY[`op'] & End_MY>End_MY[`op']
by NSID (Spell), sort: replace `i'_Overlap=3 if `obs' & Start_MY<Start_MY[`op'] & End_MY<=End_MY[`op'] & End_MY>Start_MY[`op']
by NSID (Spell), sort: replace `i'_Overlap=4 if `obs' & Start_MY>=Start_MY[`op'] & End_MY>End_MY[`op'] & Start_MY<End_MY[`op']
by NSID (Spell), sort: gen `i'_Start_MY=cond(`obs',Start_MY[`op'],.i)
by NSID (Spell), sort: gen `i'_End_MY=cond(`obs',End_MY[`op'],.i)
by NSID (Spell), sort: gen `i'_Wave=cond(`obs',Wave[`op'],.i)
}
end
capture program drop prog_bounds
program define prog_bounds
capture drop LB UB
capture drop Reverse
gen Reverse=-Spell
gen LB=max(Start_MY,ym(Start_Y,1))
gen UB=min(Start_MY,ym(Start_Y,12))
by NSID Wave (Spell), sort: replace LB=LB[_n-1] ///
if missing(LB) | (!missing(LB[_n-1]) & LB[_n-1]>LB)
by NSID Wave (Reverse), sort: replace UB=UB[_n-1] ///
if missing(UB) | (!missing(UB[_n-1]) & UB[_n-1]<UB)
replace UB=min(UB,Max_IntDate_MY)
drop Reverse
sort NSID Wave Spell
format LB UB %tm
end