* break fig clear import excel "schoolsurvey.xls", firstrow clear * show whether they deviate preserve egen tag=tag(instnr) keep if tag sum afv di 1-r(mean) restore * drop if instnr is missing drop if instnr==. * generate hours in hundres replace hour=hour*100 replace starthour=starthour*100 * first break preserve gen first=1 if hour==900 & min>=20 bys instnr: egen s=max(first) egen tag=tag(instnr) keep if tag replace s=0 if s==. sum s restore * second break preserve gen first=1 if hour==1100 & min>=20 bys instnr: egen s=max(first) egen tag=tag(instnr) keep if tag replace s=0 if s==. sum s restore * generate variables forval i=730(5)1500{ gen interval`i'=0 forval j=0/5{ qui: replace interval`i'=1 if (`i'+`j')>=(hour+100*(min/60)) /// & (hour+100*(min/60)+100*(duration/60))>(`i'+`j') } } * generate stopvariables forval i=730(5)1500{ gen stopinterval`i'=0 forval j=0/5{ qui: replace stopinterval`i'=1 if (`i'-2.5)<=(hour+100*(min/60)+100*(duration/60)) /// & (hour+100*(min/60)+100*(duration/60))<=(`i'+2.5) } } /* starttimes */ bys instnr: egen a=max(startmin) replace startmin=a forval g=730(5)1000{ gen start`g'=0 qui: replace start`g'=1 if (`g'-2.5)<=(starthour+100*(startmin/60)) /// & (starthour+100*(startmin/60))<=(`g'+2.5) } * collapse on school level collapse (sum) interval800-interval1500 (max) start750-start1000 (max) stopinterval800-stopinterval1500, by(instnr) * reshape data reshape long interval stopinterval start,i(instnr) * collapse by hour collapse (mean) interval stopinterval start, by(_j) gen dum=1 replace stopinterval=100*round(stopinterval,.01) replace interval=100*round(interval,.01) replace start=100*round(start,.01) replace interval=. if interval==0 replace start=. if start==0 // qui: tab interval local num=r(r) qui: tab start local num1=r(r)+`num'+1 local num2=r(r)+`num'+2 local num3=r(r)+`num'+3 local num4=r(r)+`num'+4 rename _j testhour drop if testhour>1400 tw (line stopinterval testhour, lcolor(black) lpattern(dash)) /// , ylabel(0(5)25,noticks nogrid ) /// xlabel(800 "8:00" 900 "9:00" 1000 "10:00" 1100 "11:00" 1200 "12:00" 1300 "13:00",noticks) legend(off) /// xtitle(" ") ytitle("Fraction (in pct.)") graphregion(fcolor(white) lcolor(white)) plotregion(lcolor(black) fcolor(white)) graph export "breakfigure.png",replace width(2000) keep testhour stopinterval export excel using "figure1b",replace