-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsigbar.ado
116 lines (111 loc) · 3.58 KB
/
sigbar.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
/* Generates barchart of significant variables
Alex Sax
RTI International
8-18-11
*/
program define sigbar
syntax varlist [pweight] [if] [in] [, SVY noLABel Keep noGRAph GRoup(varname) LEGendoptions(str) TWOWay_options(str) lsize(str) hello]
version 11
*Set labelsize if not user defined
if "`lsize'"==""{
local lsize = "lsize"
}
*If svy, use it!
if "`svy'" != ""{
local `svy' = "svy:"
}
if "`hello'"!=""{
di in red "Hi there!"
di in green "Now back to work."
}
*find the dependant variable
local dvar : word 1 of `varlist'
*If we don't already have a list, make one
capture confirm variable Variable
if _rc{
local sigvars ""
local coeflist ""
local sigvarlab ""
local siglength = 0
forvalues i=2/800 {
*Create list of potentially significant variables
local testvar : word `i' of `varlist'
capture confirm variable `testvar'
if !_rc {
if "`weight'"!="" {
quietly: `svy' regress `dvar' `testvar' [`weight'`exp']
}
else {
quietly: `svy' regress `dvar' `testvar'
}
*Test and move to significant list
quietly: test `testvar'
if r(p)<0.05{
local testcoef = _b[`testvar']
local coeflist "`coeflist' `testcoef'"
local sigvars "`sigvars' `testvar'"
local siglength = `siglength' + 1
}
}
}
*Gen vars to make the graph
quietly: gen str50 Variable = ""
quietly: gen str200 Varlab = ""
quietly: gen str14 change = ""
forvalues i = 1/`siglength' {
*List all significant variables*
local testvar : word `i' of `sigvars'
quietly: replace Variable = "`testvar'" in `i'
*List the labels of all significant variables
local testvar : word `i' of `sigvars'
local ltestvar : variable label `testvar'
quietly: replace Varlab = "`ltestvar'" in `i'
*List the beta coefficients of all sig vars
local testvar : word `i' of `coeflist'
quietly: replace change = "`testvar'" in `i'
}
quietly: destring change, replace
}
*Display graph
if "`graph'" == "" {
*Display the graph if there are not groups
if "`group'" == ""{
if "`label'" != "nolabel" {
*And apply labels
graph hbar (firstnm) change , sort(change) scheme(s2color) over(Varlab, sort(change) ///
label(labsize(vsmall))) asyvars showyvars cw blabel(bar, size(`lsize') format(%9.1g)) ytitle(`: variable label `dvar'' Change) ///
title(Change in `: variable label `dvar'' by Factor) legend(off) `twoway_options'
}
else {
*Or don't
graph hbar (firstnm) change , sort(change) scheme(s2color) over(Variable, sort(change) ///
label(labsize(vsmall))) asyvars showyvars cw blabel(bar, size(`lsize') format(%9.1g)) ytitle(`: variable label `dvar'' Change) ///
title(Change in `: variable label `dvar'' by Factor) legend(off) `twoway_options'
}
}
else {
*And if there are groups
decode `group', gen(other`group')
if "`label'" != "nolabel" {
*And apply labels
graph hbar (firstnm) change , sort(change) scheme(s2color) over(other`group', sort(change) ///
label(nolabel)) asyvars showyvars over(Varlab, sort(change) label(labsize(tiny)))cw ///
blabel(bar, size(`lsize') format(%9.1g)) ytitle(`: variable label `dvar'' Change) ///
title(Change in `: variable label `dvar'' by Factor) legend(on cols(1) `legendoptions') ///
`twoway_options'
}
else {
*Or don't
graph hbar (firstnm) change , sort(change) scheme(s2color) over(`group', sort(change) ///
label(nolabel)) asyvars showyvars over(Variable, sort(change) label(labsize(tiny)))cw ///
blabel(bar, size(`lsize') format(%9.1g)) ytitle(`: variable label `dvar'' Change) ///
title(Change in `: variable label `dvar'' by Factor) legend(on cols(1) `legendoptions') ///
`twoway_options'
}
drop other`group'
}
}
if "`keep'" == "" {
drop change Variable Varlab
}
end