Book Image

Data Analysis with STATA

Book Image

Data Analysis with STATA

Overview of this book

Table of Contents (16 chapters)
Data Analysis with Stata
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
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...