-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtexresults.ado
78 lines (65 loc) · 2.12 KB
/
texresults.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
*! 1.2 Alvaro Carril 04apr2017
program define texresults
syntax [using], ///
TEXmacro(string) ///
[ ///
replace Append ///
Result(string) coef(varname) se(varname) tstat(varname) pvalue(varname) ///
ROund(real 0.01) UNITzero XSpace ///
]
* Initial checks and processing
*------------------------------------------------------------------------------
// Parse file action
if !missing("`replace'") & !missing("`append'") {
di as error "{bf:replace} and {bf:append} may not be specified simultaneously"
exit 198
}
local action `replace' `append'
// Add backslash to macroname and issue warning if doesn't contain only alph
local isalph = regexm("`texmacro'","^[a-zA-Z ]*$")
local texmacro = "\" + "`texmacro'"
if `isalph' == 0 di as text `""`texmacro'" may not be a valid LaTeX macro name"'
//
if !missing("`xspace'") local xspace = "\" + "`xspace'"
di "opcion: `xspace'"
* Process and store [rounded] result
*------------------------------------------------------------------------------
// general result (scalar, local, etc.)
if !missing("`result'") {
local result = round(`result', `round')
}
// coefficient
if !missing("`coef'") {
local result = round(_b[`coef'], `round')
}
// standard error
if !missing("`se'") {
local result = round(_se[`se'], `round')
}
// t-stat
if !missing("`tstat'") {
local result = round(_b[`tstat']/_se[`tstat'], `round')
}
// p-value
if !missing("`pvalue'") {
local result = round(2 * ttail(e(df_r), abs(_b[`pvalue']/_se[`pvalue'])), `round')
}
// Add unit zero if option is specified and result qualifies
if (!missing("`unitzero'") & abs(`result') < 1) {
if (`result' > 0) local result 0`result'
else local result = "-0"+"`=abs(`result')'"
}
* Create or modify macros file
*------------------------------------------------------------------------------
file open texresultsfile `using', write `action'
file write texresultsfile "\newcommand{`texmacro'}{$`result'$`xspace'}" _n
file close texresultsfile
*di as text `" Open {browse results.txt}"'
end
********************************************************************************
/*
CHANGE LOG
1.2
- Implement xspace option
1.1
- First public version