-
Notifications
You must be signed in to change notification settings - Fork 17
/
edapie.ado
executable file
·99 lines (69 loc) · 3.18 KB
/
edapie.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
********************************************************************************
* Description of the Program - *
* EDA subroutine used to create pie charts *
* *
* Program Output - *
* Creates pie chart GPH and PDF as well as entries in the LaTeX document *
* *
* Lines - *
* 98 *
* *
********************************************************************************
*! edapie
*! v 0.0.1
*! 17jul2018
// Drop program from memory if already loaded
cap prog drop edapie
// Define program
prog def edapie
// Version used to interpret code
version 14
// Syntax structure for edabar subroutine
syntax varlist(min=1) [if] [in], root(string asis) ///
[PIECHartopts(string asis) ///
scheme(passthru) ///
keepgph MISSing byvars(varlist) byseq ]
// Mark only the observations to use
marksample touse, strok novarlist
// No byvars argument
if `"`byvars'"' == "" {
// Add subheading to the LaTeX file
file write doc "\subsubsection{Pie Charts}" _n
// Create bar graphs for the categorical variables
foreach v of var `varlist' {
// Get number of rows for the legend for this variable
loc leg legend(rows(`:char `v'[lrows]') symy(1.85) symx(1.85))
// Create pie chart
gr pie if `touse', over(`v') `piechartopts' ti(`:char `v'[title]') ///
note("Created on: `c(current_date)' at: `c(current_time)'") ///
`missing' `scheme'
// Export to .pdf file
qui: gr export `"`root'/graphs/pie`v'.pdf"', as(pdf) replace
// Check if user wants to keep the GPH files
if "`keepgph'" != "" {
// Define local macro with syntax to remove file
qui: gr save `"`root'/graphs/pie`v'.gph"', replace
} // End IF Block to remove .gph files
// Get LaTeX formatted variable name
texclean `"`v'"', r
// Store the variable name in vref
loc vref `r(clntex)'
// Get LaTeX formatted variable label
texclean `"`: var l `v''"'
// Store the variable label in vlab
loc vlab `r(clntex)'
// Add the graph to the LaTeX file
file write doc "\begin{figure}[h!]" _n
file write doc `"\caption{Pie Chart of `vlab' \label{fig:pie`vref'}}"' _n
file write doc `"\includegraphics[width=\textwidth]{pie`v'.pdf}"' _n
file write doc "\end{figure} \newpage\clearpage" _n
} // End loop over categorical variables
} // End IF Block for no byvars argument
// sequential by graphs
else if `"`byvars'"' != "" & "`byseq'" != "" {
} // End ELSEIF Block for sequential by graphs
// Lattice graphs
else if `"`byvars'"' != "" & "`byseq'" == "" {
} // End ELSE IF Block for Lattice style graphs
// End of subroutine definition
end