Hi Statalist,
I am working with a German panel dataset in Stata 18 containing grade levels (1-9) ("grade_self") and school types ("sample_school"), along with a binary treatment variable (1 = treated, 0 = control).
I would like to display the distribution of treatment and control groups across both grade levels and school types. My current code is:
The problem: in the bar chart produced with the code above, for each school type, all grade levels (1-9) are displayed. However, elementary/primary schools only have valid observations for grades 1-4. I would like the chart to reflect this, showing only grades 1-4 for elementary schools and grades 5-9 for other school types. I only managed to achieve this using the graph editor (see below). Is there any way to achieve this with code?
Any suggestions would be greatly appreciated! Thanks.
Best,
Samuel
I am working with a German panel dataset in Stata 18 containing grade levels (1-9) ("grade_self") and school types ("sample_school"), along with a binary treatment variable (1 = treated, 0 = control).
I would like to display the distribution of treatment and control groups across both grade levels and school types. My current code is:
Code:
graph hbar (count), over(treatment, relabel(1 "not treated" 2 "treated")) /// over(grade_self, lab(labsize(tiny))) /// over(sample_school, relabel(1 "lower secondary track (Hauptschule)" 2 "intermediate secondary track (Realschule)" 3 "upper secondary track (Gymnasium)" 4 "integrated comprehensive school (ICS)" 5 "cooperative comprehensive school (CCS)" 6 "elementary school") /// sort(1) reverse lab(labsize(vsmall))) asyvars stack title("") /// ytitle(number of observations, size (small)) scheme(s1color)
The problem: in the bar chart produced with the code above, for each school type, all grade levels (1-9) are displayed. However, elementary/primary schools only have valid observations for grades 1-4. I would like the chart to reflect this, showing only grades 1-4 for elementary schools and grades 5-9 for other school types. I only managed to achieve this using the graph editor (see below). Is there any way to achieve this with code?
Any suggestions would be greatly appreciated! Thanks.
Best,
Samuel
Comment