#### Overview of this book

Data Analysis with Stata
Credits
www.PacktPub.com
Preface
Free Chapter
Introduction to Stata and Data Analytics
Stata Programming and Data Management
Data Visualization
Important Statistical Tests in Stata
Linear Regression in Stata
Logistic Regression in Stata
Survey Analysis in Stata
Time Series Analysis in Stata
Survival Analysis in Stata
Index

## Pyramidal graphs

What if we need a pyramidal graph divided into all possible subcategories of the data? Here is your answer in terms of the Stata code:

```egen scoregroup= cut(score), group(9) label
tab scoregroup

sort sex scoregroup session
contract sex scoregroup session
rename _freq cnt

reshape wide cnt, i(scoregroup sex) j(session)

gen d1 = cnt1 /*session = 1 */
gen d12 = cnt1+cnt2
gen d123 = cnt3 + d12
gen d1_n = - d1
gen d12_n = - d12
gen d123_n = - d123

gen zero = 0

label values scoregroup scoregroup
label values sex f1

twoway bar c123 scoregroup if sex==0 , horizontal || ///
bar c12 scoregroup if sex==0, horizontal || ///
bar c1 scoregroup if sex ==0, horizontal  || ///
bar c123_n scoregroup if sex ==1 , horizontal || ///
bar c12_n scoregroup if sex ==1, horizontal || ///
bar c1_n scoregroup if sex ==1, horizontal || ///

sc  scoregroup zero ,  mlabel(scoregroup) mlabsize(vsmall) ///
mlabcolor(white) msymbol(i) || , plotregion(style(none)) ysca(dash) ///
ylabel...```