-
Notifications
You must be signed in to change notification settings - Fork 8
/
knitr.do
90 lines (75 loc) · 1.72 KB
/
knitr.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
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
89
90
capture program drop knit
program define knit
args in
_knit_with_code_tags "`in'"
_make_code_blocks "`in'"
end
capture program drop _knit_with_code_tags
program define _knit_with_code_tags
args in
set more off
file open f using "`in'", read
local out = subinstr("`in'", ".domd", ".md1", 1)
log using "`out'", text replace
local in_code_block = 0
file read f line
while r(eof) == 0 {
if substr("`line'", 1, 4) == " " {
if !`in_code_block' {
display "<code>"
local in_code_block = 1
}
else {
display ""
}
display ". `=ltrim("`line'")'"
`line'
}
else {
if `in_code_block' {
display "</code>"
local in_code_block = 0
}
display "`line'"
}
file read f line
}
log close
file close f
end
capture program drop _make_code_blocks
program define _make_code_blocks
args in
local out = subinstr("`in'", ".domd", ".md", 1)
file open f_in using "`out'1", read
file open f_out using "`out'", write replace
local in_code_block = 0
local footer = 0
file read f_in line
local line_no = 1
while r(eof) == 0 {
local header = `line_no' <= 5
local footer = ("`line'" == " name: <unnamed>" & !`header') | `footer'
if "`line'" == "<code>" {
local in_code_block = 1
}
else if "`line'" == "</code>" {
local in_code_block = 0
}
else {
if `in_code_block' {
file write f_out " `line'" _n
}
else {
if !`header' & !`footer' {
file write f_out "`line'" _n
}
}
}
file read f_in line
local line_no = `line_no' + 1
}
file close f_in
file close f_out
end
knit "clustered-standard-errors.domd"