-
Notifications
You must be signed in to change notification settings - Fork 29
/
rcall_synchronize.ado
87 lines (69 loc) · 2.4 KB
/
rcall_synchronize.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
// synchronizing from Stata to R
// =============================
*capture program drop rcall_synchronize
program rcall_synchronize
if !missing("`debug'") di as err "entering rcall_synchronize"
tempfile Rscript
tempname knot
qui file open `knot' using "`Rscript'", write text replace
// -------------------------------------------------------------------------
// List the global macros
// =========================================================================
/*
local ignorelist S_FNDATE S_FN S_level F1 F2 F7 F8 S_ADO S_StataSE S_FLAVOR ///
S_OS S_OSDTL S_MACH
local allglobals : all globals
foreach lname in `allglobals' {
local equal // reset
foreach lname2 in `ignorelist' {
if "`lname'" == "`lname2'" local equal 1
}
if missing("`equal'") {
local glo : display `"$`lname'"'
local test // reset
capture local test : display int(`glo')
if missing("`test'") & "`glo'" != "" {
file write `knot' `"`lname'_ <- "`macval(glo)'""' _n
}
else {
file write `knot' `"`lname'_ <- `macval(glo)'"' _n
}
}
}
*/
// -------------------------------------------------------------------------
// List the scalars
// =========================================================================
local allscalars : all scalars
*di as err `"SCALARS:`allscalars'"'
foreach lname in `allscalars' {
local sca : display `lname'
local test // reset
capture local test : display int(`sca')
if missing("`test'") & "`sca'" != "" {
file write `knot' `"`lname' <- "`macval(sca)'""' _n
}
else if trim("`sca'") == "." {
file write `knot' `"`lname' <- NA"' _n
}
else if trim("`sca'") != "" {
file write `knot' `"`lname' <- `macval(sca)'"' _n
}
else if trim("`sca'") == "" {
file write `knot' `"`lname' <- "`macval(sca)'" "' _n
}
}
// -------------------------------------------------------------------------
// List the matrices
// =========================================================================
local allmats : all matrices
foreach lname in `allmats' {
qui matconvert `lname'
file write `knot' `"`lname' <- `r(`lname')'"' _n
}
qui file close `knot'
// -------------------------------------------------------------------------
// Create a Source file
// =========================================================================
quietly copy "`Rscript'" "rcall_synchronize", replace
end