-
Notifications
You must be signed in to change notification settings - Fork 3
/
dataset_coefficients.do
executable file
·60 lines (59 loc) · 1.61 KB
/
dataset_coefficients.do
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
program define dataset_coefficients
syntax , Filename(string) [Separator(string)]
version 9.1
if ("`separator'" == "") {
local separator ","
}
// Get the names of the variables to write out. Need to change " o." to " " for making name for the macro to hold the variable labels
local varnames : coln e(b)
local coefs ""
foreach varn of local varnames {
local coef = _coef[`varn']
local coefs "`coefs' `coef'"
local varn1 = regexr("`varn'","o._I","_I")
if ("`varn'" != "_cons") {
local varlab_`varn1' : variable label `varn1'
}
else {
local varlab_constant "constant"
}
}
preserve
drop *
// Generate the new variable names, and apply the labels
local variablenamestoplot ""
foreach varn of local varnames {
local varn1 = regexr("`varn'","o._I","_I")
if ("`varn'" != "_cons") {
gen `varn1' = .
label var `varn1' `"`varlab_`varn1''"'
local variablenamestoplot "`variablenamestoplot' `varn1'"
}
else {
gen constant = .
label var constant "constant"
local variablenamestoplot "`variablenamestoplot' `constant'"
}
}
// Apply the values to the variables as observations
set obs 1
local count = 0
foreach varn of local varnames {
local count = `count' + 1
local coef1 : word `count' of `coefs'
local varn1 = regexr("`varn'","o._I","_I")
if ("`varn'" != "_cons") {
// constant?
replace `varn1' = `coef1' in 1
}
else {
replace constant = `coef1' in 1
}
}
cap drop __*
// global variablenamestoplot "`variablenamestoplot'"
// char [variablenamestoplot] "`variablenamestoplot'"
notes : `variablenamestoplot'
save "`filename'" , replace
restore
end program