Skip to content

Commit c615bc9

Browse files
committed
Adding byvar options to eligible graphs. Mosaic, Pie, and Scatterplots are still in progress.
1 parent a974dbf commit c615bc9

File tree

8 files changed

+1473
-535
lines changed

8 files changed

+1473
-535
lines changed

Diff for: eda.ado

+85-4
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ prog def eda
3939
QFIT2(string asis) LOWess LOWess2(string asis) FPFIT FPFIT2(string asis) ///
4040
LFITCi LFITCi2(string asis) QFITCi QFITCi2(string asis) FPFITCi ///
4141
FPFITCi2(string asis) noBUBBLEplots noBOXplots noMOSAIC noHEATmap ///
42-
COMPile PDFLatex(passthru) BYGraphs(string asis) BYVars(varlist) ///
43-
WEIGHTtype(passthru) ]
42+
COMPile PDFLatex(passthru) BYGraphs(string asis) BYVars(passthru) ///
43+
BYSeq WEIGHTtype(passthru) ]
4444

4545
// Make the sample to use for the program
4646
marksample edause, strok novarlist
@@ -437,15 +437,96 @@ prog def eda
437437

438438
} // End IF Block for correlation heatmap option
439439

440-
441-
442440
// If any graphs are going to be drawn
443441
if `"`graphs'"' != "" {
444442

445443
// Change back to portrait page layout
446444
file write doc "\end{landscape}" _n
447445

448446
} // End IF Block to reorient pages after graphs section
447+
448+
// Check for by graphs
449+
if "`bygraphs'" != "" & "`byvars'" != "" {
450+
451+
// Check if user wants bargraphs
452+
if "`bargraphs'" != "nobargraphs" & !inlist(`catvarcount', 0, .) ///
453+
& inlist("bar", `"`: subinstr loc bygraphs `" "' `"", ""''"') == 1 {
454+
455+
// Call Bar graph subroutine
456+
edabar `categorical' if `edause', `bargraphopts' `byvars' ///
457+
root(`root') bart(`bartype') `scheme' `keepgph' `byseq'
458+
459+
} // End IF Block for bar graph creation
460+
461+
// Check if user wants pie charts
462+
if "`piecharts'" != "nopiecharts" & !inlist(`catvarcount', 0, .) ///
463+
& inlist("pie", `"`: subinstr loc bygraphs `" "' `"", ""''"') == 1 {
464+
465+
// Call Pie chart subroutine
466+
edapie `categorical' if `edause', `piechartopts' ///
467+
`scheme' `keepgph' root(`root') `byvars' `byseq'
468+
469+
} // End IF Block for pie charts option
470+
471+
// Add subheading to the LaTeX file
472+
file write doc "\subsection{Continuous Variables} \newpage\clearpage" _n
473+
474+
// Check if user wants histograms
475+
if "`histograms'" != "nohistograms" & !inlist(`contvarcount', 0, .) ///
476+
& inlist("histogram", `"`: subinstr loc bygraphs `" "' `"", ""''"') == 1 {
477+
478+
// Call histogram subroutine
479+
edahist `continuous' if `edause', `histogramopts' `scheme' ///
480+
`kdensity' kdensopts(`kdensopts') `fivenumsum' `byvars' ///
481+
fnsopts(`fnsopts') root(`root') `byseq'
482+
483+
} // End IF Block for histograms
484+
485+
// Check for scatter plot option
486+
if "`scatterplots'" != "noscatterplots" & !inlist(`contvarcount', 0, .) ///
487+
& inlist("scatterplot", `"`: subinstr loc bygraphs `" "' `"", ""''"') == 1 {
488+
489+
// Call to scatterplot subroutine
490+
edascat `continuous' if `edause', `lfit' lfit2(`lfit2') ///
491+
qfit2(`qfit2') `lowess' lowess2(`lowess2') `fpfit' ///
492+
fpfit2(`fpfit2') `lfitci' lfitci2(`lfitci2') `qfitci' ///
493+
qfitci2(`qfitci2') `fpfitci' fpfitci2(`fpfitci2') `qfit' ///
494+
`scheme' `keepgph' root(`root') `byvars' `byseq'
495+
496+
} // End IF Block for scatter plots
497+
498+
// Check for bubble plots
499+
if "`bubbleplots'" != "nobubbleplots" & !inlist(`contvarcount', 0, .) ///
500+
& inlist("bubble", `"`: subinstr loc bygraphs `" "' `"", ""''"') == 1 {
501+
502+
// Call subroutine for bubble plots
503+
edabubble `continuous' if `edause', `scheme' `keepgph' ///
504+
root(`root') `byvars' `byseq'
505+
506+
} // End IF Block for bubble plots
507+
508+
// Option to generate box plots
509+
if "`boxplots'" != "noboxplots" & (!inlist(`contvarcount', 0, .) ///
510+
& !inlist(`catvarcount', 0, .)) ///
511+
& inlist("boxplot", `"`: subinstr loc bygraphs `" "' `"", ""''"') == 1 {
512+
513+
// Create Box Plots
514+
edabox if `edause', cat(`categorical') cont(`continuous') ///
515+
`scheme' `keepgph' root(`root') `byvars' `byseq'
516+
517+
} // End IF Block for box plots
518+
519+
// Check for mosiac/spine plots
520+
if "`mosaic'" != "nomosaic" & !inlist(`catvarcount', 0, .) ///
521+
& inlist("mosaic", `"`: subinstr loc bygraphs `" "' `"", ""''"') == 1 {
522+
523+
// Subroutine used to generate mosaic/spine plots
524+
edamosaic `categorical' if `edause', `scheme' `missing' ///
525+
`percent' `keepgph' root(`root') `byvars' `byseq'
526+
527+
} // End IF Block for mosaic plot creation
528+
529+
} // End IF Block for by graphs
449530

450531
// Create next section/subsection headers
451532
file write doc "\chapter{Descriptive Statistics} \newpage\clearpage" _n

Diff for: edabar.ado

+83-16
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* Creates bar graph GPH and PDF as well as entries in the LaTeX document *
77
* *
88
* Lines - *
9-
* 159 *
9+
* 224 *
1010
* *
1111
********************************************************************************
1212

1313
*! edabar
14-
*! v 0.0.0
15-
*! 28OCT2015
14+
*! v 0.0.1
15+
*! 10NOV2015
1616

1717
// Drop program from memory if already loaded
1818
cap prog drop edabar
@@ -28,7 +28,7 @@ prog def edabar
2828
root(string asis) ///
2929
[BARGRAphopts(string asis) ///
3030
scheme(passthru) ///
31-
keepgph MISSing byvars(varlist) ]
31+
keepgph MISSing byvars(varlist) byseq ]
3232

3333
// Mark only the observations to use
3434
marksample touse
@@ -83,8 +83,8 @@ prog def edabar
8383

8484
} // End IF Block for single variable
8585

86-
// If the byvars parameter has arguments
87-
else {
86+
// If the byvars parameter has arguments and user specifies sequentially
87+
else if "`byvars'" != "" & "`byseq'" != "" {
8888

8989
// Create bar graphs for the categorical variables
9090
foreach v of var `varlist' {
@@ -126,29 +126,96 @@ prog def edabar
126126
loc leg legend(rows(`:char `v'[lrows]') symy(1.85) symx(1.85))
127127

128128
// Create the histogram
129-
gr bar (`bartype') if `touse', over(`v') asyvars by(`b') ///
130-
`bargraphopts' `scheme' ti(`: char `v'[title]') `leg' ///
131-
`missing' note("Created on: `c(current_date)' at: `c(current_time)'")
129+
cap gr bar (`bartype') if `touse', over(`v') asyvars ///
130+
`bargraphopts' `scheme' `missing' by(`b', `leg' ///
131+
ti(`: char `v'[title]') ///
132+
note("Created on: `c(current_date)' at: `c(current_time)'"))
132133

134+
// Check return code
135+
if _rc == 0 {
136+
137+
// Export to .pdf file
138+
qui: gr export `"`root'/graphs/bar`v'By`bref'.pdf"', as(pdf) replace
139+
140+
// Add the graph to the LaTeX file
141+
file write doc "\begin{figure}[h!]" _n
142+
file write doc `"\caption{`cap' \label{fig:bar`v'By`bref'}}"' _n
143+
file write doc `"\includegraphics[width=\textwidth]{bar`v'By`bref'.pdf}"' _n
144+
file write doc "\end{figure} \newpage\clearpage" _n
145+
146+
// Check if user wants to keep the GPH files
147+
if "`keepgph'" != "" {
148+
149+
// Define local macro with syntax to remove file
150+
qui: gr save `"`root'/graphs/bar`v'By`bref'.gph"', replace
151+
152+
} // End IF Block to remove .gph files
153+
154+
} // End IF Block for return code check
155+
156+
} // End Loop over by variables
157+
158+
} // End loop over categorical variables
159+
160+
} // End ELSEIF Block for sequential by graphs
161+
162+
// If the byvars parameter has arguments and user specifies sequentially
163+
else if "`byvars'" != "" & "`byseq'" == "" {
164+
165+
// Create bar graphs for the categorical variables
166+
foreach v of var `varlist' {
167+
168+
// Get the name of the bar variable
169+
texclean `"`v'"', r
170+
171+
// Store bar variable name
172+
loc ref `r(clntex)'
173+
174+
// Comma separate the byvars
175+
loc blab `: subinstr loc byvars `" "' `", "', all'
176+
177+
// Combined Label for Captions
178+
texclean `"`: var l `v'' by `blab'"'
179+
180+
// Store the caption string
181+
loc cap `r(clntex)'
182+
183+
// Double check that all internal quotation marks are removed
184+
loc cap : subinstr loc cap `"""' "", all
185+
186+
// Add subsubsection header for categorical data
187+
file write doc "\subsubsection{Bar Graphs by `blab'} \newpage\clearpage" _n
188+
189+
// Define a macro used to set legend parameters
190+
loc leg legend(rows(`:char `v'[lrows]') symy(1.85) symx(1.85))
191+
192+
// Create the histogram
193+
cap gr bar (`bartype') if `touse', over(`v') asyvars `missing' ///
194+
`bargraphopts' `scheme' by(`byvars', ti(`: char `v'[title]') ///
195+
note("Created on: `c(current_date)' at: `c(current_time)'") `leg')
196+
197+
// Check return code
198+
if _rc == 0 {
199+
133200
// Export to .pdf file
134-
qui: gr export `"`root'/graphs/bar`v'By`bref'.pdf"', as(pdf) replace
201+
qui: gr export `"`root'/graphs/bar`v'ByGraph.pdf"', as(pdf) replace
135202

136203
// Add the graph to the LaTeX file
137204
file write doc "\begin{figure}[h!]" _n
138-
file write doc `"\caption{`cap' \label{fig:bar`v'By`bref'}}"' _n
139-
file write doc `"\includegraphics[width=\textwidth]{bar`v'By`bref'.pdf}"' _n
205+
file write doc `"\caption{`cap' \label{fig:bar`v'ByGraph}}"' _n
206+
file write doc `"\includegraphics[width=\textwidth]{bar`v'ByGraph.pdf}"' _n
140207
file write doc "\end{figure} \newpage\clearpage" _n
141208

142209
// Check if user wants to keep the GPH files
143210
if "`keepgph'" != "" {
144211

145212
// Define local macro with syntax to remove file
146-
qui: gr save `"`root'/graphs/bar`v'By`bref'.gph"', replace
213+
qui: gr save `"`root'/graphs/bar`v'ByGraph.gph"', replace
147214

148215
} // End IF Block to remove .gph files
149-
150-
} // End Loop over by variables
151-
216+
217+
} // End IF Block for successful return code
218+
152219
} // End loop over categorical variables
153220

154221
} // End ELSE Block for by graphs

0 commit comments

Comments
 (0)