-
Notifications
You must be signed in to change notification settings - Fork 3
/
construct_reg_eqn.ado
executable file
·51 lines (43 loc) · 1.11 KB
/
construct_reg_eqn.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
program define construct_reg_eqn, rclass
syntax , Filename(string) [Round(real 1)]
version 9.1
local varnames1 : coln e(b)
local equation ""
local equation2 ""
foreach varn of local varnames1 {
cap local varlabel : variable label `varn'
// local coef = _coef[`varn']
if ("`round'" == "") {
local coef = round(_coef[`varn'])
}
else {
local coef = round(_coef[`varn'],`round')
}
if ("`varn'" != "_cons") {
if (`coef' < 0) {
local equation "`equation' `coef'*`varn'"
local equation2 "`equation2' `coef'*(`varlabel')"
}
else if (`coef' > 0) {
local equation "`equation' + `coef'*`varn'"
local equation2 "`equation2' + `coef'*(`varlabel')"
}
}
else {
if (`coef' < 0) {
local equation "`equation' `coef'"
local equation2 "`equation2' `coef'"
}
else if (`coef' > 0) {
local equation "`equation' + `coef'"
local equation2 "`equation2' + `coef'"
}
}
}
tempname fh
file open `fh' using "`filename'", w replace all
file write `fh' "`equation'" _n _n
file write `fh' "`equation2'" _n
file close `fh'
return local equation `equation'
end