-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpcn_functions.mata
73 lines (49 loc) · 1.3 KB
/
pcn_functions.mata
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
// ------------------------------------------------------------------------
// MATA code to loop over primus results
// ------------------------------------------------------------------------
cap mata: mata drop pcn_*()
mata:
mata set mataoptimize on
mata set matafavor speed
mata set matadebug off // (on when debugging; off in production)
mata set matalnum off // (on when debugging; off in production)
void pcn_ind(string matrix R) {
i = strtoreal(st_local("i"))
vars = tokens(st_local("varlist"))
for (j =1; j<=cols(vars); j++) {
//printf("j=%s\n", R[i,j])
st_local(vars[j], R[i,j] )
}
} // end of IDs variables
string matrix pcn_info(matrix P) {
survey = st_local("survey_id")
status = st_local("status")
dlwnote = st_local("dlwnote")
if (rows(P) == 0) {
P = survey, status, dlwnote
}
else {
P = P \ (survey, status, dlwnote)
}
return(P)
}
string matrix pcn_split_id(string scalar invs) {
string colvector Y
string matrix A
Y = tokens(invs)'
A = J(0,0, .z)
for (i =1; i<=rows(Y); i++) {
//printf("i=%s\n", Y[i])
if (rows(A) == 0) {
A = tokens(Y[i], "_")
}
else {
A = A \ tokens(Y[i], "_")
}
}
A = select(A, !regexm(A[1,.],"^(_|M|A)$"))
A = Y, A
return(A)
}
end
exit