clear
input week FoC1 FoC2 FoC3
1 4 6 3
2 9 7 6
3 10 5 1
4 6 9 3
5 15 7 3
6 4 7 2
7 7 4 2
8 11 11 4
9 15 8 0
10 15 3 2
end
**************************************************
//
**************************************************
lab var FoC1 "Frequency of the category 1 within each week"
lab var FoC2 "Frequency of the category 2 within each week"
lab var FoC3 "Frequency of the category 3 within each week"
**************************************************
//Generate variables for percent
**************************************************
********************
//generate the total number for each week
********************
egen rt=rowtotal(FoC1 FoC2 FoC3)
********************
//generate percent for each category
********************
gen p1=(FoC1/rt)*100
gen p2=(FoC2/rt)*100
gen p3=(FoC3/rt)*100
********************
//generate cumulative percent
********************
gen p12= p1 + p2
gen p123=p1 + p2 + p3
**************************************************
//make the graph (area for stacked percent)
**************************************************
two (area p1 week, lc(red) fc(red)) (rarea p12 p1 week, lc( ebblue ) fc( ebblue ) ) (rarea p123 p12 week, lc(gs12) fc(gs12) ) ///
, name(p1, replace) ///
legend(lab(1 "Category1") lab(2 "Category2") lab(3 "Category3") size(small) row(1)) ///
xlab(1 "Week1" 2 "Week2" 3 "Week3" 4 "Week4" 5 "Week5" 6 "Week6" 7 "Week7" 8 "Week8" 9 "Week9" 10 "Week10", angle(90) labsize(small)) ///
ylab(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%" 60 "60%" 70 "70%" 80 "80%" 90 "90%" 100 "100%", angle(0) labsize(small)) ///
xtitle("") ytitle("")