-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdiagramconnection.ado
89 lines (66 loc) · 1.93 KB
/
diagramconnection.ado
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
prog define diagramconnection
version 11
syntax [using/] , tempfile(str) sign(str) [indent(str)]
tempname knot
file open `knot' using "`tempfile'", write append
//check for string variable type
cap confirm string variable from
if _rc == 0 local fromisstring 1
cap confirm string variable to
if _rc == 0 local toisstring 1
forval i = 1 / `c(N)' {
local next // reset
if "`fromisstring'" != "1" & "`toisstring'" != "1" {
local next : di "`indent'" from[`i'] " `sign' " to[`i']
}
else {
// FROM
// ====
if "`fromisstring'" == "1" {
*local next : di "`indent'" `"""' "`from'" `"""' " `sign' "
if substr(from[`i'], 1,1) == `"""' {
local next : di "`indent'" from[`i'] " `sign' "
}
else local next : di "`indent'" `"""' from[`i'] `"""' " `sign' "
}
else local next : di "`indent'" from[`i'] " `sign' "
// TO
// ====
if "`toisstring'" == "1" {
if substr(to[`i'], 1,1) == `"""' {
local next : di `"`next'"' to[`i']
}
*else local next = `"`next'"' + `"""' + to[`i'] + `"""'
else local next : di `"`next'"' `"""' to[`i'] `"""'
}
else local next : di `"`next'"' to[`i']
}
file write `knot' `" `next'"'
capture confirm variable label
if _rc == 0 {
local lbl : di label[`i']
}
capture confirm variable properties
if _rc == 0 {
local prp : di properties[`i']
}
//Stata returns a weird error with combining !missing() function, which
//made me take this stupid work-around...
*if !missing(label[`i']) {
if !missing("`lbl'") {
local details `"label="`lbl'""'
//add comma
if !missing(`"`prp'"') {
local details = `"`details', "'
}
}
if !missing(`"`prp'"') {
local details = `"`details'"' + `"`prp'"'
}
if !missing(`"`details'"') {
file write `knot' `"[`details']"'
}
local details // reset
file write `knot' ";" _n
}
end