Dear all, I have the database as the image below, and I would like to create a percentage graph with the variables P04_1 to P04_12 in the same figure, what is the command?
-
Login or Register
- Log in with
clear
set seed 2803
set obs 100
forval j = 1/5 {
gen P04_`j' = runiform() < `j'/7
}
* you start here
tab1 P04_*
preserve
gen id = _n
reshape long P04_, i(id) j(which)
set scheme s1color
* must install first using ssc install catplot
catplot P04_ which, asyvars percent(which) recast(bar) ///
bar(1, lcolor(red) fcolor(red*0.5)) bar(2, lcolor(blue) fcolor(blue*0.5)) ///
t1title(explain variables here)
restore
| P0_1 | P0_2 | P0_3 | ... | P0_12 | P0_13 | |
| 1 | 0 | 1 | 1 | 0 | 0 | 1 |
| 2 | 0 | 1 | 0 | 1 | 0 | 1 |
| 3 | 1 | 0 | 0 | 0 | 1 | 0 |
| 4 | 0 | 0 | 1 | 0 | 1 | 0 |
| . . . |
1 | 0 | 0 | 0 | 0 | 1 |
| 3871 | 0 | 0 | 1 | 1 | 1 | 1 |
reshape long P0_, i(id) j(which) set scheme s1color ssc install catplot, replace catplot P0_ which, asyvars percent(which) recast(bar) /// bar(1, lcolor(red) fcolor(red*0.5)) bar(2, lcolor(blue) fcolor(blue*0.5)) /// t1title(explain variables here)
Comment