-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint_ci.ado
executable file
·122 lines (84 loc) · 2.89 KB
/
point_ci.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
119
120
121
122
/***
Title
======
__point_ci__ -- Create plot of point estimates and confidence intervals
Syntax
------
__point_ci__ pointest pointest_lb pointest_ub axisvar [_if_] [_in_] [, vertical labelvar(str) plot_options(str) ci_options(str) point_options(str) ytitle(str)]
- - -
> __pointest__ : Name of variable with point estimates.
> __pointest_lb__ : Name of variable with point estimate lower bound.
> __pointest_ub__ : Name of variable with point estimate upper bound.
> __axisvar__ : Name of y-axis (usually) variable.
> __vertical__ : Optional. Plots the CIs vertically instead of horizontally.
> __labelvar(str)__ : Name of variable with estimate labels.
> __plot_options(str)__ : Optional. STATA commands to customize the plot.
> __ci_options(str)__ : STATA commands to customize the confidence intervals. (Commands are included in a twoway line command.)
> __point_options(str)__ : STATA commands to customize the points. (Commands are included in a twoway scatter command.)
- - -
Description
-----------
Creates a plot of point estimates and confidence intervals.
Example
-------
getvdata nhgh
regress ht i.re##i.sex
plotdata, at(sex = 1/2; re = 1/5)
regress_yhat_ci
decode(sex), generate(s_sex)
decode(re), generate(s_re)
gen label = s_re + " " + s_sex
egen float row = rank(-10*re+sex) if _plotindicator == 1
point_ci ht_hat ht_hat_lb ht_hat_ub row if _plotindicator == 1 & sex == 1, ///
labelvar(label) ///
point_options(mcolor(magenta)) ///
ci_options(lwidth(thick)) ///
plot_options(title(Mean heights NHANES) xtitle(Height (cm)))
***/
capture program drop point_ci
program point_ci
syntax varlist [if] [in] [, vertical labelvar(str) plot_options(str) ci_options(str) point_options(str) ytitle(str)]
tokenize `varlist'
tempfile temp1
quietly save "`temp1'"
marksample _keep
keep if `_keep'
expand 3
sort `4'
gen _row = _n
gen _odd = mod(_row, 3)
gen _bound = `2' * (_odd == 1) + `3' * (_odd == 2)
replace _bound = . if _odd == 0
if("`labelvar'" != ""){
labmask `4', values(`labelvar')
}
label variable `4' ""
levelsof `4', local(values_labelvar)
//display "`values_labelvar'"
if "`plot_options'" != "" {
local comma = ", "
}
else {
local comma = " "
}
// display "Comma: " "`comma'"
// display "plot_options: " "`plot_options'"
if("`point_options'" != ""){
local point_options = " , " + "`point_options'"
}
if("`vertical'" == "") {
twoway ///
(line `4' _bound, cmissing(n) `ci_options') ///
(scatter `4' `1' if _odd == 0 `point_options') ///
, ylabel(`values_labelvar', valuelabel angle(horizontal)) ///
legend(off) ///
`plot_options'
}
else {
twoway ///
(line _bound `4', cmissing(n)) ///
(scatter `1' `4' if _odd == 0) ///
`comma' `plot_options'
}
use "`temp1'", clear
end