forked from remlapmot/mrrobust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrivests.ado
118 lines (111 loc) · 3.15 KB
/
mrivests.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
*! 0.1.0 Tom Palmer 10jun2017
program mrivests
version 9
syntax varlist(min=3 max=5) [if] [in] , ///
Generate(string asis) [REPLACE * ]
local varlistlength : word count `varlist'
tokenize `"`varlist'"'
/*
1: gd beta
2: gd SE
3: gp beta
4: gp SE
5: cov between estimates
*/
local gdbeta `1'
local gdse `2'
local gpbeta `3'
if `varlistlength' == 4 {
local gpse `4'
}
else if `varlistlength' == 5 {
local gpse `4'
local cov `5'
}
// work out whether fieller is in `options'
local fmatch = strmatch("`options'","fieller")
if `fmatch' == 1 {
local fieller fieller
}
else {
local fieller ""
}
qui count `if' `in'
local selnmax = r(N)
tempvar obsn
qui gen `obsn' = _n
qui levelsof `obsn' `if' `in'
local selobs "`r(levels)'"
tokenize `"`generate'"', parse(",")
local genvarlist `1'
local genopts `3'
local genvarlistlength : word count `genvarlist'
if `genvarlistlength' != 2 & "`fieller'" == "" {
di as err "Please specify 2 variable names, " ///
"which are for the IV estimates and their SEs."
exit 198
}
if `genvarlistlength' != 3 & "`fieller'" == "fieller" {
di as err "Please specify 3 variable names, " ///
"which are for the IV estimates and their lower and upper CI limits."
exit 198
}
tokenize "`genvarlist'"
local ivest `1'
if "`fieller'" == "" {
local ivestse `2'
}
else {
local ivcilow `2'
local ivciupp `3'
}
if "`genopts'" == "replace" {
qui replace `ivest' = . `if' `in'
if "`fieller'" == "" {
qui replace `ivestse' = . `if' `in'
}
else {
qui replace `ivcilow' = . `if' `in'
qui replace `ivciupp' = . `if' `in'
}
}
else {
qui gen double `ivest' = .
if "`fieller'" == "" {
qui gen double `ivestse' = .
}
else {
qui gen double `ivcilow' = .
qui gen double `ivciupp' = .
}
}
foreach i of numlist `selobs' {
local one : di `gdbeta'[`i']
local two : di `gdse'[`i']
local thr : di `gpbeta'[`i']
if `varlistlength' == 3 {
qui mrratio `one' `two' `thr', `options'
}
else if `varlistlength' == 4 {
local fou : di `gpse'[`i']
qui mrratio `one' `two' `thr' `fou', `options'
}
else if `varlistlength' == 5 {
local fiv : di `cov'[`i']
qui mrratio `one' `two' `thr' `fou' `fiv', `options'
}
qui replace `ivest' = _b[beta] if _n == `i'
if "`fieller'" == "" {
qui replace `ivestse' = _se[beta] if _n == `i'
}
else if "`fieller'" == "fieller" & e(fiellerres) == 1 {
qui replace `ivcilow' = e(lowerci) if _n == `i'
qui replace `ivciupp' = e(upperci) if _n == `i'
}
else if "`fieller'" == "fieller" & e(fiellerres) > 1 {
qui replace `ivcilow' = . if _n == `i'
qui replace `ivciupp' = . if _n == `i'
}
}
end
exit